1
$\begingroup$

Below is a simplified code which I am using for a quantum circuit.

from qiskit import QuantumCircuit

qc = QuantumCircuit(5)
qc.initialize(Statevector.from_label('r'*5))
qc.h(0)
qc.crx(180, 0, 1)
qc.cx(0, 2)
qc.draw("mpl")

When I draw the circuit it looks something like this: enter image description here

As you can see, the generated matplotlib image of quantum circuit has a huge block of initialize gate. I can see that the size of initialize instruction is because of the long list of parameters. So my question is, is there a way to suppress this long list of parameters from appearing in the initialize gate when I initialize my quantum circuit to a specific state?

$\endgroup$

1 Answer 1

0
$\begingroup$

If your aim is to make a quantum circuit plot that doesn't have this big chunk of initialization state, you can make use of decompose function by qiskit.

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
qc = QuantumCircuit(5)
qc.initialize(Statevector.from_label('r'*5))
qc.h(0)
qc.crx(180, 0, 1)
qc.cx(0, 2)
qc.decompose(reps=9).draw("mpl",fold=-1)

You can vary the value of reps and select what suits you the best, maybe 3 or 4.

Like the above code gives me this:

enter image description here

$\endgroup$
3
  • $\begingroup$ I was aware of the decompose function but I don't want to decompose the circuit. I want to keep the block of initialize gate but without the long parameter list. $\endgroup$ Commented Apr 20 at 0:40
  • $\begingroup$ Then maybe this article might help medium.com/qiskit/… $\endgroup$ Commented Apr 21 at 5:20
  • $\begingroup$ After digging deep into the qiskit source code, I was able to find the list of functions and classes that are causing this. Unfortunately, there is no direct way to achieve what I want. But I have figured out a not so elegant way to decrease the size of the initialize gate without tampering with the source code. Thanks for your help! $\endgroup$ Commented Apr 22 at 2:57

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.