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

The noisy simulation of dynamic circuits gives to incorrect measurement outcomes #2091

Closed
xlelephant opened this issue Mar 29, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@xlelephant
Copy link

xlelephant commented Mar 29, 2024

Informations

  • Qiskit Aer version: 1.0.2
  • Python version: 3.9.7
  • Operating system: Windows

What is the current behavior?

Mid-circuit measurement and conditional branching are important features in Quantum computing.
Unfortunately, the Aer simulator is presently yielding wrong results when used for noisy simulation of dynamic circuits.

Steps to reproduce the problem

qregs = qiskit.QuantumRegister(2, name="Q")
final_reg = qiskit.ClassicalRegister(1, name="M")
cregs = qiskit.ClassicalRegister(1, name="R")
circ = qiskit.QuantumCircuit(qregs[:-1], cregs, qregs[-1:], final_reg)

circ.unitary(np.array([[0, 1], [1, 0]]), 0, label="excite")
circ.measure(qregs[0], final_reg)

circ.measure(qregs[1], cregs[0])
####### insertion of dynamic circuit #######
with circ.if_test((cregs[0], 1)):
    circ.y(qregs[-1])
####### insertion of dynamic circuit #######

run_options = {"shots": 10000, "seed_simulator": 123}
error = qiskit_aer.noise.depolarizing_error(0.1, 1)
noise_model = qiskit_aer.noise.NoiseModel()
noise_model.add_quantum_error(error, ["excite"], [0])
backend = qiskit_aer.AerSimulator(method="automatic", noise_model=noise_model)
job = backend.run(circ, noise_model=noise_model, **run_options)
result = job.result()
fid = (
    sum([count for bitstring, count in result.get_counts().items() if bitstring[0] == "1"])
    / run_options["shots"]
)
print("fidelity: ", fid)
circ.draw(output="mpl")
> fidelity: 1.0 (no noise effect)
> fidelity: 0.9509 (noisy)

no dynamic circuit
image

with dynamic circuit
image

What is the expected behavior?

The fidelity should be less than 1.0 since depolarizing error is added to the qubit(qregs[0]). However, it goes to 1.0 if I add one more qubit (qregs[1]) and insert some dynamic branches in the circuit, which I think should not effect qregs[0] in any way.

Suggested solutions

It appears that the inclusion of the conditional gate has interfered with the simulation noise model.
Please have a check~

@xlelephant xlelephant added the bug Something isn't working label Mar 29, 2024
@xlelephant xlelephant changed the title Noisy simulation of dynamic circuits yields wrong measurement results. The noisy simulation of dynamic circuits gives to incorrect measurement outcomes Mar 29, 2024
@xlelephant
Copy link
Author

xlelephant commented Mar 29, 2024

noise_model.add_quantum_error(error, ["excite"], [0])

And if I add errors to other instructions, with names like 'rx', 'u', 'u3', the outcomes seem noisy again.

@doichanj
Copy link
Collaborator

doichanj commented Apr 4, 2024

This is bug in aer_compiler that the labeled gate is transplied into other gates when the circuit is dynamic circuit.

@xlelephant
Copy link
Author

This is bug in aer_compiler that the labeled gate is transplied into other gates when the circuit is dynamic circuit.

Thanks for the answer,

I am wondering if a circuit composed solely of native gates, such as ['u', 'cz', 'ecr', ...], can circumvent this issue. Can I instruct the aer_compiler not to perform transpilation?

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