Reference

Result types

Instead of adding explicit measure gates, you tell QXel what you want back by attaching a Braket result type to the circuit. You can attach more than one. After the run, read them from result.values in the order you attached them.

Note Explicit measure gates are not supported. Remove any circuit.measure() calls and attach the result types below instead.

What each type returns

• Probability: probabilities of the computational basis states. • Sample: per-shot measurement outcomes for target qubits and an observable. • Expectation: expectation value ⟨O⟩ of an observable on target qubits. • Variance: variance of an observable on target qubits. • StateVector: the full complex state vector. • Amplitude: amplitudes of the specific basis states you name.

Shots: sampled vs analytic

Sampled types (Sample, and Probability/Expectation/Variance estimated from shots) need shots>0. Analytic types (StateVector, Amplitude, exact Probability) need shots=0, because they read the simulator state directly instead of sampling it. StateVector and Amplitude grow with the statevector, so they are limited by memory.

Example

Attach two result types and read them back. Here probability and expectation are estimated from 1000 shots:

python
from braket.circuits import Circuit, Observable

circuit = Circuit().h(0).cnot(0, 1)
circuit.probability()                          # values[0]
circuit.expectation(Observable.Z(), target=0)  # values[1]

result = qxel.run(circuit, shots=1000).result()
print(result.values)

Output

[array([0.501, 0.   , 0.   , 0.499]), 0.002]

values[0] is the probability over '00','01','10','11' (a Bell state, so weight on '00' and '11'). values[1] is ⟨Z⟩ on qubit 0, near 0 because it is equally likely to be 0 or 1.