Diagrams#

This module provides classes for the creation of diagrams of quantum states, gates, and circuits.

It is not intended to be used directly by the user.

from qhronology.utilities import diagrams

Classes for the creation of diagrams of quantum states, gates, and circuits. Not intended to be used directly by the user.

class Families(
*values,
)[source]#
class Sections(
*values,
)[source]#
class Styles(
*values,
)[source]#
class Connections(
*values,
)[source]#
class Directions(
*values,
)[source]#
class DiagramCell(
*args,
family: str | None = None,
connections: dict[str, str] | None = None,
label: str | None = None,
quantikz_arguments: dict[str, str] | None = None,
**kwargs,
)[source]#

A class for visualizing individual “cells” (the smallest indivisible units) of quantum circuit diagrams and storing their metadata.

class DiagramColumn(
*args,
cells: list[DiagramCell],
section: str | None = None,
**kwargs,
)[source]#

A class for assembling a collection of DiagramCell instances into a column.

class DiagramCircuit(
*args,
columns: list,
**kwargs,
)[source]#

A class for assembling DiagramColumn instances together into a grid.

class VisualizationMixin[source]#

A mixin for endowing classes derived from the base class QuantumObject the ability to be visualized as quantum circuit diagram elements.

diagram(
pad: tuple[int, int] | None = None,
sep: tuple[int, int] | None = None,
style: str | None = None,
return_string: bool | None = None,
) None | str[source]#

Print or return a circuit diagram of the quantum object as a multiline string.

Parameters:
  • pad (tuple[int, int]) – A two-tuple describing the horizontal and vertical interior paddings between the content at the centre of the object (e.g., its label) and its outer edge (e.g., block border). Both integers must be non-negative. Defaults to (0, 0).

  • sep (tuple[int, int]) – A two-tuple describing the horizontal and vertical exterior separation distances at the object’s edges. Both integers must be non-negative. Defaults to (1, 1).

  • style (str) – A string specifying the style for the circuit visualization to take. Can be any of "ascii", "unicode", or "unicode_alt". Defaults to "unicode".

  • return_string (bool) – Whether to return the assembled diagram as a multiline string. Defaults to False.

Returns:

  • None – Returned only if return_string is False.

  • str – The rendered circuit diagram. Returned only if return_string is True.

Note

The quality of the visualization depends greatly on the output’s configuration. For best results, the terminal should have a monospace font with good Unicode coverage.