omnisolver.pt.replica#
Implementation of replica used in parallel tempering.
Module Contents#
Classes#
Replica of Ising spin-glass used in parallel tempering algorithm. |
Functions#
|
|
|
Initialize an instance of jit-compiled Replica class. |
- class omnisolver.pt.replica.Replica(model: omnisolver.pt.model.IsingModel, initial_state, beta)#
Replica of Ising spin-glass used in parallel tempering algorithm.
- Variables:
model – Instance of Ising model this replica uses.
beta – inverse temperature used for sampling.
current_state – current state of the replica.
current_energy – current energy of the replica. This energy always corresponds to replica’s current state.
best_state_so_far – best state the replica was in so far. This information is updated (if necessary) in every Monte-Carlo iteration.
best_energy_so_far – energy corresponding to the best state seen by this replica so far.
- should_accept_flip(energy_diff: float) bool#
Determine if this replica should accept spin flip resulting in given energy difference.
- Parameters:
energy_diff – energy difference between current state of replica and the state with flipped spin.
- Returns:
True if replica should accept the change and False otherwise.
Note
Obviously, this method is non-deterministic. Energy differences greater than 0 (i.e. changes that improve energy) are always accepted, while flips worsening current energy are accepted with the usual Metropolis-Hastings probability.
- perform_mc_sweep() None#
Perform single Monte-Carlo sweep in this replica.
Performing MC sweep involves triaging every possible spin flip and deciding whether it should be accepted or not. The replica’s current state and energy, as well as replica’s best state and energy are update accordingly.
- omnisolver.pt.replica._create_replica_cls(spec)#
- omnisolver.pt.replica.initialize_replica(model: omnisolver.pt.model.IsingModel, initial_state, beta) Replica#
Initialize an instance of jit-compiled Replica class.
- Parameters:
model – Ising model used by the replica.
initial_state – initial state of the replica. This is expected to be a 1D array of +/-1 integers of size N, where N is the number of spins in the model. If this requirement is not met, ValueError is raised.
beta – inverse temperature of the replica.
- Raises:
ValueError – If initial state is not of shape (N,), where N is the number of spins in the system.
- Returns:
An instance of jit-compiled Replica class.
Note
Jit-compiled class definitions are reused, provided that the types of model coefficients are the same. Hence, in typical run all replicas are of the same numba type.