Sample result type is changing my measurement_counts but its not happening with Probability result type. Why is this happening ? Does Sample result type changes something in the circuit itself ?


2 Answers 2


To complete Christian's answer, here are few words and links about probability and sample.

probability returns the probabilities of measuring computational basis states. probability post-processes the results in your measurement_counts and adds a new element in results.values.

Sample returns the measurement counts of a specified target qubit set and observable. It is used to measure your qubit in a different basis (i.e. the one of the observable you specified). For instance, if you take the following snippet:

from braket.circuits import Circuit, Observable
from braket.devices import LocalSimulator
from braket.aws import AwsDevice

device = LocalSimulator()

circ = Circuit().h(0).sample(observable=Observable.X(), target=0)
result = device.run(circ, shots=10).result()
counts = result.measurement_counts

It will return Counter({'0': 10}). The circuit contains a single Hadamard gate that rotates the qubit such that it is now aligned along the X axis. sample is then used to measure the qubit in a basis that is defined by the eigenvectors of Observable.X() (represented by the Pauli X matrix). As the state is along one eigenstate of X, we only measure a single value '0' which corresponds to the measurement outcome of $|+\rangle$ state. Note that if you don't specify any result type, the observable Z (i.e. measuring the computational basis) is used.

You can find more information and examples at


You are likely using the Braket SDK. Be aware that the Braket SDK has logic to calculate probabilities from actual quantum devices (hardware) if those are not returned by the device itself. Those are technically not a measurement.

You can refer to the raw results.json file from your task to see exactly what was returned by the device.

For the changes applied in the Braket SDK see this: https://github.com/aws/amazon-braket-sdk-python/blob/main/src/braket/tasks/gate_model_quantum_task_result.py


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.