You can get these "true amplitudes" through the use of the statevector_simulator
within Aer. If you execute the circuit on the statevector_simulator
backend, it will return a statevector for the circuit. This statevector, when normalized, will return the theoretical probabilities of each state.
Let's take the circuit you posted as an example:
circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)
# Retrieve the statevector_simulator backend
backend = Aer.get_backend('statevector_simulator')
result = execute(circuit, backend, shots=1000).result()
# Get the statevector from result().
statevector = result.get_statevector(circuit)
# Normalize statevector to receive the true probabilities.
The statevector will be in the form of a list, with each entry representing a possible state. In this example, the statevector would be returned as [0.70710678+0.j 0. +0.j 0. +0.j 0.70710678+0.j]
. This can be read as:
- State
00
probability = 0.70710678+0.j (which is $\frac{1}{\sqrt2}$)
- State
01
probability = 0
- State
10
probability = 0
- State
11
probability = 0.70710678+0.j (which is $\frac{1}{\sqrt2}$)
Which, when normalized would give you a 50% probability of the state 00
and a 50% probability of the state 11
.