Skip to content

Commit

Permalink
[braket] Add support for observe API (#2539)
Browse files Browse the repository at this point in the history
Signed-off-by: Pradnya Khalate <pkhalate@nvidia.com>
  • Loading branch information
khalatepradnya authored Jan 27, 2025
1 parent 5ee448d commit 1e9bf70
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 3 additions & 7 deletions python/tests/backends/test_braket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
2 changes: 2 additions & 0 deletions runtime/common/BaseRemoteRESTQPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1e9bf70

Please sign in to comment.