Skip to content
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

QNode.execute_kwargs no longer has mcm_config key #1452

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

<h3>Internal changes ⚙️</h3>

* Update access to `QNode.execute_kwargs` as there is no more `mcm_config` key.
andrijapau marked this conversation as resolved.
Show resolved Hide resolved
Instead `postselect_mode` and `mcm_method` should be accessed instead.
[(#1452)](https://github.com/PennyLaneAI/catalyst/pull/1452)

* The `get_c_interface` method has been added to the OQD device, which enables retrieval of the C++
implementation of the device from Python. This allows `qjit` to accept an instance of the device
and connect to its runtime.
Expand All @@ -39,4 +43,5 @@ This release contains contributions from (in alphabetical order):

Christina Lee
Mehrdad Malekmohammadi
Sengthai Heng
Sengthai Heng
Andrija Paurevic
5 changes: 4 additions & 1 deletion frontend/catalyst/jax_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,10 @@ def is_leaf(obj):
output = return_values_flat
trees = return_values_tree

mcm_config = qnode.execute_kwargs["mcm_config"]
mcm_config = qml.devices.MCMConfig(
postselect_mode=qnode.execute_kwargs["postselect_mode"],
mcm_method=qnode.execute_kwargs["mcm_method"],
)
qrp_out = trace_quantum_operations(tape, device, qreg_in, ctx, trace, mcm_config)
meas, meas_trees = trace_quantum_measurements(device, qrp_out, output, trees)
qreg_out = qrp_out.actualize()
Expand Down
10 changes: 8 additions & 2 deletions frontend/catalyst/qfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ def __call__(self, *args, **kwargs):
# Mid-circuit measurement configuration/execution
dynamic_one_shot_called = getattr(self, "_dynamic_one_shot_called", False)
if not dynamic_one_shot_called:
mcm_config = copy(self.execute_kwargs["mcm_config"])
mcm_config = copy(
qml.devices.MCMConfig(
postselect_mode=self.execute_kwargs["postselect_mode"],
mcm_method=self.execute_kwargs["mcm_method"],
)
)
total_shots = get_device_shots(self.device)
_validate_mcm_config(mcm_config, total_shots)

Expand Down Expand Up @@ -238,7 +243,8 @@ def processing_fn(results):

single_shot_qnode = transform_to_single_shot(qnode)
if mcm_config is not None:
single_shot_qnode.execute_kwargs["mcm_config"] = mcm_config
single_shot_qnode.execute_kwargs["postselect_mode"] = mcm_config.postselect_mode
single_shot_qnode.execute_kwargs["mcm_method"] = mcm_config.mcm_method
single_shot_qnode._dynamic_one_shot_called = True
dev = qnode.device
total_shots = get_device_shots(dev)
Expand Down
3 changes: 2 additions & 1 deletion frontend/test/pytest/test_mid_circuit_measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ def circuit(x):
return qml.expval(qml.PauliZ(0))

_ = circuit(1.8)
assert circuit.execute_kwargs["mcm_config"] == original_config
assert circuit.execute_kwargs["postselect_mode"] == original_config.postselect_mode
assert circuit.execute_kwargs["mcm_method"] == original_config.mcm_method

@pytest.mark.parametrize("postselect_mode", [None, "fill-shots", "hw-like"])
def test_default_mcm_method(self, backend, postselect_mode, mocker):
Expand Down
Loading