diff --git a/tutorials-v4/lectures/Lecture-11-Charge-Qubits.md b/tutorials-v4/lectures/Lecture-11-Charge-Qubits.md index dbc8e279..70ed1617 100644 --- a/tutorials-v4/lectures/Lecture-11-Charge-Qubits.md +++ b/tutorials-v4/lectures/Lecture-11-Charge-Qubits.md @@ -39,7 +39,7 @@ where $E_C$ is the charge energy, $E_J$ is the Josephson energy, and $\left| n\r #### References - * [J. Koch et al, Phys. Rec. A 76, 042319 (2007)](http://link.aps.org/doi/10.1103/PhysRevA.76.042319) + * [J. Koch et al, Phys. Rec. A 76, 042319 (2007)](https://journals.aps.org/pra/abstract/10.1103/PhysRevA.76.042319) * [Y.A. Pashkin et al, Quantum Inf Process 8, 55 (2009)](http://dx.doi.org/10.1007/s11128-009-0101-5) diff --git a/tutorials-v4/lectures/Lecture-2B-Single-Atom-Lasing.md b/tutorials-v4/lectures/Lecture-2B-Single-Atom-Lasing.md index ed5be292..f9efd6ee 100644 --- a/tutorials-v4/lectures/Lecture-2B-Single-Atom-Lasing.md +++ b/tutorials-v4/lectures/Lecture-2B-Single-Atom-Lasing.md @@ -63,9 +63,9 @@ in units where $\hbar = 1$. References: - * [Yi Mu, C.M. Savage, Phys. Rev. A 46, 5944 (1992)](http://dx.doi.org/10.1103/PhysRevA.46.5944) + * [Yi Mu, C.M. Savage, Phys. Rev. A 46, 5944 (1992)](https://journals.aps.org/pra/abstract/10.1103/PhysRevA.46.5944) - * [D.A. Rodrigues, J. Imbers, A.D. Armour, Phys. Rev. Lett. 98, 067204 (2007)](http://dx.doi.org/10.1103/PhysRevLett.98.067204) + * [D.A. Rodrigues, J. Imbers, A.D. Armour, Phys. Rev. Lett. 98, 067204 (2007)](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.98.067204) * [S. Ashhab, J.R. Johansson, A.M. Zagoskin, F. Nori, New J. Phys. 11, 023030 (2009)](http://dx.doi.org/10.1088/1367-2630/11/2/023030) diff --git a/tutorials-v4/lectures/Lecture-3A-Dicke-model.md b/tutorials-v4/lectures/Lecture-3A-Dicke-model.md index cdee9f4b..3aaae2ab 100644 --- a/tutorials-v4/lectures/Lecture-3A-Dicke-model.md +++ b/tutorials-v4/lectures/Lecture-3A-Dicke-model.md @@ -49,7 +49,7 @@ $\displaystyle J_\pm = \sum_{i=1}^N \sigma_\pm^{(i)}$ ### References - * [R.H. Dicke, Phys. Rev. 93, 99–110 (1954)](http://dx.doi.org/10.1103/PhysRev.93.99) + * [R.H. Dicke, Phys. Rev. 93, 99–110 (1954)](https://journals.aps.org/pr/abstract/10.1103/PhysRev.93.99) ## Setup problem in QuTiP @@ -198,7 +198,7 @@ fig.tight_layout() ### References -* [Lambert et al., Phys. Rev. Lett. 92, 073602 (2004)](http://dx.doi.org/10.1103/PhysRevLett.92.073602). +* [Lambert et al., Phys. Rev. Lett. 92, 073602 (2004)](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.92.073602). ```python def calulcate_entropy(M, N, g_vec): diff --git a/tutorials-v4/lectures/Lecture-3B-Jaynes-Cumming-model-with-ultrastrong-coupling.md b/tutorials-v4/lectures/Lecture-3B-Jaynes-Cumming-model-with-ultrastrong-coupling.md index 37d822b6..cce8fc10 100644 --- a/tutorials-v4/lectures/Lecture-3B-Jaynes-Cumming-model-with-ultrastrong-coupling.md +++ b/tutorials-v4/lectures/Lecture-3B-Jaynes-Cumming-model-with-ultrastrong-coupling.md @@ -51,11 +51,11 @@ The regime $g$ is large compared with all other energy scales in the Hamiltonian References: - * [P. Nataf et al., Phys. Rev. Lett. 104, 023601 (2010)](http://dx.doi.org/10.1103/PhysRevLett.104.023601) + * [P. Nataf et al., Phys. Rev. Lett. 104, 023601 (2010)](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.104.023601) - * [J. Casanova et al., Phys. Rev. Lett. 105, 26360 (2010)](http://dx.doi.org/10.1103/PhysRevLett.105.263603). + * [J. Casanova et al., Phys. Rev. Lett. 105, 26360 (2010)](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.105.263603). - * [S. Ashhab et al., Phys. Rev. A 81, 042311 (2010)](http://dx.doi.org/10.1103/PhysRevA.81.042311) + * [S. Ashhab et al., Phys. Rev. A 81, 042311 (2010)](https://journals.aps.org/pra/abstract/10.1103/PhysRevA.81.042311) diff --git a/tutorials-v4/lectures/Lecture-4-Correlation-Functions.md b/tutorials-v4/lectures/Lecture-4-Correlation-Functions.md index 64313244..fb585463 100644 --- a/tutorials-v4/lectures/Lecture-4-Correlation-Functions.md +++ b/tutorials-v4/lectures/Lecture-4-Correlation-Functions.md @@ -152,7 +152,7 @@ $L(\tau) = 2\langle Q(\tau)Q(0)\rangle - \langle Q(2\tau)Q(0)\rangle \leq 1$ ### References -* [A. J. Leggett and A. Garg, Phys. Rev. Lett. 54, 857 (1985)](http://dx.doi.org/10.1103/PhysRevLett.54.857) +* [A. J. Leggett and A. Garg, Phys. Rev. Lett. 54, 857 (1985)](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.54.857) * [A. J. Leggett, J. Phys. Condens. Matter 14, R415 (2002)](http://dx.doi.org/10.1088/0953-8984/14/15/201) @@ -186,7 +186,7 @@ def leggett_garg(c_mat): References: - * [N. Lambert, J.R. Johansson, F. Nori, Phys. Rev. B 82, 245421 (2011)](http://dx.doi.org/10.1103/PhysRevB.84.245421). + * [N. Lambert, J.R. Johansson, F. Nori, Phys. Rev. B 82, 245421 (2011)](https://journals.aps.org/prb/abstract/10.1103/PhysRevB.84.245421). ```python diff --git a/tutorials-v4/quantum-circuits/qip-toffoli-cnot.md b/tutorials-v4/quantum-circuits/qip-toffoli-cnot.md index 3d933926..9c0d1f64 100644 --- a/tutorials-v4/quantum-circuits/qip-toffoli-cnot.md +++ b/tutorials-v4/quantum-circuits/qip-toffoli-cnot.md @@ -5,9 +5,9 @@ jupyter: extension: .md format_name: markdown format_version: '1.3' - jupytext_version: 1.13.8 + jupytext_version: 1.16.4 kernelspec: - display_name: Python 3 (ipykernel) + display_name: qutip-dev language: python name: python3 --- @@ -39,7 +39,7 @@ q.add_gate("TOFFOLI", controls=[0, 2], targets=[1]) ``` ```python -q.png +q.draw() ``` ```python @@ -53,7 +53,7 @@ q2 = q.resolve_gates() ``` ```python -q2.png +q2.draw() ``` ```python diff --git a/tutorials-v4/quantum-circuits/quantum-gates.md b/tutorials-v4/quantum-circuits/quantum-gates.md index c35df148..be7a4d0b 100644 --- a/tutorials-v4/quantum-circuits/quantum-gates.md +++ b/tutorials-v4/quantum-circuits/quantum-gates.md @@ -5,7 +5,7 @@ jupyter: extension: .md format_name: markdown format_version: '1.3' - jupytext_version: 1.13.8 + jupytext_version: 1.16.4 kernelspec: display_name: Python 3 (ipykernel) language: python @@ -63,7 +63,7 @@ cphase(pi / 2) ```python q = QubitCircuit(2, reverse_states=False) q.add_gate("CSIGN", controls=[0], targets=[1]) -q.png +q.draw() ``` ### Rotation about X-axis @@ -74,8 +74,8 @@ rx(pi / 2) ```python q = QubitCircuit(1, reverse_states=False) -q.add_gate("RX", targets=[0], arg_value=pi / 2, arg_label=r"\frac{\pi}{2}") -q.png +q.add_gate("RX", targets=[0], arg_value=pi / 2, style={"showarg": True}) +q.draw() ``` ### Rotation about Y-axis @@ -86,8 +86,8 @@ ry(pi / 2) ```python q = QubitCircuit(1, reverse_states=False) -q.add_gate("RY", targets=[0], arg_value=pi / 2, arg_label=r"\frac{\pi}{2}") -q.png +q.add_gate("RY", targets=[0], arg_value=pi / 2, style={"showarg": True}) +q.draw() ``` ### Rotation about Z-axis @@ -98,8 +98,8 @@ rz(pi / 2) ```python q = QubitCircuit(1, reverse_states=False) -q.add_gate("RZ", targets=[0], arg_value=pi / 2, arg_label=r"\frac{\pi}{2}") -q.png +q.add_gate("RZ", targets=[0], arg_value=pi / 2, style={"showarg": True}) +q.draw() ``` ### CNOT @@ -111,7 +111,7 @@ cnot() ```python q = QubitCircuit(2, reverse_states=False) q.add_gate("CNOT", controls=[0], targets=[1]) -q.png +q.draw() ``` ### CSIGN @@ -123,7 +123,7 @@ csign() ```python q = QubitCircuit(2, reverse_states=False) q.add_gate("CSIGN", controls=[0], targets=[1]) -q.png +q.draw() ``` ### Berkeley @@ -135,7 +135,7 @@ berkeley() ```python q = QubitCircuit(2, reverse_states=False) q.add_gate("BERKELEY", targets=[0, 1]) -q.png +q.draw() ``` ### SWAPalpha @@ -162,7 +162,7 @@ toffoli() swap() q = QubitCircuit(2, reverse_states=False) q.add_gate("SWAP", targets=[0, 1]) -q.png +q.draw() ``` ### ISWAP @@ -171,7 +171,7 @@ q.png iswap() q = QubitCircuit(2, reverse_states=False) q.add_gate("ISWAP", targets=[0, 1]) -q.png +q.draw() ``` ### SQRTiSWAP @@ -234,7 +234,7 @@ cnot(N=3) ```python q = QubitCircuit(3, reverse_states=False) q.add_gate("CNOT", controls=[1], targets=[2]) -q.png +q.draw() ``` Furthermore, the control and target qubits (when applicable) can also be similarly specified using keyword arguments `control` and `target` (or in some cases `controls` or `targets`): @@ -246,7 +246,7 @@ cnot(N=3, control=2, target=0) ```python q = QubitCircuit(3, reverse_states=False) q.add_gate("CNOT", controls=[0], targets=[2]) -q.png +q.draw() ``` ## Setup of a Qubit Circuit @@ -261,7 +261,7 @@ In the following example, we take a SWAP gate. It is known that a swap gate is e N = 2 qc0 = QubitCircuit(N) qc0.add_gate("ISWAP", [0, 1], None) -qc0.png +qc0.draw() ``` ```python @@ -275,7 +275,7 @@ qc1 = QubitCircuit(N) qc1.add_gate("CNOT", 0, 1) qc1.add_gate("CNOT", 1, 0) qc1.add_gate("CNOT", 0, 1) -qc1.png +qc1.draw() ``` ```python @@ -288,7 +288,7 @@ In place of manually converting the SWAP gate to CNOTs, it can be automatically ```python qc2 = qc0.resolve_gates("CNOT") -qc2.png +qc2.draw() ``` ```python @@ -301,7 +301,7 @@ From QuTiP 4.4, we can also add gate at arbitrary position in a circuit. ```python qc1.add_gate("CSIGN", index=[1], targets=[0], controls=[1]) -qc1.png +qc1.draw() ``` ## Example of basis transformation @@ -313,7 +313,7 @@ qc3.add_gate("RX", 0, None, pi / 2, r"\pi/2") qc3.add_gate("RY", 1, None, pi / 2, r"\pi/2") qc3.add_gate("RZ", 2, None, pi / 2, r"\pi/2") qc3.add_gate("ISWAP", [1, 2]) -qc3.png +qc3.draw() ``` ```python @@ -325,7 +325,7 @@ U3 ```python qc4 = qc3.resolve_gates("CNOT") -qc4.png +qc4.draw() ``` ```python @@ -335,7 +335,7 @@ U4 ```python qc5 = qc3.resolve_gates("ISWAP") -qc5.png +qc5.draw() ``` ```python @@ -347,7 +347,7 @@ U5 ```python qc6 = qc3.resolve_gates(["ISWAP", "RX", "RY"]) -qc6.png +qc6.draw() ``` ```python @@ -357,7 +357,7 @@ U6 ```python qc7 = qc3.resolve_gates(["CNOT", "RZ", "RX"]) -qc7.png +qc7.draw() ``` ```python @@ -373,7 +373,7 @@ Interactions between non-adjacent qubits can be resolved by QubitCircuit to a se ```python qc8 = QubitCircuit(3) qc8.add_gate("CNOT", 2, 0) -qc8.png +qc8.draw() ``` ```python @@ -393,7 +393,7 @@ U9 ```python qc10 = qc9.resolve_gates("CNOT") -qc10.png +qc10.draw() ``` ```python @@ -418,7 +418,7 @@ From QuTiP 4.4 on, user defined gates can be defined by a python function that t ```python def user_gate1(arg_value): # controlled rotation X - mat = np.zeros((4, 4), dtype=np.complex) + mat = np.zeros((4, 4), dtype=complex) mat[0, 0] = mat[1, 1] = 1.0 mat[2:4, 2:4] = rx(arg_value) return Qobj(mat, dims=[[2, 2], [2, 2]]) diff --git a/tutorials-v5/lectures/Lecture-11-Charge-Qubits.md b/tutorials-v5/lectures/Lecture-11-Charge-Qubits.md index 3bda7b24..8d3017cd 100644 --- a/tutorials-v5/lectures/Lecture-11-Charge-Qubits.md +++ b/tutorials-v5/lectures/Lecture-11-Charge-Qubits.md @@ -39,7 +39,7 @@ where $E_C$ is the charge energy, $E_J$ is the Josephson energy, and $\left| n\r #### References - * [J. Koch et al, Phys. Rec. A 76, 042319 (2007)](http://link.aps.org/doi/10.1103/PhysRevA.76.042319) + * [J. Koch et al, Phys. Rec. A 76, 042319 (2007)](https://journals.aps.org/pra/abstract/10.1103/PhysRevA.76.042319) * [Y.A. Pashkin et al, Quantum Inf Process 8, 55 (2009)](http://dx.doi.org/10.1007/s11128-009-0101-5) diff --git a/tutorials-v5/lectures/Lecture-2B-Single-Atom-Lasing.md b/tutorials-v5/lectures/Lecture-2B-Single-Atom-Lasing.md index fe501904..56191917 100644 --- a/tutorials-v5/lectures/Lecture-2B-Single-Atom-Lasing.md +++ b/tutorials-v5/lectures/Lecture-2B-Single-Atom-Lasing.md @@ -63,9 +63,9 @@ in units where $\hbar = 1$. References: - * [Yi Mu, C.M. Savage, Phys. Rev. A 46, 5944 (1992)](http://dx.doi.org/10.1103/PhysRevA.46.5944) + * [Yi Mu, C.M. Savage, Phys. Rev. A 46, 5944 (1992)](https://journals.aps.org/pra/abstract/10.1103/PhysRevA.46.5944) - * [D.A. Rodrigues, J. Imbers, A.D. Armour, Phys. Rev. Lett. 98, 067204 (2007)](http://dx.doi.org/10.1103/PhysRevLett.98.067204) + * [D.A. Rodrigues, J. Imbers, A.D. Armour, Phys. Rev. Lett. 98, 067204 (2007)](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.98.067204) * [S. Ashhab, J.R. Johansson, A.M. Zagoskin, F. Nori, New J. Phys. 11, 023030 (2009)](http://dx.doi.org/10.1088/1367-2630/11/2/023030) diff --git a/tutorials-v5/lectures/Lecture-3A-Dicke-model.md b/tutorials-v5/lectures/Lecture-3A-Dicke-model.md index cdee9f4b..3aaae2ab 100644 --- a/tutorials-v5/lectures/Lecture-3A-Dicke-model.md +++ b/tutorials-v5/lectures/Lecture-3A-Dicke-model.md @@ -49,7 +49,7 @@ $\displaystyle J_\pm = \sum_{i=1}^N \sigma_\pm^{(i)}$ ### References - * [R.H. Dicke, Phys. Rev. 93, 99–110 (1954)](http://dx.doi.org/10.1103/PhysRev.93.99) + * [R.H. Dicke, Phys. Rev. 93, 99–110 (1954)](https://journals.aps.org/pr/abstract/10.1103/PhysRev.93.99) ## Setup problem in QuTiP @@ -198,7 +198,7 @@ fig.tight_layout() ### References -* [Lambert et al., Phys. Rev. Lett. 92, 073602 (2004)](http://dx.doi.org/10.1103/PhysRevLett.92.073602). +* [Lambert et al., Phys. Rev. Lett. 92, 073602 (2004)](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.92.073602). ```python def calulcate_entropy(M, N, g_vec): diff --git a/tutorials-v5/lectures/Lecture-3B-Jaynes-Cumming-model-with-ultrastrong-coupling.md b/tutorials-v5/lectures/Lecture-3B-Jaynes-Cumming-model-with-ultrastrong-coupling.md index 37d822b6..cce8fc10 100644 --- a/tutorials-v5/lectures/Lecture-3B-Jaynes-Cumming-model-with-ultrastrong-coupling.md +++ b/tutorials-v5/lectures/Lecture-3B-Jaynes-Cumming-model-with-ultrastrong-coupling.md @@ -51,11 +51,11 @@ The regime $g$ is large compared with all other energy scales in the Hamiltonian References: - * [P. Nataf et al., Phys. Rev. Lett. 104, 023601 (2010)](http://dx.doi.org/10.1103/PhysRevLett.104.023601) + * [P. Nataf et al., Phys. Rev. Lett. 104, 023601 (2010)](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.104.023601) - * [J. Casanova et al., Phys. Rev. Lett. 105, 26360 (2010)](http://dx.doi.org/10.1103/PhysRevLett.105.263603). + * [J. Casanova et al., Phys. Rev. Lett. 105, 26360 (2010)](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.105.263603). - * [S. Ashhab et al., Phys. Rev. A 81, 042311 (2010)](http://dx.doi.org/10.1103/PhysRevA.81.042311) + * [S. Ashhab et al., Phys. Rev. A 81, 042311 (2010)](https://journals.aps.org/pra/abstract/10.1103/PhysRevA.81.042311) diff --git a/tutorials-v5/lectures/Lecture-4-Correlation-Functions.md b/tutorials-v5/lectures/Lecture-4-Correlation-Functions.md index db8c71b9..3d4990bc 100644 --- a/tutorials-v5/lectures/Lecture-4-Correlation-Functions.md +++ b/tutorials-v5/lectures/Lecture-4-Correlation-Functions.md @@ -157,7 +157,7 @@ $L(\tau) = 2\langle Q(\tau)Q(0)\rangle - \langle Q(2\tau)Q(0)\rangle \leq 1$ ### References -* [A. J. Leggett and A. Garg, Phys. Rev. Lett. 54, 857 (1985)](http://dx.doi.org/10.1103/PhysRevLett.54.857) +* [A. J. Leggett and A. Garg, Phys. Rev. Lett. 54, 857 (1985)](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.54.857) * [A. J. Leggett, J. Phys. Condens. Matter 14, R415 (2002)](http://dx.doi.org/10.1088/0953-8984/14/15/201) @@ -191,7 +191,7 @@ def leggett_garg(c_mat): References: - * [N. Lambert, J.R. Johansson, F. Nori, Phys. Rev. B 82, 245421 (2011)](http://dx.doi.org/10.1103/PhysRevB.84.245421). + * [N. Lambert, J.R. Johansson, F. Nori, Phys. Rev. B 82, 245421 (2011)](https://journals.aps.org/prb/abstract/10.1103/PhysRevB.84.245421). ```python diff --git a/tutorials-v5/quantum-circuits/matrenderer-plot.md b/tutorials-v5/quantum-circuits/matrenderer-plot.md new file mode 100644 index 00000000..f18a24b1 --- /dev/null +++ b/tutorials-v5/quantum-circuits/matrenderer-plot.md @@ -0,0 +1,239 @@ +--- +jupyter: + jupytext: + text_representation: + extension: .md + format_name: markdown + format_version: '1.3' + jupytext_version: 1.16.4 + kernelspec: + display_name: qutip-dev + language: python + name: python3 +--- + +# Plotting and Customizing Quantum Circuits using MatRenderer + +Author: Rushiraj Gadhvi (gadhvirushiraj@gmail.com) + +This notebook serves as a comprehensive guide to plotting quantum circuits using QuTiP-QIP's MatRenderer, a Matplotlib-based rendering tool. It explores the various customization options available to users for creating and modifying plots. The content is organized into two main sections: + +- **Circuit-Level Customization** +- **Gate-Level Customization** + +```python +import qutip +import numpy as np +from qutip import Qobj +from qutip_qip.operations import rx +from qutip_qip.circuit import QubitCircuit +``` + +```python +qc = QubitCircuit(2, num_cbits=1) +qc.add_gate("CNOT", controls=0, targets=1) +qc.add_gate("SNOT", targets=1) +qc.add_gate("ISWAP", targets=[0, 1]) +qc.add_measurement("M0", targets=1, classical_store=0) +``` + +```python +qc.draw() +``` + +--- + +### Circuit Level Customization Options + +--- + +##### Changing FontSize + +```python +qc.draw(fontsize=13) +``` + +##### Background Color + +```python +qc.draw(bgcolor="gray") +``` + +##### Gate Bulge Control + +```python +qc.draw(bulge=False) +``` + +##### Custom Wire Labels + +```python +qc.draw(wire_label=["some_name", "some_long_name", "long_long_name"]) +``` + +##### Control extra wire extension at end of circuit + +```python +qc.draw(end_wire_ext=0) +``` + +```python +qc.draw(end_wire_ext=5) +``` + +##### Condense Circuit + +```python +qc.draw(gate_margin=0.1) +``` + +##### Adding Title + +```python +qc.draw(title="QuTiP") +``` + +##### Changing Theme + +```python +qc.draw(theme="light") +``` + +```python +qc.draw(theme="dark", title="QuTiP") +``` + +```python +qc.draw(theme="modern") +``` + +##### Aligning Layer + +```python +qc = QubitCircuit(3) +qc.add_gate("H", targets=[1]) +qc.add_gate("RZ", targets=[2], arg_value=0.5, style={"showarg": True}) +qc.add_gate("RZ", targets=[2], arg_value=0.5, style={"showarg": True}) +qc.add_gate("CNOT", controls=[0], targets=[1], style={"showarg": True}) +qc.add_gate("CNOT", controls=[0], targets=[1], style={"showarg": True}) +qc.add_gate("SWAP", targets=[0, 2]) +``` + +```python +# not-aligned gates +qc.draw(theme="modern") +``` + +```python +# aligned gates +qc.draw(align_layer=True, theme="modern") +``` + +--- + +### Gate Level Customization Options + +--- + +```python +qc = QubitCircuit(7) +qc.add_gate("H", targets=[0], style={"fontcolor": "red"}) +qc.add_gate("H", targets=[1], style={"fontstyle": "italic"}) +qc.add_gate("H", targets=[2], style={"fontweight": "bold"}) +qc.add_gate("H", targets=[3], style={"color": "green"}) +qc.add_gate("H", targets=[4], style={"fontsize": 12}) +qc.add_gate("H", targets=[5], arg_label="hadamard gate") +qc.add_gate("H", targets=[6], style={"fontfamily": "cursive"}) +``` + +```python +qc.draw() +``` + +##### Rendering Argument Value + +```python +qc = QubitCircuit(3) +qc.add_gate("RX", targets=[0], arg_value=np.pi / 12, style={"showarg": True}) +qc.add_gate( + "RY", targets=[1], arg_value=2 * np.pi / 3, style={"showarg": True} +) +qc.add_gate("RY", targets=[2], arg_value=0.3, style={"showarg": True}) +qc.draw() +``` + +#### With User Custom Gates + +```python +def user_gate1(arg_value): + # controlled rotation X + mat = np.zeros((4, 4), dtype=np.complex) + mat[0, 0] = mat[1, 1] = 1.0 + mat[2:4, 2:4] = rx(arg_value).full() + return Qobj(mat, dims=[[2, 2], [2, 2]]) + + +def user_gate2(): + # S gate + mat = np.array([[1.0, 0], [0.0, 1.0j]]) + return Qobj(mat, dims=[[2], [2]]) +``` + +```python +qc = QubitCircuit(3) +qc.user_gates = {"CTRLRX": user_gate1, "S": user_gate2} + +# qubit 1 controls qubit 0 +qc.add_gate("CTRLRX", targets=[1, 0], arg_value=np.pi / 2) +# qubit 2 is target of S gate +qc.add_gate("S", targets=[2]) +``` + +```python +qc.draw() +``` + +--- + +### Some more circuit examples + +--- + +```python +trotter_simulation_noisey = QubitCircuit(4) + +trotter_simulation_noisey.add_gate("RZ", targets=[0]) +trotter_simulation_noisey.add_gate("RZ", targets=[1]) + +trotter_simulation_noisey.add_gate("CNOT", controls=0, targets=1) +trotter_simulation_noisey.add_gate("RX", targets=[0]) +trotter_simulation_noisey.add_gate("CNOT", controls=0, targets=1) + +trotter_simulation_noisey.add_gate("CNOT", controls=0, targets=2) +trotter_simulation_noisey.add_gate("RX", targets=[0]) +trotter_simulation_noisey.add_gate("CNOT", controls=0, targets=2) + +trotter_simulation_noisey.add_gate("RZ", targets=[2], arg_value=-np.pi / 2) +trotter_simulation_noisey.add_gate("CNOT", controls=0, targets=2) +trotter_simulation_noisey.add_gate("RY", targets=[0]) +trotter_simulation_noisey.add_gate("CNOT", controls=0, targets=2) +trotter_simulation_noisey.add_gate("RZ", targets=[2], arg_value=np.pi / 2) + +trotter_simulation_noisey.add_gate("CNOT", controls=1, targets=3) +trotter_simulation_noisey.add_gate("RX", targets=[1]) +trotter_simulation_noisey.add_gate("CNOT", controls=1, targets=3) + +trotter_simulation_noisey.add_gate("RZ", targets=[3], arg_value=-np.pi / 2) +trotter_simulation_noisey.add_gate("CNOT", controls=1, targets=3) +trotter_simulation_noisey.add_gate("RY", targets=[1]) +trotter_simulation_noisey.add_gate("CNOT", controls=1, targets=3) +trotter_simulation_noisey.add_gate("RZ", targets=[3], arg_value=np.pi / 2) + +trotter_simulation_noisey.draw(theme="dark", title="Trotter Simulation") +``` + +--- + +```python +qutip.about() +``` diff --git a/tutorials-v5/quantum-circuits/qip-toffoli-cnot.md b/tutorials-v5/quantum-circuits/qip-toffoli-cnot.md index 3d933926..9c0d1f64 100644 --- a/tutorials-v5/quantum-circuits/qip-toffoli-cnot.md +++ b/tutorials-v5/quantum-circuits/qip-toffoli-cnot.md @@ -5,9 +5,9 @@ jupyter: extension: .md format_name: markdown format_version: '1.3' - jupytext_version: 1.13.8 + jupytext_version: 1.16.4 kernelspec: - display_name: Python 3 (ipykernel) + display_name: qutip-dev language: python name: python3 --- @@ -39,7 +39,7 @@ q.add_gate("TOFFOLI", controls=[0, 2], targets=[1]) ``` ```python -q.png +q.draw() ``` ```python @@ -53,7 +53,7 @@ q2 = q.resolve_gates() ``` ```python -q2.png +q2.draw() ``` ```python diff --git a/tutorials-v5/quantum-circuits/quantum-gates.md b/tutorials-v5/quantum-circuits/quantum-gates.md index ce71bb2a..a0d4b450 100644 --- a/tutorials-v5/quantum-circuits/quantum-gates.md +++ b/tutorials-v5/quantum-circuits/quantum-gates.md @@ -5,9 +5,9 @@ jupyter: extension: .md format_name: markdown format_version: '1.3' - jupytext_version: 1.13.8 + jupytext_version: 1.16.4 kernelspec: - display_name: Python 3 (ipykernel) + display_name: qutip-dev language: python name: python3 --- @@ -63,7 +63,7 @@ cphase(pi / 2) ```python q = QubitCircuit(2, reverse_states=False) q.add_gate("CSIGN", controls=[0], targets=[1]) -q.png +q.draw() ``` ### Rotation about X-axis @@ -74,8 +74,8 @@ rx(pi / 2) ```python q = QubitCircuit(1, reverse_states=False) -q.add_gate("RX", targets=[0], arg_value=pi / 2, arg_label=r"\frac{\pi}{2}") -q.png +q.add_gate("RX", targets=[0], arg_value=pi / 2, style={"showarg": True}) +q.draw() ``` ### Rotation about Y-axis @@ -86,8 +86,8 @@ ry(pi / 2) ```python q = QubitCircuit(1, reverse_states=False) -q.add_gate("RY", targets=[0], arg_value=pi / 2, arg_label=r"\frac{\pi}{2}") -q.png +q.add_gate("RY", targets=[0], arg_value=pi / 2, style={"showarg": True}) +q.draw() ``` ### Rotation about Z-axis @@ -98,8 +98,8 @@ rz(pi / 2) ```python q = QubitCircuit(1, reverse_states=False) -q.add_gate("RZ", targets=[0], arg_value=pi / 2, arg_label=r"\frac{\pi}{2}") -q.png +q.add_gate("RZ", targets=[0], arg_value=pi / 2, style={"showarg": True}) +q.draw() ``` ### CNOT @@ -111,7 +111,7 @@ cnot() ```python q = QubitCircuit(2, reverse_states=False) q.add_gate("CNOT", controls=[0], targets=[1]) -q.png +q.draw() ``` ### CSIGN @@ -123,7 +123,7 @@ csign() ```python q = QubitCircuit(2, reverse_states=False) q.add_gate("CSIGN", controls=[0], targets=[1]) -q.png +q.draw() ``` ### Berkeley @@ -135,7 +135,7 @@ berkeley() ```python q = QubitCircuit(2, reverse_states=False) q.add_gate("BERKELEY", targets=[0, 1]) -q.png +q.draw() ``` ### SWAPalpha @@ -162,7 +162,7 @@ toffoli() swap() q = QubitCircuit(2, reverse_states=False) q.add_gate("SWAP", targets=[0, 1]) -q.png +q.draw() ``` ### ISWAP @@ -171,7 +171,7 @@ q.png iswap() q = QubitCircuit(2, reverse_states=False) q.add_gate("ISWAP", targets=[0, 1]) -q.png +q.draw() ``` ### SQRTiSWAP @@ -234,7 +234,7 @@ cnot(N=3) ```python q = QubitCircuit(3, reverse_states=False) q.add_gate("CNOT", controls=[1], targets=[2]) -q.png +q.draw() ``` Furthermore, the control and target qubits (when applicable) can also be similarly specified using keyword arguments `control` and `target` (or in some cases `controls` or `targets`): @@ -246,7 +246,7 @@ cnot(N=3, control=2, target=0) ```python q = QubitCircuit(3, reverse_states=False) q.add_gate("CNOT", controls=[0], targets=[2]) -q.png +q.draw() ``` ## Setup of a Qubit Circuit @@ -261,7 +261,7 @@ In the following example, we take a SWAP gate. It is known that a swap gate is e N = 2 qc0 = QubitCircuit(N) qc0.add_gate("ISWAP", [0, 1], None) -qc0.png +qc0.draw() ``` ```python @@ -275,7 +275,7 @@ qc1 = QubitCircuit(N) qc1.add_gate("CNOT", 0, 1) qc1.add_gate("CNOT", 1, 0) qc1.add_gate("CNOT", 0, 1) -qc1.png +qc1.draw() ``` ```python @@ -288,7 +288,7 @@ In place of manually converting the SWAP gate to CNOTs, it can be automatically ```python qc2 = qc0.resolve_gates("CNOT") -qc2.png +qc2.draw() ``` ```python @@ -301,7 +301,7 @@ From QuTiP 4.4, we can also add gate at arbitrary position in a circuit. ```python qc1.add_gate("CSIGN", index=[1], targets=[0], controls=[1]) -qc1.png +qc1.draw() ``` ## Example of basis transformation @@ -313,7 +313,7 @@ qc3.add_gate("RX", 0, None, pi / 2, r"\pi/2") qc3.add_gate("RY", 1, None, pi / 2, r"\pi/2") qc3.add_gate("RZ", 2, None, pi / 2, r"\pi/2") qc3.add_gate("ISWAP", [1, 2]) -qc3.png +qc3.draw() ``` ```python @@ -325,7 +325,7 @@ U3 ```python qc4 = qc3.resolve_gates("CNOT") -qc4.png +qc4.draw() ``` ```python @@ -335,7 +335,7 @@ U4 ```python qc5 = qc3.resolve_gates("ISWAP") -qc5.png +qc5.draw() ``` ```python @@ -347,7 +347,7 @@ U5 ```python qc6 = qc3.resolve_gates(["ISWAP", "RX", "RY"]) -qc6.png +qc6.draw() ``` ```python @@ -357,7 +357,7 @@ U6 ```python qc7 = qc3.resolve_gates(["CNOT", "RZ", "RX"]) -qc7.png +qc7.draw() ``` ```python @@ -373,7 +373,7 @@ Interactions between non-adjacent qubits can be resolved by QubitCircuit to a se ```python qc8 = QubitCircuit(3) qc8.add_gate("CNOT", 2, 0) -qc8.png +qc8.draw() ``` ```python @@ -393,7 +393,7 @@ U9 ```python qc10 = qc9.resolve_gates("CNOT") -qc10.png +qc10.draw() ``` ```python diff --git a/tutorials-v5/quantum-circuits/textrenderer-plot.md b/tutorials-v5/quantum-circuits/textrenderer-plot.md new file mode 100644 index 00000000..fa773619 --- /dev/null +++ b/tutorials-v5/quantum-circuits/textrenderer-plot.md @@ -0,0 +1,119 @@ +--- +jupyter: + jupytext: + text_representation: + extension: .md + format_name: markdown + format_version: '1.3' + jupytext_version: 1.16.4 + kernelspec: + display_name: qutip-dev + language: python + name: python3 +--- + +# Plotting and Customizing Quantum Circuits using TextRenderer +Author: Rushiraj Gadhvi (gadhvirushiraj@gmail.com) + +This notebook serves as a comprehensive guide to plotting quantum circuits using QuTiP-QIP's TextRenderer. It explores the various customization options available to users for creating and modifying plots. + +- **Circuit-Level Customization** +- **Gate-Level Customization** + +```python +import qutip +import numpy as np +from qutip import Qobj +from qutip_qip.operations import rx +from qutip_qip.circuit import QubitCircuit +``` + +```python +qc = QubitCircuit(2, num_cbits=1) +qc.add_gate("CNOT", controls=0, targets=1) +qc.add_gate("SNOT", targets=1) +qc.add_gate("ISWAP", targets=[0, 1]) +qc.add_measurement("M0", targets=1, classical_store=0) +``` + +```python +qc.draw("text") +``` + +--- +### Circuit Level Customization Options +--- + + +##### Custom Wire Labels + +```python +qc.draw("text", wire_label=["some_name", "some_long_name", "long_long_name"]) +``` + +##### Control extra wire extension at end of circuit + +```python +qc.draw("text", end_wire_ext=0) +``` + +```python +qc.draw("text", end_wire_ext=5) +``` + +##### Adjust Gate Padding + +```python +qc.draw("text", gate_pad=3) +``` + +--- +### Gate Level Customization Options +--- + +```python +qc = QubitCircuit(2) +qc.add_gate("H", targets=[0]) +qc.add_gate("H", targets=[1], arg_label="hadamard gate") +``` + +```python +qc.draw("text") +``` + +#### With User Custom Gates + +```python +def user_gate1(arg_value): + # controlled rotation X + mat = np.zeros((4, 4), dtype=np.complex) + mat[0, 0] = mat[1, 1] = 1.0 + mat[2:4, 2:4] = rx(arg_value).full() + return Qobj(mat, dims=[[2, 2], [2, 2]]) + + +def user_gate2(): + # S gate + mat = np.array([[1.0, 0], [0.0, 1.0j]]) + return Qobj(mat, dims=[[2], [2]]) +``` + +```python +qc = QubitCircuit(3) +qc.user_gates = {"CTRLRX": user_gate1, "S": user_gate2} + +# qubit 1 controls qubit 0 +qc.add_gate("CTRLRX", targets=[1, 0], arg_value=np.pi / 2) +# qubit 2 is target of S gate +qc.add_gate("S", targets=[2]) +``` + +```python +qc.draw("text") +``` + +--- + +```python +qutip.about() +```