matchcake.base package¶
Submodules¶
matchcake.base.lookup_table module¶
- class matchcake.base.lookup_table.NonInteractingFermionicLookupTable(transition_matrix: TensorLike, *, cache_observables: bool = False, **kwargs)¶
Bases:
object
Lookup table for the non-interacting fermionic device.
- Parameters:
transition_matrix (TensorLike) – The transition matrix of the device.
show_progress (bool) – Whether to show progress bars.
The lookup table is a 3x3 matrix where the rows and columns are labeled by the following: - 0: c_d_alpha - 1: c_e_alpha - 2: c_2p_alpha_m1
# TODO: Add more documentation. # TODO: Tips for optimization: Maybe there is a way to use the sparsity of the block diagonal matrix to reduce # TODO: the number of operations in the lookup table.
- ALL_1D_INDEXES = array([0, 1, 2, 3, 4, 5, 6, 7, 8])¶
- ALL_2D_INDEXES = array([[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]])¶
- DEFAULT_CACHE_OBSERVABLES = False¶
- __init__(transition_matrix: TensorLike, *, cache_observables: bool = False, **kwargs)¶
- assert_binary(binary_state: ndarray) bool ¶
Check if the binary state contains only zeros or ones. If not, a value error will be raised.
- Parameters:
binary_state (np.ndarray) – Input binary state.
- Returns:
Whether the input state is binary or not.
- Return type:
bool
- Raises:
ValueError
- property batch_size¶
- property block_bm_transition_dagger_matrix¶
- property block_bm_transition_transpose_matrix¶
- property block_diagonal_matrix¶
- property c_2p_alpha_m1__c_2p_beta_m1¶
- property c_2p_alpha_m1__c_d_beta¶
- property c_2p_alpha_m1__c_e_beta¶
- property c_d_alpha__c_2p_beta_m1¶
- property c_d_alpha__c_d_beta¶
- property c_d_alpha__c_e_beta¶
- property c_e_alpha__c_2p_beta_m1¶
- property c_e_alpha__c_d_beta¶
- property c_e_alpha__c_e_beta¶
- close_p_bar()¶
- compute_items(indexes: Iterable[Tuple[int, int]], close_p_bar: bool = True) List[TensorLike] ¶
Compute the items of the lookup table corresponding to the indexes.
- Parameters:
indexes – Indexes of the items to compute.
close_p_bar – Whether to close the progress bar.
- Returns:
The items of the lookup table corresponding to the indexes.
- compute_observable_of_target_state(system_state: int | ndarray | sparray, target_binary_state: ndarray | None = None, indexes_of_target_state: ndarray | None = None, **kwargs) TensorLike ¶
- compute_observables_of_target_states(system_state: int | ndarray | sparray, target_binary_states: ndarray | None = None, indexes_of_target_states: ndarray | None = None, **kwargs) TensorLike ¶
- compute_pfaffian_of_target_states(system_state: int | ndarray | sparray, target_binary_states: ndarray | None = None, indexes_of_target_states: ndarray | None = None, **kwargs) TensorLike ¶
- compute_stack_and_pad_items(indexes: Iterable[Tuple[int, int]], pad_value: Number = 0.0, close_p_bar: bool = True) TensorLike ¶
- convert_2d_indexes_to_1d_indexes(all_indexes, unique_indexes)¶
- extend_unique_indexes_to_all_indexes(all_indexes, unique_indexes)¶
- get_c_2p_alpha_m1__c_2p_beta_m1()¶
- get_c_2p_alpha_m1__c_d_beta()¶
- get_c_2p_alpha_m1__c_e_beta()¶
- get_c_d_alpha__c_2p_beta_m1()¶
- get_c_d_alpha__c_d_beta()¶
- get_c_d_alpha__c_e_beta()¶
- get_c_e_alpha__c_2p_beta_m1()¶
- get_c_e_alpha__c_d_beta()¶
- get_c_e_alpha__c_e_beta()¶
- get_observable(k: int, system_state: ndarray) ndarray ¶
TODO: change k to y* or wires Get the observable corresponding to the index k and the state.
- Parameters:
k (int) – Index of the observable
system_state (np.ndarray) – State of the system
- Returns:
The observable of shape (2(h + k), 2(h + k)) where h is the hamming weight of the state.
- Return type:
np.ndarray
- get_observable_of_target_state(system_state: int | ndarray | sparray, target_binary_state: ndarray | None = None, indexes_of_target_state: ndarray | None = None, **kwargs) TensorLike ¶
Get the observable corresponding to target_binary_state and the system_state.
- Parameters:
system_state (Union[int, np.ndarray, sparse.sparray]) – State of the system
target_binary_state (Optional[np.ndarray]) – Target state of the system
indexes_of_target_state (Optional[np.ndarray]) – Indexes of the target state of the system
- Returns:
The observable of shape (2(h + k), 2(h + k)) where h is the hamming weight of the system state.
- Return type:
np.ndarray
- get_observables_of_target_states(system_state: int | ndarray | sparray, target_binary_states: ndarray | None = None, indexes_of_target_states: ndarray | None = None, **kwargs) TensorLike ¶
Get the observable corresponding to target_binary_state and the system_state.
- Parameters:
system_state (Union[int, np.ndarray, sparse.sparray]) – State of the system
target_binary_states (Optional[np.ndarray]) – Target state of the system
indexes_of_target_states (Optional[np.ndarray]) – Indexes of the target state of the system
- Returns:
The observable of shape (2(h + k), 2(h + k)) where h is the hamming weight of the system state.
- Return type:
np.ndarray
- property getter_table: List[List[callable]]¶
- initialize_p_bar(*args, **kwargs)¶
- property memory_usage¶
Compute the memory usage of the lookup table in bytes.
- property memory_usage_in_gb¶
- property n_particles¶
- p_bar_set_n(n: int)¶
- p_bar_set_postfix(*args, **kwargs)¶
- p_bar_set_postfix_str(*args, **kwargs)¶
- property shape: Tuple[int, int]¶
- property stacked_items¶
- property transition_bm_block_matrix¶
- property transition_matrix¶
- update_p_bar(*args, **kwargs)¶
matchcake.base.matchgate module¶
- class matchcake.base.matchgate.Matchgate(params: MatchgateParams | ndarray | list | tuple, *, raise_errors_if_not_matchgate=False, **kwargs)¶
Bases:
object
A matchgate is a matrix of the form
\[\begin{split}\begin{pmatrix} a & 0 & 0 & b \\ 0 & w & x & 0 \\ 0 & y & z & 0 \\ c & 0 & 0 & d \end{pmatrix}\end{split}\]where \(a, b, c, d, w, x, y, z \in \mathbb{C}\). The matrix M can be decomposed as
\[\begin{split}A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}\end{split}\]and
\[\begin{split}W = \begin{pmatrix} w & x \\ y & z \end{pmatrix}\end{split}\]The matchgate is a unitary matrix if and only if the following conditions are satisfied:
\[M^\dagger M = \mathbb{I} \quad \text{and} \quad MM^\dagger = \mathbb{I}\]where \(\mathbb{I}\) is the identity matrix and \(M^\dagger\) is the conjugate transpose of \(M\), and the following condition is satisfied:
\[\det(A) = \det(W)\]The final form of the matchgate is
\[\begin{split}\begin{pmatrix} r_0 e^{i\theta_0} & 0 & 0 & (\sqrt{1 - r_0^2}) e^{i(\theta_2 + \theta_4 - (\theta_1+\pi))} \\ 0 & r_1 e^{i\theta_2} & (\sqrt{1 - r_1^2}) e^{i(\theta_2 + \theta_4 - (\theta_3+\pi))} & 0 \\ 0 & (\sqrt{1 - r_1^2}) e^{i\theta_3} & r_1 e^{i\theta_4} & 0 \\ (\sqrt{1 - r_0^2}) e^{i\theta_1} & 0 & 0 & r_0 e^{i(\theta_2 + \theta_4 - \theta_0)} \end{pmatrix}\end{split}\]with the parameters
\[r_0, r_1 \quad \text{and} \quad \theta_0, \theta_1, \theta_2, \theta_3, \theta_4\]with
\[\theta_i \in [0, 2\pi) \forall i in \{0, 1, 2, 3, 4\}\]Note that by setting the parameter \(\theta_4\) to \(-\theta_2\), the matchgate can be written as
\[\begin{split}\begin{pmatrix} r_0 e^{i\theta_0} & 0 & 0 & (\sqrt{1 - r_0^2}) e^{-i(\theta_1+\pi)} \\ 0 & r_1 e^{i\theta_2} & (\sqrt{1 - r_1^2}) e^{-i(\theta_3+\pi)} & 0 \\ 0 & (\sqrt{1 - r_1^2}) e^{i\theta_3} & r_1 e^{-i\theta_2} & 0 \\ (\sqrt{1 - r_0^2}) e^{i\theta_1} & 0 & 0 & r_0 e^{-i\theta_0} \end{pmatrix}\end{split}\]which set
\[\det(A) = \det(W) = 1\]- DEFAULT_USE_H_FOR_TRANSITION_MATRIX = False¶
- DEFAULT_USE_LESS_EINSUM_FOR_TRANSITION_MATRIX = False¶
- SPTM_CONTRACTION_PATH = None¶
- UNPICKEABLE_ATTRS = []¶
- __init__(params: MatchgateParams | ndarray | list | tuple, *, raise_errors_if_not_matchgate=False, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- property batch_size¶
- property batched_gate_data¶
- check_asserts()¶
- check_det_constraint() bool ¶
- check_m_dagger_m_constraint() bool ¶
- check_m_m_dagger_constraint() bool ¶
- property composed_hamiltonian_params: MatchgateComposedHamiltonianParams¶
- compute_all_attrs() None ¶
In the constructor of this object, not all the attributes are computed. This method will compute all the attributes of the object. The list of attributes computed are:
action_matrix
- Returns:
None
- compute_m_dagger_m()¶
- compute_m_m_dagger()¶
- find_hamiltonian_coefficients(order: int = 1, iterations: int = 100) ndarray ¶
Find the 2n x 2n matrix \(h\) of elements \(h_{\mu\nu}\) such that
\[M = \exp{-i\sum_{\mu\neq\nu = 1}^{2n} h_{\mu\nu} c_\mu c_\nu}\]where \(c_\mu\) is the \(\mu\)-th Majorana operator, \(M\) is the matchgate and \(n\) is the number of qubits which is equal to the number of rows and columns of the matchgate.
- Parameters:
order (int) – The order of the taylor expansion of the exponential.
- Returns:
The matrix of coefficients \(h\).
- Return type:
np.ndarray
- classmethod find_single_particle_transition_matrix_contraction_path(*operands, **kwargs)¶
- classmethod from_matrix(matrix: ndarray, *args, **kwargs) Matchgate ¶
Construct a Matchgate from a matrix if it is possible. The matrix must be a 4x4 matrix.
- Parameters:
matrix (np.ndarray) – The matrix to construct the Matchgate from.
- Returns:
The Matchgate constructed from the matrix.
- Return type:
- Raises:
ValueError – If the matrix is not a 4x4 matrix.
ValueError – If the matrix is not a matchgate.
- static from_sub_matrices(outer_matrix: ndarray, inner_matrix: ndarray) Matchgate | ndarray ¶
Construct a Matchgate from the sub-matrices \(A\) (outer matrix) and \(W\) (inner_matrix) defined as
\[\begin{split}A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}\end{split}\]and
\[\begin{split}W = \begin{pmatrix} w & x \\ y & z \end{pmatrix}\end{split}\]where \(a, b, c, d, w, x, y, z \in \mathbb{C}\). The matchgate is constructed as
\[\begin{split}\begin{pmatrix} a & 0 & 0 & b \\ 0 & w & x & 0 \\ 0 & y & z & 0 \\ c & 0 & 0 & d \end{pmatrix}\end{split}\]
- property gate_data¶
- get_all_params_set(make_params: bool = False)¶
Get all the parameters set in the matchgate. The parameters set are the attributes
polar_params
,standard_params
,hamiltonian_params
andcomposed_hamiltonian_params
.- Parameters:
make_params (bool) – If True, the parameters will be computed if they are not already computed.
- Returns:
A list of the parameters set.
- get_inner_determinant() float ¶
- get_outer_determinant() float ¶
- classmethod get_single_particle_transition_matrix_contraction_path(*operands, **kwargs)¶
- property hamiltonian_coefficients_params: MatchgateHamiltonianCoefficientsParams¶
- property hamiltonian_coeffs_matrix: ndarray¶
Since the Hamiltonian coefficients is a vector that represent the upper triangular part of a skew-symmetric 4x4 matrix, we can reconstruct the matrix using the following formula:
\[\begin{split}\begin{pmatrix} 0 & h_{0} & h_{1} & h_{2} \\ -h_{0} & 0 & h_{3} & h_{4} \\ -h_{1} & -h_{3} & 0 & h_{5} \\ -h_{2} & -h_{4} & -h_{5} & 0 \end{pmatrix}\end{split}\]where \(h_{i}\) is the \(i\)-th element of the Hamiltonian coefficients vector.
- Returns:
The Hamiltonian coefficients matrix.
- property hamiltonian_matrix¶
- property inner_gate_data¶
The gate data is the matrix
\[\begin{split}\begin{pmatrix} a & 0 & 0 & b \\ 0 & w & x & 0 \\ 0 & y & z & 0 \\ c & 0 & 0 & d \end{pmatrix}\end{split}\]where \(a, b, c, d, w, x, y, z \in \mathbb{C}\). The inner gate data is the following sub-matrix of the matchgate matrix:
\[\begin{split}\begin{pmatrix} w & x \\ y & z \end{pmatrix}\end{split}\]- Returns:
- static is_matchgate(matrix: ndarray) bool ¶
- property outer_gate_data¶
The gate data is the matrix
\[\begin{split}\begin{pmatrix} a & 0 & 0 & b \\ 0 & w & x & 0 \\ 0 & y & z & 0 \\ c & 0 & 0 & d \end{pmatrix}\end{split}\]where \(a, b, c, d, w, x, y, z \in \mathbb{C}\). The outer gate data is the following sub-matrix of the matchgate matrix:
\[\begin{split}\begin{pmatrix} a & b \\ c & d \end{pmatrix}\end{split}\]- Returns:
The outer gate data.
- property polar_params: MatchgatePolarParams¶
- property r¶
- static random() Matchgate ¶
Construct a random Matchgate.
- Returns:
A random Matchgate.
- Rtype Matchgate:
- property single_particle_transition_matrix¶
- property standard_hamiltonian_params: MatchgateStandardHamiltonianParams¶
- property standard_params: MatchgateStandardParams¶
- property thetas¶
- static to_sympy()¶
- property transition_matrix¶