-
Notifications
You must be signed in to change notification settings - Fork 615
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
…neAI/pennylane into add-qubit_mixed/sampling
Let's merge this after the v0.40 release is live |
Note that the coverage issue is due to the fact that the legacy mixed deletion. We might need to override it some time. |
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.
Looks good. Some final comments left below.
While it was a good change to remove the QubitDensityMatrix
validation from apply_operation
, I think it's meaningful to have it somewhere. It's probably worth adding it to QubitDensityMatrix.__init__
. However, that is not a change needed for this PR. Could you open a story for this in the Top of the Backlog?
* Converted current tests that used `default.mixed` to use other equivalent devices in-place. | ||
[(#6684)](https://github.com/PennyLaneAI/pennylane/pull/6684) | ||
|
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.
There should also be a changelog entry under either the "New features" or "Improvements" section about porting default.mixed
to the new device API. I will let @isaacdevlugt pick which section makes more sense.
import numpy as np | ||
import pennylane as qml | ||
|
||
from pennylane.devices.qubit_mixed import measure_final_state |
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.
No need to import pennylane and numpy. We assume users to import those in our docstrings.
import numpy as np | |
import pennylane as qml | |
from pennylane.devices.qubit_mixed import measure_final_state | |
from pennylane.devices.qubit_mixed import measure_final_state |
from pennylane import expval, probs | ||
from pennylane.devices.qubit_mixed import simulate | ||
from pennylane.ops import RX, PauliX | ||
from pennylane.tape import QuantumScript |
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.
For functions/classes available top-level, it's probably best to use them with qml.
instead of importing them.
from pennylane import expval, probs | |
from pennylane.devices.qubit_mixed import simulate | |
from pennylane.ops import RX, PauliX | |
from pennylane.tape import QuantumScript | |
from pennylane.devices.qubit_mixed import simulate | |
from pennylane.tape import QuantumScript |
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.
The rest of the docstring needs to be updated accordingly.
@@ -365,22 +364,6 @@ def func(x): | |||
): | |||
d_func(pnp.array(0.1, requires_grad=True)) | |||
|
|||
def test_no_state_capability(self, monkeypatch): |
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.
We shouldn't be removing tests. Instead of removing this test. You can test it with DefaultQubitLegacy
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.
Same for any other unit tests have been removed for similar reasons.
# !TODO: bring back angle 0 when the bug fixed https://github.com/PennyLaneAI/pennylane/pull/6684#issuecomment-2552123064 | ||
@pytest.mark.parametrize("angle", np.linspace(0, 2 * np.pi, 7)[1:]) |
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 add a shortcut story to the top of the backlog for this TODO and include the story ID in this TODO comment?
# !TODO: bring back angle 0 when the bug fixed https://github.com/PennyLaneAI/pennylane/pull/6684#issuecomment-2552123064 | |
@pytest.mark.parametrize("angle", np.linspace(0, 2 * np.pi, 7)[1:]) | |
# TODO: bring back angle 0 when the bug fixed https://github.com/PennyLaneAI/pennylane/pull/6684#issuecomment-2552123064 | |
@pytest.mark.parametrize("angle", np.linspace(0, 2 * np.pi, 7)[1:]) |
@@ -334,32 +348,25 @@ def _(op: type_op, state, is_state_batched=False, **kwargs): | |||
>>> state[0][0] = 1 |
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.
The state has 4 dims
>>> state[0][0] = 1 | |
>>> state[0][0][0][0] = 1 |
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.
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.
Comments for apply_operation
docs:
Due to the singledispatch
, the docs for apply_operation
look really weird:
We can fix this by using a similar strategy to devices.qubit.apply_operation
, which calls an internal apply_operation_default
method. This apply_operation_default
method is what gets decorated with singledispatch
, so we don't get the weird doc rendering.
# Simulate the circuit | ||
results = simulate(circuit) | ||
print(results) | ||
# Output: (0.0, array([0.68117888, 0.0, 0.31882112, 0.0])) |
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.
# Simulate the circuit | |
results = simulate(circuit) | |
print(results) | |
# Output: (0.0, array([0.68117888, 0.0, 0.31882112, 0.0])) | |
>>> print(simulate(circuit)) | |
(0.0, array([0.68117888, 0.0, 0.31882112, 0.0])) |
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 asapRelated GitHub Issues:
[sc-73324]