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
483 stars 358 forks source link

Should be possible to pass a backend to the Aer primitives #2166

Open nonhermitian opened 3 months ago

nonhermitian commented 3 months ago

What is the expected behavior?

I would expect something like this to work:


noisy_sim = AerSimulator.from_backend(backend)
sampler = SamplerV2(backend=noisy_sim)
doichanj commented 3 months ago

Sampler can be made from backend as following

sampler = SamplerV2.from_backend(backend)
nonhermitian commented 3 months ago

I get

QiskitError: 'ERROR: [Experiment 0] a circuit requires more memory than max_memory_mb. , ERROR: a circuit requires more memory than max_memory_mb.'

for a 6 qubit problem when targeting a noisy simulator made from a 127Q backend

doichanj commented 3 months ago

I tested with script below and I can reproduce the issue with the same error message

from qiskit import transpile
from qiskit_aer import AerSimulator
from qiskit_aer.primitives import SamplerV2
from qiskit import QuantumCircuit

qc= QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()

from qiskit_ibm_runtime import QiskitRuntimeService
provider = QiskitRuntimeService(channel='ibm_quantum')
backend = provider.backend("ibm_kyoto")

sampler = SamplerV2.from_backend(backend)
qc = transpile(qc, backend, optimization_level=0)
job3 = sampler.run([qc], shots=128)

And I found the transpiler fills ancilla qubits in unused qubits like this image This causes simulator's memory error.

But when I transpiled as following, I can run the circuit

qc = transpile(qc, basis_gates=backend.configuration().basis_gates, optimization_level=0)

Should we truncate ancilla qubits in Aer?

doichanj commented 1 month ago

The memory error issue was fixed in PR #2150 so this will be fixed in Aer 0.15