qiskit-aer icon indicating copy to clipboard operation
qiskit-aer copied to clipboard

Sampler with shots=None does not behave as documented when number of qubits is 10 or more

Open kevinsung opened this issue 1 year ago • 3 comments

It appears that when the number of qubits is 10 or more, running Sampler with shots=None doesn't actually calculate the exact probabilities. For example, the following raises AssertionError. The true behavior should be documented.

import numpy as np
from qiskit.circuit.library import EfficientSU2
from qiskit.quantum_info import SparsePauliOp
from qiskit_aer.primitives import Sampler
from qiskit_aer.noise import NoiseModel, depolarizing_error

n_qubits = 10
circuit = EfficientSU2(n_qubits)
circuit.measure_all()

observable = SparsePauliOp("Z" * n_qubits)
params = [0.1] * circuit.num_parameters

noise_model = NoiseModel()
cx_depolarizing_prob = 0.02
noise_model.add_all_qubit_quantum_error(
    depolarizing_error(cx_depolarizing_prob, 2), ["cx"]
)

noisy_sampler = Sampler(backend_options={"noise_model": noise_model})
job = noisy_sampler.run(circuit, params, shots=None)
quasis_1 = job.result().quasi_dists[0]
job = noisy_sampler.run(circuit, params, shots=None)
quasis_2 = job.result().quasi_dists[0]

for b in quasis_1 | quasis_2:
    np.testing.assert_allclose(quasis_1[b], quasis_2[b])

kevinsung avatar Nov 08 '23 01:11 kevinsung

There are two types of noise model simulations: trajectory and density matrix. In this case, the density matrix should be used. In the case of statevector, it is computed in trajectory, so the noise introduced is different for each run.

noisy_sampler = Sampler(backend_options={"noise_model": noise_model, "method": "density_matrix"})

The noise introduced by each run is different for statevector, but it is not wrong in that it returns an exact probability distribution for the final quantum state.

ikkoham avatar Nov 08 '23 02:11 ikkoham

So for qubits < 10 it uses the density matrix and for qubits >= 10 it uses the trajectories. Is that right? Is this behavior documented somewhere? I did not see it at https://qiskit.org/ecosystem/aer/stubs/qiskit_aer.primitives.Sampler.html.

kevinsung avatar Nov 08 '23 05:11 kevinsung

TBH, I'm not sure which method is chosen by the simulator method option automatic https://qiskit.org/ecosystem/aer/stubs/qiskit_aer.AerSimulator.html.

ikkoham avatar Nov 10 '23 05:11 ikkoham