Circuit Plot#

Matplotlib based plotting of quantum circuits.

Todo:

  • Optimize printing of large circuits.

  • Get this to work with single gates.

  • Do a better job checking the form of circuits to make sure it is a Mul of Gates.

  • Get multi-target gates plotting.

  • Get initial and final states to plot.

  • Get measurements to plot. Might need to rethink measurement as a gate issue.

  • Get scale and figsize to be handled in a better way.

  • Write some tests/examples!

class sympy.physics.quantum.circuitplot.CircuitPlot(c, nqubits, **kwargs)[source]#

A class for managing a circuit plot.

control_line(gate_idx, min_wire, max_wire)[source]#

Draw a vertical control line.

control_point(gate_idx, wire_idx)[source]#

Draw a control point.

not_point(gate_idx, wire_idx)[source]#

Draw a NOT gates as the circle with plus in the middle.

one_qubit_box(t, gate_idx, wire_idx)[source]#

Draw a box for a single qubit gate.

swap_point(gate_idx, wire_idx)[source]#

Draw a swap point as a cross.

two_qubit_box(t, gate_idx, wire_idx)[source]#

Draw a box for a two qubit gate. Does not work yet.

update(kwargs)[source]#

Load the kwargs into the instance dict.

sympy.physics.quantum.circuitplot.CreateCGate(name, latexname=None)[source]#

Use a lexical closure to make a controlled gate.

class sympy.physics.quantum.circuitplot.Mx(*args, **kwargs)[source]#

Mock-up of an x measurement gate.

This is in circuitplot rather than gate.py because it’s not a real gate, it just draws one.

class sympy.physics.quantum.circuitplot.Mz(*args, **kwargs)[source]#

Mock-up of a z measurement gate.

This is in circuitplot rather than gate.py because it’s not a real gate, it just draws one.

sympy.physics.quantum.circuitplot.circuit_plot(c, nqubits, **kwargs)[source]#

Draw the circuit diagram for the circuit with nqubits.

Parameters

c : circuit

The circuit to plot. Should be a product of Gate instances.

nqubits : int

The number of qubits to include in the circuit. Must be at least as big as the largest min_qubits of the gates.

sympy.physics.quantum.circuitplot.labeller(n, symbol='q')[source]#

Autogenerate labels for wires of quantum circuits.

Parameters

n : int

number of qubits in the circuit.

symbol : string

A character string to precede all gate labels. E.g. ‘q_0’, ‘q_1’, etc.

>>> from sympy.physics.quantum.circuitplot import labeller

>>> labeller(2)

[‘q_1’, ‘q_0’]

>>> labeller(3,’j’)

[‘j_2’, ‘j_1’, ‘j_0’]