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

Improve error message for invalid measurement in adjoint() region #1425

Merged
merged 9 commits into from
Jan 13, 2025
6 changes: 5 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
* `from_plxpr` now uses the `qml.capture.PlxprInterpreter` class for reduced code duplication.
[(#1398)](https://github.com/PennyLaneAI/catalyst/pull/1398)

* Improve the error message for invalid measurement in `adjoin()` or `ctrl()` region.
[(#1425)](https://github.com/PennyLaneAI/catalyst/pull/1425)

* Replace `ValueRange` with `ResultRange` and `Value` with `OpResult` to better align with the semantics of `**QubitResult()` functions like `getNonCtrlQubitResults()`. This change ensures clearer intent and usage. Improve the `matchAndRewrite` function by using `replaceAllUsesWith` instead of for loop.
[(#1426)](https://github.com/PennyLaneAI/catalyst/pull/1426)


<h3>Documentation 📝</h3>

<h3>Contributors ✍️</h3>
Expand All @@ -31,4 +35,4 @@ This release contains contributions from (in alphabetical order):

Christina Lee
Mehrdad Malekmohammadi
Sengthai Heng
Sengthai Heng
8 changes: 4 additions & 4 deletions frontend/catalyst/api_extensions/quantum_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,14 @@ def ctrl_distribute(
def _check_no_measurements(tape: QuantumTape) -> None:
"""Check the nested quantum tape for the absense of quantum measurements of any kind"""

msg = "Quantum measurements are not allowed"

if len(tape.measurements) > 0:
raise ValueError(msg)
raise ValueError("Quantum measurements are not allowed")
sengthai marked this conversation as resolved.
Show resolved Hide resolved
for op in tape.operations:
if has_nested_tapes(op):
for r in [r for r in op.regions if r.quantum_tape is not None]:
_check_no_measurements(r.quantum_tape)
else:
if isinstance(op, MidCircuitMeasure):
raise ValueError(msg)
raise ValueError(
sengthai marked this conversation as resolved.
Show resolved Hide resolved
"Measurements cannot be used within an adjoint() or ctrl() region."
sengthai marked this conversation as resolved.
Show resolved Hide resolved
)
2 changes: 1 addition & 1 deletion frontend/test/pytest/test_quantum_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def _func1():
C_ctrl(_func1, control=[1], control_values=[True])()
return qml.state()

with pytest.raises(ValueError, match="measurements are not allowed"):
with pytest.raises(ValueError, match="Measurements cannot be used"):
qjit(circuit)(0.1)

def test_qctrl_no_end_circuit_measurements(self, backend):
Expand Down