Objects#

This module contains the base class for constructing quantum states and gates.

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

from qhronology.utilities import objects

The base class for constructing quantum states and gates. Not intended to be used directly by the user.

class QuantumObject(
form: str | None = None,
matrix: MutableDenseMatrix | None = None,
dim: int | None = None,
num_systems: int | None = None,
symbols: dict[MatrixSymbol | MatrixElement | Symbol | str, dict[str, Any]] | None = None,
conditions: list[tuple[Number | generic | Basic | MatrixSymbol | MatrixElement | Symbol | str, Number | generic | Basic | MatrixSymbol | MatrixElement | Symbol | str]] | None = None,
conjugate: bool | None = None,
label: str | None = None,
notation: str | None = None,
family: str | None = None,
debug: bool | None = None,
)[source]#

A base class forming the backbone of the QuantumState and QuantumGate classes.

Not intended to be instantiated directly itself, but rather indirectly via the constructors of its derived classes.

print(
delimiter: str | None = None,
product: bool | None = None,
return_string: bool | None = None,
) None | str[source]#

Print or return a mathematical expression of the quantum object as a string.

Parameters:
  • delimiter (str) – A string containing the character(s) with which to delimit (i.e., separate) the values in the ket and/or bra terms in the mathematical expression. Defaults to ",".

  • product (bool) – Whether to represent the mathematical expression using tensor products. Only applies if the object is a multipartite composition. Defaults to False.

  • return_string (bool) – Whether to return the mathematical expression as a string. Defaults to False.

Returns:

  • None – Returned only if return_string is False.

  • str – The constructed mathematical expression. Returned only if return_string is True.

output(
conditions: list[tuple[Number | generic | Basic | MatrixSymbol | MatrixElement | Symbol | str, Number | generic | Basic | MatrixSymbol | MatrixElement | Symbol | str]] | None = None,
simplify: bool | None = None,
conjugate: bool | None = None,
) MutableDenseMatrix[source]#

Return the object’s simplified matrix representation.

Parameters:
  • conditions (list[tuple[num | sym | str, num | sym | str]]) – Algebraic conditions to be applied to the state. Defaults to the value of self.conditions.

  • simplify (bool) – Whether to perform algebraic simplification on the object. Defaults to False.

  • conjugate (bool) – Whether to perform Hermitian conjugation on the object. If False, does not conjugate. Defaults to the value of self.conjugate.

Returns:

mat – The object’s simplified matrix representation.

property form: str#

The form of the object. Can be either of "vector" or "matrix". Only QuantumState objects can be "vector".

property is_vector: bool#

Test for whether the object is a vector. Returns True if so, otherwise False.

property dim: int#

The dimensionality of the quantum object. Must be a non-negative integer.

property label: str#

The unformatted string used to represent the object in mathematical expressions. Must have a non-zero length.

property labels: list[str]#

An ordered list of the object’s labels corresponding to its boundaries. Used exclusively by the visualization engine.

property notation: str#

The formatted string used to represent the object in mathematical expressions. When set, overrides the value of the label property. Must have a non-zero length. Not intended to be set by the user in most cases.

property family: str#

The code of the block element that the object is to be visualized as. Not intended to be set by the user.

property boundaries: list[int]#

An ordered list of indices of the object’s boundaries corresponding to its labels. Used exclusively by the visualization engine.

property num_systems: int#

The number of systems that the object spans. Must be a non-negative integer. Should not be set for states.

property systems: list[int]#

Read-only property containing an ordered list of the numerical indices of the object’s systems.

property targets: list[int]#

An ordered list of the numerical indices of the object’s target systems.

property controls: list[int]#

An ordered list of the numerical indices of the object’s control systems.

property anticontrols: list[int]#

An ordered list of the numerical indices of the object’s anticontrol systems.

property matrix: MutableDenseMatrix#

The matrix representation of the object.

Considered read-only (this is strictly enforced by QuantumGate class and its derivatives), though can be (indirectly) mutated by some derived classes (such as QuantumState). Not intended to be set directly by the user.

property conjugate: bool#

Whether to perform Hermitian conjugation on the object when it is called.

property debug: bool#

Whether to print the object’s matrix representation (stored in the matrix property) on mutation.