Skip to content

Commit

Permalink
Uncompute (bug/feature)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Strano committed Feb 25, 2024
1 parent e75bbb5 commit b2f20d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.3.1 (2024-02-25)

Bug fix / feature addition: "uncompute" after observable calculation (to allow different bases of observation for the same qubits).

## v0.3.0 (2024-02-25)

Features added:
Expand Down
2 changes: 1 addition & 1 deletion src/braket/qrack_simulator/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.0
0.3.1
10 changes: 10 additions & 0 deletions src/braket/qrack_simulator/qrack_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,12 @@ def run(self, ir: OQ3Program, shots=1, is_reactively_separated=False, sdrp=-1, n
obs = Observable.H()
else:
raise ValueError("BraketQrackSimulator only allows x, y, z, i, and h basis sample, variance, and expectation return values!")

# "Compute" must "uncompute" to restore original state (for outer loop).
# We "compute" by `basis_rotation_gates`, then we uncompute later.
for g in obs.basis_rotation_gates:
qsim.mtrx(g.to_matrix().flatten().tolist(), b[0])

if tensor_product is None:
tensor_product = obs
else:
Expand Down Expand Up @@ -233,6 +237,12 @@ def run(self, ir: OQ3Program, shots=1, is_reactively_separated=False, sdrp=-1, n
else:
resultTypes.append(jaqcd.Expectation.construct(observable=tensor_product.to_ir(), targets=qubits))

for b in qubit_bases:
# "Compute" must "uncompute" to restore original state (for outer loop).
# We "uncompute" by reversed gate order and conjugate transposition of elements with getH().
for g in reversed(obs.basis_rotation_gates):
qsim.mtrx(g.getH().to_matrix().flatten().tolist(), b[0])

return GateModelTaskResult.construct(
taskMetadata=TaskMetadata(
id=str(uuid.uuid4()),
Expand Down

0 comments on commit b2f20d4

Please sign in to comment.