amazon-braket / amazon-braket-default-simulator-python

Quantum program simulators that can run locally
https://amazon-braket-default-simulator-python.readthedocs.io/
Apache License 2.0
67 stars 22 forks source link

fix: support measurements on qubits without gates #236

Closed ashlhans closed 7 months ago

ashlhans commented 7 months ago

Issue #, if available:

Description of changes: Currently, the local simulators do not support measuring qubits that are not used (do not a gate) on the circuit.

Example:

Circuit().measure(0)

Circuit().h(0).cnot(0,1).measure([0, 1, 2])

To support this any qubits that are measured but not used, should return 0

Example:

circ = Circuit().measure(0)
result = device.run(circ, shots=10).result()
print(result.measurements)

[[0]
 [0]
 [0]
 [0]
 [0]
 [0]
 [0]
 [0]
 [0]
 [0]]
circ = Circuit().h(0).cnot(0,1).measure([0, 1, 2])
result = device.run(circ, shots=10).result()
print(result.measurements)

[[1 1 0]
 [1 1 0]
 [0 0 0]
 [1 1 0]
 [1 1 0]
 [1 1 0]
 [0 0 0]
 [0 0 0]
 [1 1 0]
 [0 0 0]]

Testing done: tox

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (8ff6589) to head (0aa4bb2).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #236 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 48 48 Lines 3770 3778 +8 Branches 915 916 +1 ========================================= + Hits 3770 3778 +8 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.