-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a full-featured serializer from a
qiskit.QuantumCircuit
to a `q…
…uantum-viz.js` JSON (#44)
- Loading branch information
Showing
19 changed files
with
3,170 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Display a Qiskit circuit\n", | ||
"\n", | ||
"This sample shows how to visualizes a circuit built using Qiskit using the Viewer widget.\n", | ||
"\n", | ||
"First, create any Qiskit circuit:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit\n", | ||
"\n", | ||
"qr = QuantumRegister(3, 'q')\n", | ||
"anc = QuantumRegister(1, 'ancilla')\n", | ||
"cr = ClassicalRegister(3, 'c')\n", | ||
"qc = QuantumCircuit(qr, anc, cr)\n", | ||
"\n", | ||
"\n", | ||
"qc.h(qr[0:3])\n", | ||
"qc.x(anc[0])\n", | ||
"qc.h(anc[0])\n", | ||
"qc.cx(qr[0:3], anc[0])\n", | ||
"qc.h(qr[0:3])\n", | ||
"qc.barrier(qr)\n", | ||
"qc.measure(qr, cr)\n", | ||
"\n", | ||
"qc.draw()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Then use the `Viewer` to render the circuit on Jupyter:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from quantum_viz import Viewer\n", | ||
"\n", | ||
"Viewer(qc)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Optionally, you can import the `display` method to render the circuit on a new browser window:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from quantum_viz.utils import display\n", | ||
"\n", | ||
"display(qc)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"interpreter": { | ||
"hash": "2c5b1a7a6495a30544972baa96a8850cbe45fafa3dce99d03214c29b73e345ae" | ||
}, | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
## | ||
# This script shows how to display a Qiskit circuit on a new browser window rendered using the Viewer. | ||
## | ||
from qiskit.circuit.random import random_circuit | ||
from qiskit.circuit.reset import Reset | ||
from quantum_viz.utils import display | ||
|
||
qc = random_circuit(4, 5, measure=False, reset=True, conditional=False) | ||
qc.barrier() | ||
qc.rccx(0, 3, 2) | ||
qc.sxdg(1) | ||
qc.append(Reset(), [1]) | ||
|
||
print(qc.draw()) | ||
display(qc, skip_barriers=False, style="BlackAndWhite", version="1.0.2") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.