-
Notifications
You must be signed in to change notification settings - Fork 633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration into the current PL device ecosys #6684
base: master
Are you sure you want to change the base?
Conversation
…ultMixed In this commit, we would like to replace all the usecase across the whole codebase that require the legacy default mixed from DefaultMixed to DefaultMixedLegacy
Co-authored-by: Astral Cai <astral.cai@xanadu.ai>
Finally we passed the CodeCov 🥳 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a huge effort. Congrats @JerryChen97 : )
3450f5b patched the missing coverage of device constructor. Since its design is to process device name, we are not able to make use of LegacyQubitDevice. Instead, we do a dumb construction with custom decomposition (i.e. no actual call of expand, which might lead to inf recursion) for |
Co-authored-by: Christina Lee <christina@xanadu.ai>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty much ready to approve once the _apply_state_vector
stuff is resolved. Amazing effort so far.
for op_class in SYMMETRIC_REAL_OPS: | ||
apply_operation.register(op_class)(apply_symmetric_real_op) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave a comment about why this syntax was used rather than using @apply_operation.register` as a decorator? It was so that the docs render nicely right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/devices/test_default_mixed.py
Outdated
class TestLegacyDefaultMixed: | ||
""" | ||
Tests that covered parts of legacy method of the DefaultMixed device. | ||
""" | ||
|
||
@pytest.mark.all_interfaces | ||
@pytest.mark.parametrize("interface", ML_INTERFACES) | ||
@pytest.mark.parametrize( | ||
"total_wires", [qml.wires.Wires([0]), qml.wires.Wires([0, 1]), qml.wires.Wires([0, 2, 1])] | ||
) | ||
def test_apply_state_vector(self, total_wires, interface): | ||
"""Initialize the internal state in a specified pure state.""" | ||
if interface == "autograd": | ||
pytest.skip( | ||
"Autograd interface not supported for this test. No autograd scatter support." | ||
) | ||
num_total_wires = len(total_wires) | ||
|
||
device_wires = qml.wires.Wires([0]) | ||
num_wires = len(device_wires) | ||
tolerance = 1e-10 | ||
state_np = np.zeros(shape=(2**num_wires,), dtype=np.complex128) | ||
state_np[0] = 1.0 | ||
_state = _apply_state_vector( | ||
total_wires=total_wires, | ||
state=state_np, | ||
device_wires=device_wires, | ||
interface=interface, | ||
) | ||
|
||
rho_expected_numpy = np.zeros([2] * 2 * num_total_wires, dtype=np.complex128) | ||
rho_expected_numpy[tuple([0] * 2 * num_total_wires)] = 1.0 | ||
rho_expected = qml.math.asarray(rho_expected_numpy, like=interface) | ||
assert qml.math.allclose(_state, rho_expected, atol=tolerance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to remove _apply_state_vector
and just add a unit test for scatter
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright! I'll try cleaning it up here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mudit2812 Redesigned the unitttests here ce0e8ad
@@ -600,6 +600,7 @@ def apply_symmetric_real_op( | |||
return state | |||
|
|||
|
|||
# NOTE: this loop is for a nice doc rendering for `apply_operation`. With a direct multiple single registers over different op class there will be severe rendering issue as discussed in https://github.com/PennyLaneAI/pennylane/pull/6684#pullrequestreview-2565634328 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just splitting it into multiple lines for readability
# NOTE: this loop is for a nice doc rendering for `apply_operation`. With a direct multiple single registers over different op class there will be severe rendering issue as discussed in https://github.com/PennyLaneAI/pennylane/pull/6684#pullrequestreview-2565634328 | |
# NOTE: this loop is for a nice doc rendering for `apply_operation`. With a direct multiple single | |
# registers over different op class there will be severe rendering issue as discussed in | |
# https://github.com/PennyLaneAI/pennylane/pull/6684#pullrequestreview-2565634328 |
We are finally merging this PR! 🍾 |
Context:
We finished all the necessary components of the new API interface of
default_mixed
. However, since this is an internal change, which involves many different files and paths, we would like to have one more round of check, success and merge of which should concludes the whole epic.Description of the Change:
keep DefaultMixed, but rename it to DefaultMixedLegacy (note: still the legacy one will be purged before this PR merged into master; it's kept right now due to great help in debug)operations_mixed
back tooperations
, and copy it to DefaultMixedLegacyreadout_error
just aswith arbitrary input error channelsBitFlip
modify all the device tests inDeleted legacy specified device tests. These should be covered in the integration test suite mentioned abovetests/devices
accordingly. Basically thetests/devices/test_default_mixed*.py
if no errors come up, then separate the legacy code into another fileLots of errors, see drawback section for a record along with updates.test_return_types_qnode
default.mixed
dev._state
needs to be removed and may be replaced by equivalent or not. Sol: had a PR to improve this linepip install git+https://github.com/PennyLaneAI/pennylane-qiskit.git@master
)why user warning here? Didn't read like sensible. Should double check.when running on notebook everything is finesome by-the-way improvement:
get_canonical_interface_name
and removed the hardcoded dictionary mimic of enum.qubit_mixed
much more withqubit
moduleBenefits:
Legacy code was preserved for reference purpose as well as catering for potential usersBetter separation between new interface and legacydefault.mixed
is ported directly with our new API.Possible Drawbacks:
default_mixed
might find it annoying for a while. However, we would include a direct indication in changelog as well as the new class.unexpected bug 1:finite-diff
support forPurityMP
on torch, tf, and jax downunexpected bug 2: gradient calculation atPhaseFlip(0)
breaks withnan
returned at initial state |0> (all good for other other channels or other state with PhaseFlip`expected bug 3: classical shadow is down for most of tests. This is due to the fact that the implementation is hidden insideQubitDevice
which was missed out before. Need to be fixed asapThe drop of legacy device might introduce some missing in related code coverage. For visibility, we track them as todos here as well.
ClassicalShadow
related missing: the entireClassicalShadowMP.process()
method;shadow_expval
branch in_qubit_device.py
single_dispatch
andmutliple_dispatch
)scatter
related missing:this is suspicious since it might imply that some functinoalities were lost.nothing has been lost. The legacy code that usescatter
was for initializing states in a bruteforce way, which is not needed anymore.Related GitHub Issues:
[sc-73324]