acetn.model package
Subpackages
Submodules
acetn.model.model module
- class acetn.model.model.Model(config)
Bases:
ABCAbstract base class for quantum models.
This class provides the basic structure for a quantum model, including methods to access one-site and two-site Hamiltonians, observables, and bond directions. It must be extended by specific models like IsingModel or HeisenbergModel.
Attributes:
- configdict
A dictionary containing the model configuration (name, params, dtype, device, dim).
- namestr
The name of the model (e.g., “Ising”, “Heisenberg”).
- paramsdict
A dictionary containing the model parameters (e.g., interaction strengths).
- dtypetorch.dtype
The data type of the model (e.g., torch.float32).
- devicetorch.device
The device where the model will run (e.g., CPU or GPU).
- dimdict
A dictionary containing the model dimensions (physical dimension).
Methods:
- bond_direction(bond):
Returns the direction associated with a given bond.
- one_site_observables(site=None):
Returns a dictionary of one-site observables for the given site.
- two_site_observables(bond=None):
Returns a dictionary of two-site observables for the given bond.
- one_site_hamiltonian(site=None):
Returns the one-site Hamiltonian for the given site.
- two_site_hamiltonian(bond=None):
Abstract method for calculating the two-site Hamiltonian for the given bond.
- static bond_direction(bond)
Determines the direction of a given bond.
Parameters:
- bondlist
A list representing the bond, where the third element indicates the bond direction.
Returns:
- str
The bond direction (‘-x’, ‘+y’, ‘+x’, ‘-y’) or None if the bond direction is unrecognized.
- initial_site_state(site)
Determines the site tensor state used to initialize a tensor-network product state.
Parameters:
- sitetuple
The site for which to return the one-site Hamiltonian (default: None).
Returns:
- list
The state of a site tensor.
- one_site_hamiltonian(site=None)
Returns the one-site Hamiltonian for a given site.
This is a placeholder method intended to be overridden in subclasses.
Parameters:
- siteoptional
The site for which to return the one-site Hamiltonian (default: None).
Returns:
- torch.Tensor or None
The one-site Hamiltonian as a tensor, or None if not defined.
- one_site_observables(site=None)
Returns a dictionary of one-site observables for a given site.
This is a placeholder method intended to be overridden in subclasses.
Parameters:
- siteoptional
The site for which to return the one-site observables (default: None).
Returns:
- dict
A dictionary of one-site observables.
- abstract two_site_hamiltonian(bond=None)
Abstract method to compute the two-site Hamiltonian for a given bond.
This method must be implemented by subclasses.
Parameters:
- bondoptional
The bond for which to return the two-site Hamiltonian (default: None).
Returns:
- torch.Tensor
The two-site Hamiltonian as a tensor.
- two_site_observables(bond=None)
Returns a dictionary of two-site observables for a given bond.
This is a placeholder method intended to be overridden in subclasses.
Parameters:
- bondoptional
The bond for which to return the two-site observables (default: None).
Returns:
- dict
A dictionary of two-site observables.
acetn.model.model_factory module
- class acetn.model.model_factory.ModelFactory
Bases:
objectA factory class for creating and managing model instances.
The ModelFactory class allows for the registration of different model classes and the creation of model instances based on a string identifier. It ensures that models are properly registered and instantiated using the provided configuration.
- Attributes:
_models (dict): A dictionary mapping model names (strings) to their corresponding model classes.
- create(config)
Creates an instance of a model based on the registered model name.
This method instantiates a model class that has been registered under the specified name and initializes it with the provided configuration.
- Args:
name (str): The name of the registered model. config (dict): A configuration dictionary to initialize the model.
- Raises:
KeyError: If the provided model name is not registered.
- Returns:
Model: An instance of the registered model class initialized with the provided configuration.
- list_registered()
Lists all the registered model names.
This method returns a list of all model names that have been registered with the factory.
- Returns:
list: A list of strings representing the names of all registered models.
- register(name, cls)
Registers a new model class under a given name.
This method allows users to register new model classes with the factory. The registered class must inherit from the Model base class.
- Args:
name (str): The name associated with the model class. cls (type): The model class that is to be registered.
- Raises:
TypeError: If the provided class does not inherit from the Model base class.
- Returns:
None
acetn.model.pauli_matrix module
- class acetn.model.pauli_matrix.PauliMatrix(key, dtype, device, mat=None)
Bases:
objectA class that represents a Pauli matrix or identity matrix.
This class allows operations with Pauli matrices and supports multiplication, addition, subtraction, negation, and division. The matrices are represented as tensors, and the operations are performed using PyTorch. The class can handle the four standard Pauli matrices (‘X’, ‘Y’, ‘Z’, ‘I’) and allows scaling and Kronecker product operations.
- Attributes:
key (str): A key representing the Pauli matrix (‘X’, ‘Y’, ‘Z’, ‘I’). dtype (torch.dtype): The data type for the matrix. device (torch.device): The device (e.g., CPU or CUDA) on which the matrix resides. mat (torch.Tensor): The Pauli matrix or identity matrix represented as a tensor.
- mat = None
- acetn.model.pauli_matrix.pauli_matrices(dtype, device)
Creates and returns the four Pauli matrices (X, Y, Z, I) as instances of the PauliMatrix class.
Parameters:
- dtypetorch.dtype
The data type of the Pauli matrices (e.g., torch.float32, torch.float64).
- devicetorch.device
The device on which the Pauli matrices will be allocated (e.g., CPU or GPU).
Returns:
- tuple
A tuple containing the four Pauli matrices (X, Y, Z, I) as instances of the PauliMatrix class.