From 1e9bf705100da28700e2b6c27f94ed3192b1866f Mon Sep 17 00:00:00 2001 From: Pradnya Khalate <148914294+khalatepradnya@users.noreply.github.com> Date: Mon, 27 Jan 2025 09:26:03 -0800 Subject: [PATCH] [braket] Add support for observe API (#2539) Signed-off-by: Pradnya Khalate --- python/tests/backends/test_braket.py | 10 +++------- runtime/common/BaseRemoteRESTQPU.h | 2 ++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/python/tests/backends/test_braket.py b/python/tests/backends/test_braket.py index e847d19714..320b7c9461 100644 --- a/python/tests/backends/test_braket.py +++ b/python/tests/backends/test_braket.py @@ -101,7 +101,7 @@ def single_qubit_gates(): s(q) t(q) mx(q) - my(q) + ## my(q) # not supported since the default rewriter uses `sdg` mz(q) # Test here is that this runs @@ -245,17 +245,13 @@ def ansatz(theta: float): x(qreg[0]) ry(theta, qreg[1]) x.ctrl(qreg[1], qreg[0]) - ## NOTE: Measure required since 'Device requires all qubits in the program to be measured.' - mz(qreg) # Define its spin Hamiltonian. hamiltonian = 5.907 - 2.1433 * spin.x(0) * spin.x(1) - 2.1433 * spin.y( 0) * spin.y(1) + .21829 * spin.z(0) - 6.125 * spin.z(1) - with pytest.raises(RuntimeError) as e: - cudaq.observe(ansatz, hamiltonian, .59, shots_count=100) - assert "observe specification violated for 'ansatz': kernels passed to observe cannot have measurements specified." in repr( - e) + res = cudaq.observe(ansatz, hamiltonian, .59, shots_count=1) + print(res.expectation()) def test_custom_operations(): diff --git a/runtime/common/BaseRemoteRESTQPU.h b/runtime/common/BaseRemoteRESTQPU.h index 81d8c5e2b3..bdf74957eb 100644 --- a/runtime/common/BaseRemoteRESTQPU.h +++ b/runtime/common/BaseRemoteRESTQPU.h @@ -547,6 +547,8 @@ class BaseRemoteRESTQPU : public cudaq::QPU { for (auto &pass : csvSplit) if (pass.ends_with("-gate-set-mapping")) runPassPipeline(pass, tmpModuleOp); + if (!emulate && combineMeasurements) + runPassPipeline("func.func(combine-measurements)", tmpModuleOp); modules.emplace_back(term.to_string(false), tmpModuleOp); } } else