Helpers#
This module contains general helper functions.
It is not intended to be used directly by the user.
from qhronology.utilities import helpers
General helper functions. Not intended to be used directly by the user.
- flatten_list(
- nested_list: list,
Flatten a list of any nesting depth and structure, e.g.:
Examples
>>> flatten_list([1, [2, [3, [4]]]]) [1, 2, 3, 4]
>>> flatten_list([[1], [2], [3], [4]]) [1, 2, 3, 4]
- count_systems(
- matrix: MutableDenseMatrix,
- dim: int,
Count the number of
dim-dimensional subsystems which constitute the (composite) system represented bymatrix.
- count_dims(
- matrix: MutableDenseMatrix,
- systems: list[int],
Compute the dimensionality of the (composite) system represented by
matrix.
- check_systems_conflicts(
- *subsystems: list[int],
Check for conflicts (common element(s)) in the given (unpacked) tuple of lists. Returns
Trueif any are found, otherwiseFalse.
- adjust_targets(
- targets: list[int],
- removed: list[int],
Adjust the specified system indices (
targets) according to those which have been removed (removed) from the total set.
- arrange(
- positions: list[list[int]],
- items: list[Any],
Arranges the elements of
itemsthe according to the respective locations (e.g., system indices) inpositions. The main use case would be to arrange gates in a multipartite system.The lengths of both
positionsanditemsmust be the same, andpositionsmust not contain any missing system indices.Examples
>>> arrange([[0, 3], [1, 2]], ["a", "b"]) ['a', 'b', 'b', 'a']
- to_density(
- vector: MutableDenseMatrix,
Compute the outer product of
vectorwith itself, thereby converting any vector state into density matrix form. Leaves square matrices unaffected, and raises an error for non-square matrices.
- to_column(
- vector: MutableDenseMatrix,
Transpose
vectorinto its column form.
- stringify(
- matrix: MutableDenseMatrix,
- dim: int,
- delimiter: str | None = None,
- product: bool | None = None,
Render the mathematical expression (as a string) of the given
matrix.
- symbolize_expression(
- expression: MutableDenseMatrix | ndarray | Number | generic | Basic | MatrixSymbol | MatrixElement | Symbol | str,
- symbols: dict[MatrixSymbol | MatrixElement | Symbol | str, dict[str, Any]] | list[MatrixSymbol | MatrixElement | Symbol] | None = None,
Sympify a numerical, symbolic, or string expression, and replace the symbols with given counterparts.
- symbolize_tuples(
- conditions: list[tuple[Number | generic | Basic | MatrixSymbol | MatrixElement | Symbol | str, Number | generic | Basic | MatrixSymbol | MatrixElement | Symbol | str]],
- symbols_list: list[MatrixSymbol | MatrixElement | Symbol],
Sympify the numerical, symbolic, or string expression pairs within tuples of the list
conditionsand replace the symbols with given counterparts.
- recursively_simplify(
- expression: MutableDenseMatrix | ndarray | Number | generic | Basic | MatrixSymbol | MatrixElement | Symbol,
- conditions: list[tuple[Number | generic | Basic | MatrixSymbol | MatrixElement | Symbol, Number | generic | Basic | MatrixSymbol | MatrixElement | Symbol]] | None = None,
- limit: int | None = None,
- comprehensive: bool | None = None,
Simplify
expressionrecursively using the substitutions given inconditions. Runs untilexpressionis unchanged from the previous iteration, or until thelimitnumber of iterations is reached. IfcomprehensiveisFalse, the algorithm uses a relatively efficient subset of simplifying operations, otherwise it uses a larger, more powerful (but slower) set.
- extract_matrix(
- operator: mat | arr | QuantumObject,
Extract the SymPy matrix from the
operatorobject.
- extract_conditions(
- *states,
Extract any substitution conditions accessible via the
conditionsproperty from the objects instates.
- extract_symbols(
- *states,
Extract any SymPy symbols accessible via the
symbolsproperty from the objects instates.
- apply_function(
- matrix: MutableDenseMatrix,
- function: Callable,
- arguments: list[Any] | None = None,
Applies a function to a matrix. This is accomplished using eigendecomposition, in which the specified matrix is assumed to be normal (i.e.,
matrix * Dagger(matrix) = Dagger(matrix) * matrix, which holds true for density operators).
- default_arguments(
- arguments,
- kwarguments,
- class_object,
- arg_pairs: list[tuple[str, Any]],
Change the default value of an argument in a subclass’s constructor.
class_objectis the class whose__init__signature is to be targeted.
- fix_arguments(
- arguments,
- kwarguments,
- class_object,
- arg_pairs: list[tuple[str, Any]],
Fix the value of an argument in a subclass’s constructor. The argument
class_objectis the class whose__init__signature is to be targeted.
- assemble_composition(
- *pairs: tuple[MutableDenseMatrix, list[int]],
Assemble a composite state from constituent subsystems described by the items in
pairs. For each pair: - the first element is the subsystem’s state matrix. - the second element is the list of indices of its systems.