The Stacasso Guide (Notebook)

Stacasso is a Python library for visualizing quantum computing circuits. See * Stacasso README, or view the project on GitHub for more information.

The original project notebook can be viewed online at Stacasso Guide (Notebook)

This notebook can be rendered to .html with

time jupyter nbconvert --to html --execute stacasso_guide.ipynb

Using Stacasso

Stacasso is extremely easy to use. For installation, see the README. Stacasso is typically imported with

import stacasso as so

There are two or three main functions, exposed to the user:

pprint( circuit, title=None, spacing=6 )

The "pretty-print" displays the circuit to the string like the standard print(circuit) command, but add syntax highlighting. By default, the circuit is spaced wider than in the original cirq code; this is adjustable with the spacing parameter.

highlight( circuit, title=None, spacing=6 )

The highlight command works like pretty-print, but returns the syntax highlighted code as an html string. The string can copied directly into a markdown or .html file, to render a syntax-highlighted version of the circuit.

illustrate( circuit, labels )

Stacasso can Illustrate the state (wavefuction) of the circuit as it executes. The simulation is done using cirq as a backend. The wavefunction is drawn after each moment (unitary transform), on grid representing the state-space ("Hilbert-space").

Setup and Imports

Quantum Random Number Generator

A Hadamard transformation put the bit into an equal superpositon of two states.

Upon measument, it will collapse to one of two states ("quantum coin flip").

This circuit is not useful in itself, but demonstrates the use of the H gate to create superposition, one of the building blocks of quantum circuits.

Bell State

Bell States are made from maximially entangling two photons. It is one of the most fundamental quantum mechanical circuits.

Quantum Teleportation

Textbook algorithms in Cirq (Quantum Teleportation)

HLF 2D

Hidden linear function problem

Visualizing Amplitudes and Probabilites

Creates a test_state out of two qubits. The state is a superposition, each in a different phase, to demonstrate visual represnting probability amplitudes and phases.

One of the contral notions in quantum computation is the notion that you are not computing with classical probability, which is a real number between zero and one. (Classically, an event can be said to occur with a chance between 0 and 100%.)

In quantum theory, the state of a system is described not be classical probabilies, but by complex amplitudes. Amplitudes have a magitude between zero (no chance) and one (certainty), but additionally have phase information, which is discarded in classical probability, but becomes an important tool in quantum computation.

Moreover, the gates in quantum computing operate on these complex amplitudes, rather than probabilities.

The classical probability is the square of the amplitude

Amplitudes are described by a magnitude between zero and one Like probabilies, amplitudes can have a magnitude between zero (no chance) and one (a certainty).