matchcake.base package¶
Submodules¶
matchcake.base.lookup_table module¶
- class matchcake.base.lookup_table.NonInteractingFermionicLookupTable(transition_matrix: TensorLike, **kwargs)¶
Bases:
objectRepresents a lookup table for computations related to non-interacting fermionic systems.
This class is designed to handle the Lookup table describe in [] . More specifically, it is design to find the tensor that represents the contraction of the summation
\[p(y^{*}|x) &= \prod_{\gamma = 1}^{k}\sum_{m_{\gamma},n_{\gamma} = 1}^{2N} T_{j_\gamma,m_\gamma}T_{j_\gamma,n_\gamma}^* \left\langle \boldsymbol{0} \left|c_{2p_{\ell}}..c_{2p_1}\left(\prod_{\gamma = 1}^{k} c_{m_{\gamma}}c_{n_{\gamma}}\right)c_{2p_1}..c_{2p_{\ell}} \right|\boldsymbol{0}\right\rangle.\]where \(c\) are the majoranas fermions, \(y^*\) is the target output state, \(x\) is the system state and \(T\) is the given transition matrix of the circuit or of the system evolution.
# TODO: Make it a torch function to output the analytical grad instead of creating a huge computational graph # TODO: during the current computation. # 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.
- Variables:
ALL_2D_INDEXES – Stores all possible 2D indexes for a system with three rows.
ALL_1D_INDEXES – Contains converted 1D indexes corresponding to the 2D indexes.
p_bar – Progress bar object used for tracking computation, can be None if disabled.
show_progress – Indicates if progress tracking through a progress bar should be enabled.
- 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]])¶
- __call__(system_state: int | ndarray | sparray, target_binary_states: ndarray | None = None, indexes_of_target_states: ndarray | None = None, **kwargs) TensorLike¶
Get the contracted tensor 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 tensor of shape (2(h + k), 2(h + k)) where h is the hamming weight of the system state representing the action of the transition matrix on the system.
- Return type:
np.ndarray
- __init__(transition_matrix: TensorLike, **kwargs)¶
Represents a class that contract the action of the given transition matrix on a free fermionic system into a tensor.
- Parameters:
transition_matrix – A tensor or array-like structure representing the transition matrix for the system.
kwargs –
Additional keyword arguments. Optional argument: -
show_progress(bool): Indicates whether to show progress duringoperations. Default is
False.
- property batch_size¶
- property block_bm_transition_dagger_matrix¶
- property block_bm_transition_transpose_matrix¶
- property block_diagonal_matrix¶
The block diasgonal matrix \(B\) is a \(2N \times 2N\) Hermitian matrix block diagonal matrix containing \(N\) number of \(2 \times 2\) blocks
\[\begin{split}B = \left( \begin{matrix} 1 & i & & & &\\ -i & 1 & & & &\\ & & & \ddots & & \\ & & & & 1 & i \end{matrix} \right) = \bigoplus_{l = 1}^{N} \left( \begin{matrix} 1 & i \\ -i & 1 \end{matrix} \right).\end{split}\]- Returns:
the \(B\) matrix.
- property c_2p_alpha_m1__c_2p_beta_m1: TensorLike¶
- property c_2p_alpha_m1__c_d_beta: TensorLike¶
- property c_2p_alpha_m1__c_e_beta: TensorLike¶
- property c_d_alpha__c_2p_beta_m1: TensorLike¶
- property c_d_alpha__c_d_beta: TensorLike¶
- property c_d_alpha__c_e_beta: TensorLike¶
- property c_e_alpha__c_2p_beta_m1: TensorLike¶
- property c_e_alpha__c_d_beta: TensorLike¶
- property c_e_alpha__c_e_beta: TensorLike¶
- close_p_bar()¶
- 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 the observable of a target state from the given system state.
This method calculates the quantum observable corresponding to a specific target state defined by the binary representation or the specified indices. If the resulting observable has multiple dimensions beyond the expected output shape, it will be reshaped accordingly. This accounts for scenarios where batch processing is not specified or when multi-dimensional shapes arise.
- Parameters:
system_state – The current state of the system, which can be an integer, a Numpy array, or a sparse array.
target_binary_state – Optional Numpy array representing the binary configuration of the target state.
indexes_of_target_state – Optional Numpy array containing the indices corresponding to the target state.
kwargs – Arbitrary keyword arguments for additional configurations or parameters.
- Returns:
A tensor-like object representing the observable(s) of the target state. The shape of the output may vary depending on the dimensional nature of the input and batch configurations.
- 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¶
Computes observables for target quantum states based on the provided system state and configuration.
This function processes the system state and a set of target binary states or their respective indexes to calculate observables. It constructs the necessary indices, computes intermediary terms required for observables, and combines them into the final observable tensor. The resulting observables capture quantum correlations and measurements over the target states.
- Parameters:
system_state – The state of the system, which can be an integer, a numpy array, or a sparse array.
target_binary_states – Optional numpy array of the target binary states. Represents the configurations of the target quantum states.
indexes_of_target_states – Optional numpy array of indices corresponding to target states. If provided, these indices specify which states to compute observables for.
kwargs – Additional keyword arguments to configure or modify the behavior of the computations.
- Returns:
The computed tensor-like object representing the observables for the target states. The tensor reflects quantum measurements and correlations for the given configurations.
- 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()¶
- property getter_table: List[List[callable]]¶
- initialize_p_bar(*args, **kwargs)¶
- 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)¶
Updates the progress bar with the given arguments and refreshes its state. This method safeguards the operation if the progress bar is not initialized.
- Parameters:
args – Positional arguments to pass to the progress bar’s update method.
kwargs – Keyword arguments to pass to the progress bar’s update method.
- Returns:
None