Generators Reference
module generators
Submodules:
- language_model
- quantum_computing
- random
- structured
module generators.language_model
function p_first_and_last
Generates an einsum query and shape arguments for computing the distribution of the first and last observable in a model with the given parameters.
Args:
mera_depth
(int): Number of layers in a MERA network with 4th-order tensors.axis_size_hidden
(int): Domain size of hidden variables.axis_size_observable
(int): Domain size of observable variables.
Returns:
tuple[str, list[tuple[int, ...]]]
: The einsum format string, which is needed to compute the distribution, and the shapes of its arguments.
Example:
function sliding_likelihood
Generates an einsum query and shape arguments for computing the likelihood of the model on an imaginary batch of training data.
Args:
mera_depth
(int): Number of layers in a MERA network with 4th-order tensors.axis_size_hidden
(int): Domain size of hidden variables.axis_size_observable
(int): Domain size of observable variables.batch_size
(int): Number of context windows to compute the likelihood for.
Returns:
tuple[str, list[tuple[int, ...]]]
: The einsum format string, which is needed to compute the batch likelihood, and the shapes of its arguments.
Example:
module generators.quantum_computing
function matrix_product_state
Generates a matrix product state (MPS) for a quantum computing simulation.
Args:
n
(int): The number of sites in the MPS. Default is 100.phys_dim_min
(int): The minimum physical dimension of each site. Default is 10.phys_dim_max
(int): The maximum physical dimension of each site. Default is 200.bond_dim
(int): The bond dimension between neighboring sites. Default is 20.seed
(int): The seed for the random number generator. Default is None.
Returns:
tuple
: A tuple containing the einsum string and the shapes of the tensors in the MPS.
Example:
function maxcut
Generates a Max-Cut quantum circuit using the Quantum Approximate Optimization Algorithm (QAOA).
Args:
n
(int): Number of nodes in the graph (default: 24).reg
(int): Regularity of the graph (default: 3).p
(int): Number of QAOA steps (default: 3).seed
(int): Seed for random number generation (default: 1).
Returns:
tuple
: A tuple containing the input string and the arrays of the quantum circuit.
Example:
module generators.random
function regular
Create a random contraction equation that corresponds to a random regular graph.
The graph must not be connected and for large graphs it will very likely have several components
Args:
n
(int): The number of terms.reg
(int): The degree of the graph.d_min
(int, optional): The minimum size of an index.d_max
(int, optional): The maximum size of an index.seed
(None or int, optional): Seed fornetworkx
andnp.random.default_rng
for repeatability.
Returns:
Tuple[List[List[str]], List[str], List[Tuple[int]], Dict[str, int]]
: The inputs, output, shapes, and size dictionary.
Example:
function connected_hypernetwork
Generate a random connected Hyper Tensor Network (HTN).
Returns an einsum expressions string representing the HTN, shapes of the tensors and optionally a dictionary containing the index sizes.
Args:
number_of_tensors
(int): Number of tensors/arrays in the TN.regularity
(float): ‘Regularity’ of the TN. This determines how many indices/axes each tensor shares with others on average (not counting output indices, global dimensions, self edges and single summation indices).max_tensor_order
(int, optional): The maximum order (number of axes/dimensions) of the tensors. IfNone
, use an upper bound calculated from other parameters.max_edge_order
(int, optional): The maximum order of hyperedges.diagonals_in_hyper_edges
(bool, optional): Whether diagonals can appear in hyper edges, e.g. in “aab,ac,ad -> bcd” a is a hyper edge with a diagonal in the first tensor.number_of_output_indices
(int, optional): Number of output indices/axes (i.e. the number of non-contracted indices) including global dimensions. Defaults to 0 if global_dim = False, i.e., a contraction resulting in a scalar, and to 1 if global_dim = True.max_output_index_order
(int, optional): Restricts the number of times the same output index can occur.diagonals_in_output_indices
(bool, optional): Whether diagonals can appear in output indices, e.g. in “aab,ac -> abc” a is an output index with a diagonal in the first tensor.number_of_self_edges
(int, optional): The number of self edges/traces (e.g. in “ab,bcdd->ac” d represents a self edge).max_self_edge_order
(int, optional): The maximum order of a self edge e.g. in “ab,bcddd->ac” the self edge represented by d has order 3.number_of_single_summation_indices
(int, optional): The number of indices that are not connected to any other tensors and do not show up in the ouput (e.g. in “ab,bc->c” a is a single summation index).min_axis_size
(int, optional): Minimum size of an axis/index (dimension) of the tensors.max_axis_size
(int, optional): Maximum size of an axis/index (dimension) of the tensors.seed
(int, optional): If not None, seed numpy’s random generator with this.global_dim
(bool, optional): Add a global, ‘broadcast’, dimension to every operand.return_size_dict
(bool, optional): Return the mapping of indices to sizes.
Returns:
Tuple[str, List[Tuple[int]], Optional[Dict[str, int]]]
: The einsum expression string, the shapes of the tensors/arrays, and the dict of index sizes (only returned ifreturn_size_dict=True
).
Examples: ‘usual’ Tensor Hyper Networks
Tensor Hyper Networks with self edges (of higher order), single summation indices, output indices of higher order and a global dimension
Tensor Hyper Networks as above but with diagonals in hyper edges and output indices
function connected_network
Generate a random connected Tensor Network (TN).
Args:
number_of_tensors
(int): Number of tensors/arrays in the TN.regularity
(float): ‘Regularity’ of the TN. This determines how many indices/axes each tensor shares with others on average (not counting output indices and a global dimension).number_of_output_indices
(int, optional): Number of output indices/axes (i.e. the number of non-contracted indices) including the global dimension. Defaults to 0 in case of no global dimension, i.e., a contraction resulting in a scalar, and to 1 in case there is a global dimension.min_axis_size
(int, optional): Minimum size of an axis/index (dimension) of the tensors.max_axis_size
(int, optional): Maximum size of an axis/index (dimension) of the tensors.seed
(int, optional): If not None, seed numpy’s random generator with this.global_dim
(bool, optional): Add a global, ‘broadcast’, dimension to every operand.return_size_dict
(bool, optional): Return the mapping of indices to sizes.
Returns:
Tuple[str, List[Tuple[int]], Optional[Dict[str, int]]]
: The einsum expression string, the shapes of the tensors/arrays, and the dict of index sizes (only returned if return_size_dict=True).
Example:
module generators.structured
function generate_mcm
Generate a matrix chain multiplication problem.
Args:
num_matrices
(int): The number of matrices in the chain (default: 10).min_dim
(int): The minimum dimension of each matrix (default: 10).max_dim
(int): The maximum dimension of each matrix (default: 1000).is_shuffle
(bool): Whether to shuffle the einsum string and shapes (default: False).seed
(int): The seed value for reproducibility (default: None).
Returns:
tuple
: A tuple containing the einsum string and the shapes of the matrices.
Raises:
AssertionError
: If the lists of einsum string and shapes have different sizes.
Example:
function tree
Create a random contraction equation that corresponds to a tree.
Args:
n
(int): The number of tensors.d_min
(int, optional): The minimum size of an index.d_max
(int, optional): The maximum size of an index.n_outer
(int, optional): The number of outer indices.seed
(int, optional): Seed for generator.
Returns:
tuple
: A tuple containing the contraction equation format string and the shapes of the tensors.
function lattice
Create a random contraction equation that corresponds to a lattice.
Args:
dims
(sequence of int): The size of each dimension, with the dimensionality being the length of the sequence.cyclic
(bool or sequence of bool, optional): Whether each dimension is cyclic or not. If a sequence, must be the same length asdims
.d_min
(int, optional): The minimum size of an index.d_max
(int, optional): The maximum size of an index. IfNone
, defaults tod_min
, i.e. all indices are the same size.seed
(None or int, optional): Seed forrandom.Random
for repeatability.
Returns:
tuple
: A tuple containing the contraction equation format string and the shapes of the inputs.
Raises:
TypeError
: Ifcyclic
is a sequence but not the same length asdims
.