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(
- spec: mat | arr | list[list[num | expr | str]] | list[tuple[num | expr | str, int | list[int]]] | None = None,
- form: str | None = None,
- kind: str | None = None,
- dim: int | None = None,
- numerical: bool | None = None,
- array: bool | None = None,
- num_systems: int | None = None,
- symbols: dict[sym | str, dict[str, Any]] | None = None,
- substitutions: list[tuple[num | expr | str, num | expr | str]] | None = None,
- conjugate: bool | None = None,
- label: str | None = None,
- notation: str | None = None,
- family: str | None = None,
- debug: bool | None = None,
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.
- property spec: mat | arr | list[list[num | expr | str]] | list[tuple[num | expr | str, int | list[int]]]#
The specification of the quantum object. Provides a description of the object’s values in a standard
dim-dimensional basis.
- property current: mat | arr#
The current (unprocessed) matrix representation of the quantum object.
- matrix(
- numerical: bool | None = None,
- array: bool | None = None,
Compute the unprocessed matrix representation of the object.
- Parameters:
numerical (
bool) – Whether to cast the matrix elements as floating-point values (True) (if possible) or exact values (False). Defaults to the value ofself.numerical.array (
bool) – Whether to cast the matrix as a NumPy array (True) or SymPy matrix (False). Defaults to the value ofself.array.
- Returns:
mat | arr– The unprocessed matrix representation of the object.
- output(
- numerical: bool | None = None,
- array: bool | None = None,
- substitutions: list[tuple[num | expr | str, num | expr | str]] | None = None,
- simplify: bool | None = None,
- conjugate: bool | None = None,
Compute the processed matrix representation of the object.
- Parameters:
numerical (
bool) – Whether to cast the matrix elements as floating-point values (True) (if possible) or exact values (False). Defaults to the value ofself.numerical.array (
bool) – Whether to cast the matrix as a NumPy array (True) or SymPy matrix (False). Defaults to the value ofself.array.substitutions (
list[tuple[num | expr | str,num | expr | str]]) – Algebraic substitutions to be applied to the state. Defaults to the value ofself.substitutions.simplify (
bool) – Whether to perform mathematical simplification on the object. IfFalse, does not simplify. Defaults toFalse.conjugate (
bool) – Whether to perform Hermitian conjugation on the object. IfFalse, does not conjugate. Defaults to the value ofself.conjugate.
- Returns:
mat | arr– The processed matrix representation of the object.
- print(
- delimiter: str | None = None,
- product: bool | None = None,
- return_string: bool | None = None,
- numerical: bool | None = None,
- substitutions: list[tuple[num | expr | str, num | expr | str]] | None = None,
- simplify: bool | None = None,
- conjugate: bool | None = None,
Print or return a mathematical expression of the quantum object as a string.
Note that this method is essentially a wrapper on the
output()method, and so includes all of its arguments.- 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 toFalse.return_string (
bool) – Whether to return the mathematical expression as a string. Defaults toFalse.numerical (
bool) – Whether to cast the matrix elements as floating-point values (True) (if possible) or exact values (False). Defaults to the value ofself.numerical.substitutions (
list[tuple[num | expr | str,num | expr | str]]) – Algebraic substitutions to be applied to the object. Defaults to the value ofself.substitutions.simplify (
bool) – Whether to perform mathematical simplification on the object. IfFalse, does not simplify. Defaults toFalse.conjugate (
bool) – Whether to perform Hermitian conjugation on the object. IfFalse, does not conjugate. Defaults to the value ofself.conjugate.
- Returns:
None– Returned ifreturn_stringisFalse.str– The constructed mathematical expression. Returned ifreturn_stringisTrue.
- property form: str#
The form of the object. Can be either of
"vector"or"matrix". OnlyQuantumStateobjects can be"vector".
- property kind: str#
The kind of quantum object. Can be either of
"mixed"or"pure".
- property is_vector: bool#
Test for whether the object is a vector. Returns
Trueif so, otherwiseFalse.
- 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
labelproperty. Must have a non-zero length. Not intended to be set by the user in most cases.
- property family: str | list[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 conjugate: bool#
Whether to perform Hermitian conjugation on the object when it is called.
- property numerical: bool#
Whether to cast the object’s matrix elements as floating-point values or exact values.
- property array: bool#
Whether to cast the object’s matrix as a NumPy array or SymPy matrix.
- property debug: bool#
Whether to print the object’s matrix representation (stored in the
matrixproperty) on mutation.