gflownet.envs.crystals.lattice_parameters
Classes to represent continuous lattice parameters environments.
An implementation for discrete lattice parameters preceded this one but has been removed for simplicity. Check commit 9f3477d8e46c4624f9162d755663993b83196546 to see these changes or the history previous to that commit to consult previous implementations.
Attributes
Classes
Module Contents
- gflownet.envs.crystals.lattice_parameters.ANGLE_PARAMETER_NAMES = ('alpha', 'beta', 'gamma')[source]
- gflownet.envs.crystals.lattice_parameters.PARAMETER_NAMES = ('a', 'b', 'c', 'alpha', 'beta', 'gamma')[source]
- class gflownet.envs.crystals.lattice_parameters.LatticeParameters(lattice_system, min_length=1.0, max_length=350.0, min_angle=50.0, max_angle=150.0, **kwargs)[source]
Bases:
gflownet.envs.composite.stack.Stack- Parameters:
lattice_system (str) – One of the seven lattice systems. By default, the triclinic lattice system is used, which has no constraints.
min_length (float) – Minimum value of the lengths.
max_length (float) – Maximum value of the lengths.
min_angle (float) – Minimum value of the angles.
max_angle (float) – Maximum value of the angles.
- get_lattice_system_idx(state)[source]
Returns the lattice system index, retrieved from the condition state.
- Parameters:
state (dict) – A state in environment format.
- Returns:
int – The index of the lattice system contained in the condition state.
- Return type:
int
- get_lattice_system(state)[source]
Returns the lattice system name, retrieved from the condition state.
- Parameters:
state (dict) – A state in environment format.
- Returns:
str – The name of the lattice system contained in the condition state.
- Return type:
str
- set_lattice_system(lattice_system, state=None)[source]
Sets the lattice system of the unit cell as the condition of the environment.
If the input state is not None, it is updated with the given lattice system. Otherwise
self.stateis updated.- Parameters:
lattice_system (int or str) – The index of the lattice system, as stored in
gflownet.envs.crystals.lattice_parameters.LATTICE_SYSTEMSor the string identifier.state (dict (optional)) – A state in environment format.
- Returns:
state – The input state updated with the given lattice system. This is a state of the LatticeParameters environment in environment format.
- Return type:
Dict
- property lattice_system_idx: int[source]
Returns the lattice system index of the environment as per
self.state.- Returns:
int – The index of the lattice system contained in the condition state.
- Return type:
int
- property lattice_system: str[source]
Returns the name of the lattice system of the environment as per
self.state.- Returns:
str – The name of the lattice system contained in the condition state.
- Return type:
str
- apply_lattice_constraints(state, lattice_system)[source]
Applies lattice system constraints to a single cube state.
The input state is expected to be a state of the ContinuousCube in environment format.
- Parameters:
state (dict) – A state of the ContinuousCube in environment format.
lattice_system (int or str) – The index of the lattice system, as stored in
gflownet.envs.crystals.lattice_parameters.LATTICE_SYSTEMSor the string identifier.
- Returns:
a, b, c (float) – Lattice lengths of the state, in angstroms.
alpha, beta, gamma (float) – Lattice angles, in degrees.
- Return type:
Tuple[Tuple, Tuple]
- revert_lattice_constraints(parameters, lattice_system)[source]
Reverts lattice system constraints to a set of lattice parameters.
The output is in the format of a ContinuousCube state in environment format, with the parameters in the [0, 1] range.
- Parameters:
parameters (list) – A list of lattice parameters in angstroms and degrees.
lattice_system (int or str) – The index of the lattice system, as stored in
gflownet.envs.crystals.lattice_parameters.LATTICE_SYSTEMSor the string identifier.
- Returns:
state (list) – A ContinuousCube state in environment format.
- Return type:
List[float]
- static apply_lattice_constraints_batch(states, lattice_system)[source]
Applies lattice system constraints to a batch of states.
The input states are expected to be a tensor with values already mapped from [0; 1] to
min_length,max_length,min_angleandmax_angle.Depending on the lattice system passed as an input, the corresponding constraints are applied to the entire batch.
- statestensor
A batch of ContinuousCube states (6D) in an intermediate format between the environment states and the proxy format. The values of the states are assumed to be already converted into lattice parameters with the correct units (angstroms and angles), but no lattice system constraints.
- lattice_systemint
The index of the lattice system, as stored in
gflownet.envs.crystals.lattice_parameters.LATTICE_SYSTEMSor the string identifier.
- Parameters:
states (torchtyping.TensorType[batch, 6])
lattice_system (Union[int, str])
- states2proxy(states)[source]
Prepares a batch of states in environment format for a proxy.
The proxy representation is the Cube states, mapped from [0; 1] to edge lengths and angles using min_length, max_length, min_angle and max_angle, via _statevalue2length() and _statevalue2angle(). Furthermore, the lattice system constraints are applied to the lenghts and angles.
The batch may contain states with different lattice systems (conditions). The constraints are applied by taking the lattice system from the state (the Dummy part of the Stack).
Paramters
- stateslist or tensor
A batch of states in environment format, either as a list of states or as a single tensor.
- returns:
A tensor containing all the states in the batch.
- Parameters:
states (Union[List, torchtyping.TensorType[batch, state_dim]])
- Return type:
torchtyping.TensorType[height, width, batch]
- states2policy(states)[source]
Prepares a batch of states in “environment format” for the policy model.
The policy representation is identical to that of the Cube environment and it is agnostic to the lattice system. Also, the action of the condition (Dummy) environment is deterministic. Therefore, instead of using the Stack’s method, the Cube part of the states is first extracted and then the entire batch is converted into the policy representation using the Cube environment.
- Parameters:
states (list) – A batch of states in environment format.
- Returns:
A tensor containing all the states in the batch.
- Return type:
torchtyping.TensorType[batch, state_policy_dim]
- state2readable(state=None)[source]
Converts the state into a human-readable string in the format “(a, b, c), (alpha, beta, gamma)”.
- Parameters:
state (dict) – A state in environment format.
- Returns:
str – A human-readable version of the state.
- Return type:
str
- readable2state(readable)[source]
Converts a human-readable representation of a state into the standard format.
- Parameters:
readable (str) – A human-readable version of a state.
- Returns:
state (dict) – A state in environment format.
- Return type:
Dict
- is_valid(state)[source]
Determines whether a state is valid, according to the attributes of the environment.
- Parameters:
state (dict) – A state in environment format. If None, then lengths and angles will be used instead.
- Returns:
bool – True if the state is valid according to the attributes of the environment; False otherwise.
- Return type:
bool
- get_grid_terminating_states(n_states, kappa=None)[source]
Constructs a grid of terminating states within the range of the hyper-cube.
This method uses the Cube’s corresponding method to generate the Cube states, and then creates LatticeParameters states from them.
- Parameters:
n_states (int) – Requested number of states. The actual number of states will be rounded up such that all dimensions have the same number of states.
kappa (float) – Small constant indicating the distance to the theoretical limits of the cube [0, 1], in order to avoid innacuracies in the computation of the log probabilities due to clamping. The grid will thus be in [kappa, 1 - kappa]. If None, self.kappa will be used.
- Return type:
List[Dict]
- get_uniform_terminating_states(n_states, seed=None, kappa=None)[source]
Constructs a set of terminating states sampled uniformly within the range of the hyper-cube.
This method uses the Cube’s corresponding method to generate the Cube states, and then creates LatticeParameters states from them.
- Parameters:
n_states (int) – Number of states in the returned list.
kappa (float) – Small constant indicating the distance to the theoretical limits of the cube [0, 1], in order to avoid innacuracies in the computation of the log probabilities due to clamping. The states will thus be uniformly sampled in [kappa, 1 - kappa]. If None, self.kappa will be used.
seed (int)
- Return type:
List[Dict]
- class gflownet.envs.crystals.lattice_parameters.LatticeParametersSGCCG(lattice_system, **kwargs)[source]
Bases:
gflownet.envs.cube.ContinuousCube- Parameters:
lattice_system (str) – One of the seven lattice systems. By default, the triclinic lattice system is used, which has no constraints.
- state2lattice(state=None)[source]
Transforms a state into its equivalent lattice parameters
- Parameters:
state (list) – A state in environment format. If None, then the current state will be used instead
- Returns:
proj (list) – Lattice parameters equivalent to the provided state representation. In format [[a, b, c], [alpha, beta, gamma]] for compatibility with previous lattice parameter environment.
- apply_projection_constraints(projection_vector)[source]
Apply the environment constraints to a state representation in projection space.
- Parameters:
projection_vector (list) – State representation in projection space
- Returns:
constrained_projection_vector (list) – State representation in projection space, compatible with the environment constraints.
- apply_lattice_constraints(lattice_params)[source]
Apply the environment constraints to a set of lattice parameters.
- Parameters:
lattice_params (list) – Lattice parameters, in order (a, b, c, alpha, beta, gamma).
- Returns:
constrained_lattice_params (list) – Lattice parameters in the same order as in the input, modified if needed to be compatible with the environment constraints.
- set_lattice_system(lattice_system)[source]
Sets the lattice system of the unit cell and updates the constraints.
- Parameters:
lattice_system (str) – Name of the lattice system for which to produce lattice parameters.
- parameters2state(parameters=None, lengths=None, angles=None)[source]
Converts a set of lattice parameters in angstroms and degrees into a ContinuousCube state, with the parameters in the [0, 1] range.
The parameters may be passed as a single tuple parameters containing the six parameters or via separate lengths and angles. If parameters is not None, lengths and angles are ignored.
- Parameters:
parameters (tuple (optional)) – The six lattice parameters (a, b, c, alpha, beta, gamma) in target units (angstroms and degrees).
lengths (tuple (optional)) – A triplet of length lattice parameters (a, b, c) in angstroms. Ignored if parameters is not None.
angles (tuple (optional)) – A triplet of angle lattice parameters (alpha, beta, gamma) in degrees. Ignored if parameters is not None.
- Returns:
state – A state in environment format.
- Return type:
Dict
- states2proxy(states)[source]
Prepares a batch of states in “environment format” for a proxy: states are mapped from [0; 1] to edge lengths and angles.
- Parameters:
states (list or tensor) – A batch of states in environment format, either as a list of states or as a single tensor.
- Returns:
A tensor containing all the states in the batch.
- Return type:
torchtyping.TensorType[height, width, batch]
- state2readable(state=None)[source]
Converts the state into a human-readable string in the format “(a, b, c), (alpha, beta, gamma)”.
- Parameters:
state (Optional[Dict])
- Return type:
str
- readable2state(readable)[source]
Converts a human-readable representation of a state into the state format.
- Parameters:
readable (str)
- Return type:
Dict
- is_valid(state)[source]
Determines whether a state is valid, according to the attributes of the environment.
- Parameters:
state (list) – A state in environment format. If None, then the current state will be used instead
- Returns:
bool – True if the state is valid according to the attributes of the environment; False otherwise.
- Return type:
bool