Qiskit / qiskit-aer

Aer is a high performance simulator for quantum circuits that includes noise models
https://qiskit.github.io/qiskit-aer/
Apache License 2.0
505 stars 361 forks source link

Estimator handles shots=None incorrectly #1820

Closed kevinsung closed 1 year ago

kevinsung commented 1 year ago

Informations

What is the current behavior?

If you run the Estimator with shots=None the result has shots=1024.

Steps to reproduce the problem

from qiskit import QuantumCircuit, QuantumRegister, transpile
from qiskit.quantum_info import SparsePauliOp
from qiskit_aer.primitives import Estimator

hamiltonian = SparsePauliOp("X")
qubits = QuantumRegister(1)
circuit = QuantumCircuit(qubits)
circuit.measure_all()

estimator = Estimator()
job = estimator.run(circuit, hamiltonian, shots=None)
result = job.result()
result.metadata
[{'shots': 1024,
  'variance': (0.9972190856933594+0j),
  'simulator_metadata': [{'noise': 'ideal',
    'batched_shots_optimization': False,
    'measure_sampling': True,
    'parallel_shots': 1,
    'remapped_qubits': False,
    'active_input_qubits': [0],
    'num_clbits': 1,
    'parallel_state_update': 8,
    'sample_measure_time': 0.000191442,
    'num_qubits': 1,
    'device': 'CPU',
    'input_qubit_map': [[0, 0]],
    'method': 'stabilizer',
    'fusion': {'enabled': False}}]}]

What is the expected behavior?

shots should be None. I'm not sure what variance here means but if it depends on the number of shots then it is also incorrect.

Suggested solutions

ikkoham commented 1 year ago

Thank you for your reporting an issue. This is not a bug, but it should raise an error because shots=None can only be done in the case of approximation=True. I'll fix this until 0.12.1.

ikkoham commented 1 year ago

s/error/warning/