Hello Quantum is a project based on the idea of visualizing two qubit states and gates, and making them accessible to a non-specialist audience.
In the hello_quantum.py file you'll find some tools with which the 'Hello Quantum' visualizations and puzzles can be implemented in Jupyter notebooks. These were used to create the puzzles in the Hello_Qiskit notebook, but you can also create your own custom ones. These could then be used as part of presentations given about Qiskit, or self-study materials prepared for people learning Qiskit.
To use it, import hello_quantum
and use matplotlib magic.
In [1]:
%matplotlib notebook
import hello_quantum
The import here was very simple, because this notebook is in the same folder as the hello_quantum.py file. If this is not the case, you'll have to change the path. See the Hello_Qiskit notebook for an example of this.
Once the import has been done, you can set up and display the visualization.
In [2]:
grid = hello_quantum.pauli_grid()
grid.update_grid()
This has attributes and methods which create and run quantum circuits with Qiskit.
In [3]:
for gate in [['x','1'],['h','0'],['z','0'],['h','1'],['z','1']]:
command = 'grid.qc.'+gate[0]+'(grid.qr['+gate[1]+'])'
eval(command)
grid.update_grid()
There is also an alternative visualization, which can be used to better represent non-Clifford gates.
In [4]:
grid = hello_quantum.pauli_grid(mode='line')
grid.update_grid()
The run_game
function, can also be used to implement custom 'Hello Quantum' games within a notebook. This is called with
hello_quantum.run_game(initialize, success_condition, allowed_gates, vi, qubit_names)
where the arguments set up the puzzle by specifying the following information.
initialize
00
state to get the starting state of the puzzle.initialize = [['x', '0'],['cx', '1']]
success_condition
success_condition = {'IZ': 1.0}
allowed_gates
allowed_gates = {'0': {'h':0}, '1': {'h':0}, 'both': {'cz': 1}}
vi
True
for qubit puzzles and False
for bit puzzles).vi = [[], True, True]
qubit_names
qubit_names = {'0':'qubit 0', '1':'qubit 1'}
The puzzle defined by the examples given here can be run in the following cell. See also the many examples in the Hello_Qiskit notebook.
In [5]:
initialize = [['x', '0'],['cx', '1']]
success_condition = {'IZ': 1.0}
allowed_gates = {'0': {'h':0}, '1': {'h':0}, 'both': {'cz': 1}}
vi = [[], True, True]
qubit_names = {'0':'qubit 0', '1':'qubit 1'}
puzzle = hello_quantum.run_game(initialize, success_condition, allowed_gates, vi, qubit_names)
In [ ]: