dwavesystems / dwave-gate

dwave-gate is a software package for constructing, modifying and running quantum circuits on the provided state-vector simulator.
Apache License 2.0
15 stars 8 forks source link

Add multi-qubit sampling to measurements #31

Closed thisac closed 1 year ago

thisac commented 1 year ago

Adds support for multi-qubit sampling in measurements along with support for directly returning samples as bitstrings instead of integers in nested lists. This simplifies sampling from simulating circuits and avoids the need for simulating the full circuit again for each sample.

circuit = Circuit(2, 2)

with circuit.context as (q, c):
    ops.Hadamard(q[0])
    ops.CNOT(q[0], q[1])
    m = ops.Measurement(q) | c

simulate(circuit)

Samples should (and will) always be either "00" or "11" for the specified circuit above. Which qubits to sample can be specified as e.g., qubits=[0] or qubits=[0, 1] (the latter sampling from all qubits in a 2-qubit circuit).

>>> m.sample(num_samples=5, as_bitstring=True)
['00', '11', '00', '00', '11']
codecov-commenter commented 1 year ago

Codecov Report

Merging #31 (b8b7ebe) into master (ecb8b06) will not change coverage. The diff coverage is 100.00%.

:exclamation: Current head b8b7ebe differs from pull request most recent head 204daa9. Consider uploading reports for the commit 204daa9 to get more accurate results

@@            Coverage Diff            @@
##            master       #31   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        15           
  Lines         1191      1186    -5     
  Branches       184       183    -1     
=========================================
- Hits          1191      1186    -5     
Impacted Files Coverage Δ
dwave/gate/operations/base.py 100.00% <100.00%> (ø)
dwave/gate/simulator/__init__.py 100.00% <100.00%> (ø)
dwave/gate/tools/samples.py 100.00% <100.00%> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more