1
$\begingroup$

Using from qiskit.circuit.library I can import MCMT to create short-hand multi controlled gates, e.g.

from qiskit.circuit.library import MCMT
c3z = MCMT('z', num_ctrl_qubits=3, num_target_qubits=1) #define the 3-controlled z gate a.k.a. cccz gate
c3z.decompose().draw(output='mpl')

upon running the code you see the decomposed c3z gate: enter image description here

if you append this gate to a quantum circuit,

from qiskit import QuantumCircuit
circ.clear()
circ = QuantumCircuit(4)
circ.append(c3z,[0,1,2,3])
circ.draw('mpl')

you see the following:

enter image description here

2 questions:

1.) If I add the line

circ.decompose(c3z)

(see https://qiskit.org/documentation/stubs/qiskit.circuit.QuantumCircuit.decompose.html) to the above then the code becomes

from qiskit import QuantumCircuit
circ.clear()
circ = QuantumCircuit(4)
circ.append(c3z,[0,1,2,3])
circ.decompose(c3z)
circ.draw('mpl')

And I'd expect the output to resemble the first image, not the second. However the circuit is not decomposed by adding this line and I just see the purple rectangle instead.

2.) The cz/ccz gates in Qiskit have a nice appearance:

circ.clear()
circ = QuantumCircuit(4)
circ.cz(0,1)
circ.ccz(0,1,2)
circ.draw('mpl')

enter image description here

is there any way to get my c3z gate to follow this trend and look neat and tidy? Many thanks.

$\endgroup$

1 Answer 1

2
$\begingroup$

I don't think this is possible if you use the MCMT class to create your custom gate. However, if you start from a simple ZGate and transform it into your multi-controlled c3z gate by the Gate.control method, then the circuit should be finally drawn as you wish:

from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

circ = QuantumCircuit(4)
c3z = ZGate().control(num_ctrl_qubits=3, ctrl_state='111')
circ.append(c3z, [0,1,2,3])

circ.draw('mpl')

enter image description here

$\endgroup$

Your Answer

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

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