Skip to content

Commit

Permalink
Merge pull request #1464 from qiboteam/draw
Browse files Browse the repository at this point in the history
Remove deprecation warning, remove old `draw`, and rename `display` as `draw` in `Circuit` class
  • Loading branch information
renatomello committed Sep 30, 2024
2 parents 1675510 + 6d8624f commit fee545b
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 170 deletions.
6 changes: 3 additions & 3 deletions doc/source/code-examples/advancedexamples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ Additionally, one can also pass single-qubit readout error probabilities (`reado
)

print("raw circuit:")
print(circuit.draw())
circuit.draw()

parameters = {
"t1": {"0": 250*1e-06, "1": 240*1e-06},
Expand All @@ -1168,7 +1168,7 @@ Additionally, one can also pass single-qubit readout error probabilities (`reado
noisy_circuit = noise_model.apply(circuit)

print("noisy circuit:")
print(noisy_circuit.draw())
noisy_circuit.draw()

.. testoutput::
:hide:
Expand Down Expand Up @@ -1242,7 +1242,7 @@ Let's see how to use them. For starters, let's define a dummy circuit with some
circ.add(gates.M(*range(nqubits)))
# visualize the circuit
print(circ.draw())
circ.draw()

# q0: ─RZ─RX─RZ─RX─RZ─o────o────────M─
# q1: ─RZ─RX─RZ─RX─RZ─X─RZ─X─o────o─M─
Expand Down
2 changes: 1 addition & 1 deletion doc/source/code-examples/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ For example
from qibo.models import QFT

c = QFT(5)
print(c.draw())
c.draw()
# Prints
'''
q0: ─H─U1─U1─U1─U1───────────────────────────x───
Expand Down
2 changes: 1 addition & 1 deletion examples/adiabatic_qml/adiabatic-qml.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@
"circ1 = rotcirc.rotations_circuit(t=0.1)\n",
"circ2 = rotcirc.rotations_circuit(t=0.8)\n",
"\n",
"print(f\"Circuit diagram: {circ1.draw()}\")\n",
"print(f\"Circuit diagram: {str(circ1)}\")\n",
"print(f\"\\nCirc1 params: {circ1.get_parameters()}\")\n",
"print(f\"\\nCirc2 params: {circ2.get_parameters()}\")"
]
Expand Down
2 changes: 1 addition & 1 deletion examples/anomaly_detection/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def compute_loss_test(encoder, vector):
encoder_test = make_encoder(n_qubits, n_layers, trained_params, q_compression)
encoder_test.compile()
print("Circuit model summary")
print(encoder_test.draw())
encoder_test.draw()

print("Computing losses...")
# Compute loss for standard data
Expand Down
2 changes: 1 addition & 1 deletion examples/anomaly_detection/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def train_step(batch_size, encoder, params, dataset):
# Create and print encoder circuit
encoder = make_encoder(n_qubits, n_layers, params, q_compression)
print("Circuit model summary")
print(encoder.draw())
encoder.draw()

# Define optimizer parameters
steps_for_epoch = math.ceil(train_size / batch_size)
Expand Down
10 changes: 5 additions & 5 deletions examples/circuit-draw-mpl/qibo-draw-circuit-matplotlib.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
" \n",
"ansatz.add((gates.RY(q, theta=0) for q in range(nqubits)))\n",
"ansatz.add(gates.M(qubit) for qubit in range(2))\n",
"print(ansatz.draw())"
"ansatz.draw()"
]
},
{
Expand Down Expand Up @@ -185,7 +185,7 @@
"c.add(gates.X(1))\n",
"c.add(gates.X(0))\n",
"c.add(gates.M(qubit) for qubit in range(2))\n",
"print(c.draw())"
"c.draw()"
]
},
{
Expand All @@ -206,7 +206,7 @@
}
],
"source": [
"plot_circuit(c);"
"plot_circuit(c)"
]
},
{
Expand All @@ -231,7 +231,7 @@
"c = QFT(5)\n",
"c.add(gates.M(qubit) for qubit in range(2))\n",
"\n",
"print(c.draw())"
"c.draw()"
]
},
{
Expand Down Expand Up @@ -384,7 +384,7 @@
}
],
"source": [
"print(c.fuse().draw())"
"c.fuse().draw()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/qcnn_classifier/qcnn_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
"source": [
"test = QuantumCNN(nqubits=4, nlayers=1, nclasses=2)\n",
"testcircuit = test._circuit\n",
"print(testcircuit.draw())"
"testcircuit.draw()"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions examples/qfiae/qfiae_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@
],
"source": [
"circuit_a_prob = create_circuit_a(n_qubits = 4,b_max = x_max_int, b_min = x_min_int)\n",
"print(circuit_a_prob.draw())"
"circuit_a_prob.draw()"
]
},
{
Expand Down Expand Up @@ -753,7 +753,7 @@
}
],
"source": [
"print(create_circuit_q(n_qubits=4,circuit_a=circuit_a_prob).draw())"
"create_circuit_q(n_qubits=4,circuit_a=circuit_a_prob).draw()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/qibo/gates/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def on_qubits(self, qubit_map) -> "Gate":
c.add(gates.CNOT(2, 3).on_qubits({2: 3, 3: 0})) # equivalent to gates.CNOT(3, 0)
c.add(gates.CNOT(2, 3).on_qubits({2: 1, 3: 3})) # equivalent to gates.CNOT(1, 3)
c.add(gates.CNOT(2, 3).on_qubits({2: 2, 3: 1})) # equivalent to gates.CNOT(2, 1)
print(c.draw())
c.draw()
.. testoutput::
q0: ───X─────
Expand Down
2 changes: 1 addition & 1 deletion src/qibo/gates/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def on_qubits(self, qubit_map) -> "Gate":
c = models.Circuit(3)
c.add(measurement.on_qubits({0: 0, 1: 2}))
assert c.queue[0].result is measurement.result
print(c.draw())
c.draw()
.. testoutput::
q0: ─M─
Expand Down
24 changes: 1 addition & 23 deletions src/qibo/models/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1377,26 +1377,4 @@ def draw(self, line_wrap: int = 70, legend: bool = False):
Returns:
String containing text circuit diagram.
"""
qibo.config.log.warning(
"Starting on qibo 0.2.13, ``Circuit.draw`` will work in-place. "
+ "The in-place method is currently implemented as ``Circuit.display``, but "
+ "will be renamed as ``Circuit.draw`` on release 0.2.13. "
+ "In release 0.2.12, the in-place display of circuits is accessible as "
+ "``Circuit.display``."
)
return self.diagram(line_wrap, legend)

def display(self, line_wrap: int = 70, legend: bool = False):
"""Draw text circuit using unicode symbols.
Args:
line_wrap (int, optional): maximum number of characters per line. This option
split the circuit text diagram in chunks of line_wrap characters.
Defaults to :math:`70`.
legend (bool, optional): If ``True`` prints a legend below the circuit for
callbacks and channels. Defaults to ``False``.
Returns:
String containing text circuit diagram.
"""
sys.stdout.write(self.diagram(line_wrap, legend))
sys.stdout.write(self.diagram(line_wrap, legend) + "\n")
2 changes: 1 addition & 1 deletion tests/test_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def test_measurement_basis_list(backend):
result = backend.execute_circuit(c, nshots=100)
assert result.frequencies() == {"0011": 100}
assert (
c.draw()
str(c)
== """q0: ─H─H───M─
q1: ───────M─
q2: ─X─H─H─M─
Expand Down
Loading

0 comments on commit fee545b

Please sign in to comment.