Hello Quantum for Jupyter notebook

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

  • List of gates applied to the initial 00 state to get the starting state of the puzzle.
  • Supported single qubit gates (applied to qubit '0' or '1') are 'x', 'y', 'z', 'h', 'ry(pi/4)'
  • Supported two qubit gates are 'cz' and 'cx'. For these, specify only the target qubit.
  • Example: initialize = [['x', '0'],['cx', '1']]

success_condition

  • Values for pauli observables that must be obtained for the puzzle to declare success.
  • Example: success_condition = {'IZ': 1.0}

allowed_gates

  • For each qubit, specify which operations are allowed in this puzzle.
  • For operations that don't need a qubit to be specified ('cz' and 'unbloch'), assign the operation to 'both' instead of qubit '0' or '1'.
  • Gates are expressed as a dict with an int as value.
    • If this is non-zero, it specifies the exact number of times the gate must be used for the puzzle to be successfully solved.
    • If it is zero, the player can use the gate any number of times.
  • Example: allowed_gates = {'0': {'h':0}, '1': {'h':0}, 'both': {'cz': 1}}

vi

  • Some visualization information as a three element list. These specify:
    • Which qubits are hidden (empty list if both shown).
    • Whether both circles shown for each qubit? (use True for qubit puzzles and False for bit puzzles).
    • Whether the correlation circles (the four in the middle) are shown.
  • Example: vi = [[], True, True]

qubit_names

  • The two qubits are always called '0' and '1' internally. But for the player, we can display different names.
  • Example: 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)


Your quantum program so far


In [ ]: