Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aer sampler does not truncate to active number of qubits #2084

Closed
nonhermitian opened this issue Mar 18, 2024 · 8 comments
Closed

Aer sampler does not truncate to active number of qubits #2084

nonhermitian opened this issue Mar 18, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@nonhermitian
Copy link
Contributor

Informations

  • Qiskit Aer version: latest
  • Python version:
  • Operating system:

What is the current behavior?

For many years now, the Aer simulator has truncated a circuit to only the active qubits, allowing for simulating transpiled circuits against device noise models; even when the full device number of qubits is larger than Aer supports (but the circuits active width is small enough for Aer to handle). However, the Aer Sampler does not perform the same truncation. E.g. using 5 qubits, and transpiling to an Eagle, the old Aer simulator will still truncate and run the circuit.

sim = AerSimulator()
job1 = sim.run(trans_qc, shots=int(1e4), dynamic=True)

works fine. But doing the same thing via the Aer sampler raises:

from qiskit_aer.primitives import Sampler as AerSampler
sampler = AerSampler()
job1 = sampler.run(trans_qc, shots=int(1e4), dynamic=True)

CircuitTooWideForTarget: 'Number of qubits (127) in circuit-8195 is greater than maximum (30) in the coupling_map'

Steps to reproduce the problem

Run a transpiled circuit that is smaller than 30Q in active qubits, but transpiled against a 127Q system

What is the expected behavior?

The sampler should truncate to active qubits only, just like the simulator does.

Suggested solutions

@nonhermitian nonhermitian added the bug Something isn't working label Mar 18, 2024
@zlatko-minev
Copy link

+1

@doichanj
Copy link
Collaborator

doichanj commented Apr 3, 2024

Could you provide full script to reproduce the problem?

@nonhermitian
Copy link
Contributor Author

from qiskit import *
from qiskit_aer.primitives import Sampler
sampler = Sampler()

qc = QuantumCircuit(100, 2)
qc.h(98)
qc.cx(98, 99)
qc.measure([98, 99], [0, 1])
sampler.run(qc).result()

@doichanj
Copy link
Collaborator

doichanj commented May 1, 2024

This issue is fixed by release 0.14.1

@doichanj doichanj closed this as completed May 1, 2024
@nonhermitian
Copy link
Contributor Author

It is not fixed in Aer 0.14.1:

image

@doichanj
Copy link
Collaborator

doichanj commented May 2, 2024

I'm sorry but I had implemented wrongly this one:

if self._target is not None:

I fixed this

@haimeng-zhang
Copy link

haimeng-zhang commented May 31, 2024

The issue does not seem to be fixed when one of the following simulation methods is specified:
statevector, density_matrix, extended_stabilizer, matrix_product_state, unitary, superop.
For example, when using the method matrix_product_state, I got the following error
image

The script to reproduce this error is the following:

from qiskit import *
from qiskit_aer.primitives import Sampler
shots = 5000
options = {'shots':shots, 'method':'matrix_product_state'}
sampler = Sampler(backend_options=options)

qc = QuantumCircuit(100, 2)
qc.h(98)
qc.cx(98, 99)
qc.measure([98, 99], [0, 1])
sampler.run(qc).result()

I am using Aer version '0.14.2'.

@hhorii
Copy link
Collaborator

hhorii commented Aug 23, 2024

I confirmed that 0.15 can run

from qiskit import *
from qiskit_aer.primitives import Sampler
sampler = Sampler()

qc = QuantumCircuit(100, 2)
qc.h(98)
qc.cx(98, 99)
qc.measure([98, 99], [0, 1])
sampler.run(qc).result()

and

from qiskit import *
from qiskit_aer.primitives import Sampler
shots = 5000
options = {'shots':shots, 'method':'matrix_product_state'}
sampler = Sampler(backend_options=options)

qc = QuantumCircuit(100, 2)
qc.h(98)
qc.cx(98, 99)
qc.measure([98, 99], [0, 1])
sampler.run(qc).result()

, which were reported in this issue.

@hhorii hhorii closed this as completed Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants