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

AerSimulator from NoiseModel does not work with dynamic circuits #1997

Closed
anedumla opened this issue Nov 13, 2023 · 3 comments
Closed

AerSimulator from NoiseModel does not work with dynamic circuits #1997

anedumla opened this issue Nov 13, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@anedumla
Copy link

Informations

  • Qiskit Aer version: 0.13.0
  • Python version: 3.10.8
  • Operating system:

What is the current behavior?

The custom noise is not applied when the circuit contains dynamic instructions. The output of the following example is {'0 0': 1024}, i.e. the result without noise.

from qiskit import QuantumCircuit

from qiskit_aer.noise import NoiseModel, pauli_error
from qiskit_aer import AerSimulator

# Create the noise model
p_error = 0.3

readout_error = pauli_error([('X', p_error), ('I', 1 - p_error)])
noise_bit_flip = NoiseModel()
noise_bit_flip.add_all_qubit_quantum_error(readout_error, ['id'])

backend = AerSimulator(noise_model=noise_bit_flip)

test = QuantumCircuit(1,1)
test.id(0)
test.measure(0,0)
with test.if_test((0, 1)):
        test.x(0)
test.measure_all()
backend.run(test).result().get_counts()

However, when commenting out the lines containing dynamic instructions:

with test.if_test((0, 1)):
        test.x(0)

the output is {'0 0': 730, '1 1': 294}, as expected.

@anedumla anedumla added the bug Something isn't working label Nov 13, 2023
@doichanj doichanj self-assigned this Nov 13, 2023
@doichanj
Copy link
Collaborator

I think this script always returns 0 at mid-measure and always skips x gate.

Following circuit works well.

test = QuantumCircuit(1,1)
test.h(0)
test.measure(0,0)
with test.if_test((0, 1)):
        test.x(0)
test.measure_all()

@anedumla
Copy link
Author

In my original script, since the only noise is attached to the id gate, and from the results of the example without the dynamic instruction, the expected result would be {'0 0': 730, '0 1': 294}. I.e., because the id gate is noisy and flips the qubit with prob 0.3 to 1, you would expect that with probability 0.3, the dynamic X gate acts and the final result is with prob. 0.3 0 1, because measurements are noiseless in this example.

@doichanj
Copy link
Collaborator

I found id gate is removed by qiskit.compiler.transpile called from here

compiled_circ = transpile(
self._inline_circuit(circuit, None, None), basis_gates=basis_gates
)

I think we can avoid by adding optimization_level=0, I will make PR for this fix

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

2 participants