3
$\begingroup$

When I try to draw the quantum circuit it is shown in only one block and not the whole circuit. For example using the code:

from qiskit.circuit.library import RealAmplitudes
ansatz = RealAmplitudes(3, reps=2)
print(ansatz)

This code only shows the circuit as one block as follows:

     ┌───────────────────────────────────────────────────────────────┐
q_0: ┤0                                                              ├
     │                                                               │
q_1: ┤1 RealAmplitudes(θ[0],θ[1],θ[2],θ[3],θ[4],θ[5],θ[6],θ[7],θ[8]) ├
     │                                                               │
q_2: ┤2                                                              ├
     └───────────────────────────────────────────────────────────────┘

Do you know how to show the whole circuit with the details of the gates instead?

$\endgroup$

1 Answer 1

2
$\begingroup$

You can break all the blocks in a circuit in smaller blocks by using the decompose method.

from qiskit.circuit.library import RealAmplitudes
ansatz = RealAmplitudes(3, reps=2)
ansatz.decompose().draw('mpl')

RealAmplitudes(3, reps=2) decomposition

$\endgroup$
1
  • $\begingroup$ Works great. Thanks alot. $\endgroup$
    – Salah
    Jul 27 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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