1
$\begingroup$

I'm doing a project for an internship related to quantum computing and I was trying to do this operation on Qiskit lab:

from qiskit import *
from qiskit.circuit.library.standard_gates import *
from qiskit.providers.aer import AerSimulator

qreg=QuantumRegister(8)
creg=ClassicalRegister(8)
circuit=QuantumCircuit(qreg,creg)
circuit.append(XGate().control(1,ctrl_state="0").c_if(creg[0],1),[1,4])
circuit.measure_all(add_bits=False)

#For execution
simulator=Aer.get_backend('qasm_simulator')
job=execute(circuit,simulator,memory=True,shots=1)
result = job.result()

when I've obtained this error : "DAGCircuitError: invalid clbits in condition for cx"

So I've check by changing controlled values for the qubit and the classical bit and it seems that when the gate is controlled by 0 on the qubit, the operation doesn't work whatever if the controlled value is 1 or 0 on the classical bit, but when the controlled value is 1 on the qubit, the operation works for both controlled value on the classical bit... What's the problem ? Why the controlled value on the qubit need to be equal to 1 in order to do (run with a Aer backend) the operation ? Someone could help me on this issue which seems very weird for a 'basic' operation ?

$\endgroup$

1 Answer 1

0
$\begingroup$

Running your code as it is on IBM Quantum lab:

qreg = QuantumRegister(8)
creg = ClassicalRegister(8)
circuit = QuantumCircuit(qreg,creg)
circuit.draw('mpl',style='iqx',fold=-1)

gives: enter image description here

and then adding the XGate(), as you mentioned

from qiskit.circuit.library import XGate
circuit.append(XGate().control(1,ctrl_state="0").c_if(creg[0],1),[1,4])
circuit.draw('mpl',style='iqx',fold=-1)

gives me this:

enter image description here


I am not getting the error you mentioned, maybe there's an issue with the Qiskit version you are using, or if there are some other steps to replicate this error.

But if only making a circuit is your issue, it isn't giving me the error.

If there's something else that you wanted to ask, rephrase the question in detail, that what you wanted to do, and what behavior was expected and what you are getting.

$\endgroup$
5
  • $\begingroup$ In fact it was when I wanted to run the code with the Aer backend (sorry I've forgotten to mention that ,I've added some things on the code) that I obtain the problem, but to draw this operation there's effectively any problem ! $\endgroup$
    – Thomas
    Jan 11 at 8:59
  • 1
    $\begingroup$ Are you still getting the error? or does this answer your question? If you are still getting the error, can you explain that in detail in your question? $\endgroup$ Jan 11 at 9:14
  • $\begingroup$ Yes I've always the problem : in fact the problem appears when I want to 'execute' this operation (with the use of Aer backend). $\endgroup$
    – Thomas
    Jan 11 at 12:04
  • $\begingroup$ The operation that you drew is exactly what I want to do. The weird thing is that there's no problem to 'draw' the operation, it works, but when you want to execute it (in order to modify values that qubits can own) with the use of Aer simulator, there's the error that I mention previously. And this issue only appears if on the qubit the 'controlled value' is equal to 0 . You can try the previous code by changing the qubit's controlled value with 1, it works perfectly. $\endgroup$
    – Thomas
    Jan 11 at 23:13
  • $\begingroup$ Do you have understand the issue ? Do you have the same error when you try to execute the previous code in the question ? $\endgroup$
    – Thomas
    Jan 13 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.