ParallelTempering¶
Parallel Tempering uses multiple optimization procedures per temperature. During the cooling process, an exchange of replicas can take place between the parallel procedures, thus enabling higher energy mountains to be overcome.
Compatible Backends¶
The ParallelTempering
algorithm supports the following backends:
By default, ParallelTempering
uses the DWave
backend.
Initialization¶
The following section outlines the default configurations of ParallelTempering
. You can also specify other compatible backends for the algorithm. When backend=None
is specified, the default backend will be initialized automatically. In this case, if the backend requires a token, it will be taken from the environment variables.
from luna_quantum.solve.parameters.algorithms import ParallelTempering
algorithm = ParallelTempering(
backend=None,
n_replicas=2,
random_swaps_factor=1,
max_iter=100,
max_time=5,
convergence=3,
target=None,
rtol=1e-05,
atol=1e-08,
fixed_temp_sampler_num_sweeps=10000,
fixed_temp_sampler_num_reads=None
)
Parameter Details
For a complete overview of available parameters and their usage, see the ParallelTempering API Reference.
Usage¶
from luna_quantum import LunaSolve
LunaSolve.authenticate("<YOUR_LUNA_API_KEY>")
# Define your model and algorithm
model = ...
algorithm = ...
solve_job = algorithm.run(model, name="my-solve-job")
API Reference¶
Bases: LunaAlgorithm[DWave]
Parameters for the Parallel Tempering (replica exchange) optimization algorithm.
Parallel Tempering runs multiple copies ("replicas") of the system simultaneously at different temperatures. Periodically, replicas at adjacent temperatures can swap configurations, allowing high-temperature replicas to explore widely while low-temperature replicas exploit promising regions.
This approach is particularly effective for problems with many local minima, as it combines the exploration benefits of high temperature with the exploitation benefits of low temperature.
Attributes:
Name | Type | Description |
---|---|---|
n_replicas |
int
|
Number of system replicas to simulate at different temperatures. More replicas provide better temperature coverage but increase computational cost. Higher values allow for finer gradations between temperature levels, potentially improving the exchange of configurations between adjacent replicas. Default is 2, which is minimal but can still provide benefits over single-temperature methods. |
random_swaps_factor |
int
|
Factor controlling how frequently random swap attempts occur between replicas. Higher values increase mixing between replicas but add computational overhead. More frequent swaps help configurations move more quickly between temperature levels, allowing good solutions found at high temperatures to be refined at lower temperatures. Default is 1, balancing mixing with efficiency. |
max_iter |
int | None
|
Maximum number of iterations (temperature cycles) to perform. Each iteration involves sampling at all temperature levels and attempting exchanges between replicas. Higher values allow more thorough exploration but increase runtime. Default is 100. |
max_time |
int
|
Maximum time in seconds for the algorithm to run. Provides a hard time limit regardless of convergence or iteration status. Useful for time-constrained scenarios where some solution is needed within a specific timeframe. Default is 5. |
convergence |
int
|
Number of consecutive iterations without improvement before declaring convergence. Higher values ensure more stable solutions but may increase computation time unnecessarily if the algorithm has already found the best solution. Default is 3. |
target |
float | None
|
Target objective value that triggers termination if reached. Allows early stopping when a sufficiently good solution is found. Default is None, which means the algorithm will run until other stopping criteria are met. |
rtol |
float
|
Relative tolerance for convergence detection. Used when comparing objective values between iterations to determine if significant improvement has occurred. Default is DEFAULT_RTOL. |
atol |
float
|
Absolute tolerance for convergence detection. Used alongside rtol when comparing objective values to determine if the algorithm has converged. Default is DEFAULT_ATOL. |
fixed_temp_sampler_num_sweeps |
int
|
Number of Monte Carlo sweeps to perform at each temperature level, where one sweep attempts to update all variables once. More sweeps produce better equilibrated samples but increase computation time. This parameter controls how thoroughly each replica explores its local solution space before exchange attempts. Default is 10,000, which is suitable for thorough exploration of moderate-sized problems. |
fixed_temp_sampler_num_reads |
int | None
|
Number of independent sampling runs to perform at each temperature level. Each run produces one sample from the equilibrium distribution. Multiple reads provide better statistical coverage of the solution space at each temperature. Default is None, which typically defaults to 1 or matches the number of initial states provided. |
backend
class-attribute
instance-attribute
¶
fixed_temp_sampler_num_reads
class-attribute
instance-attribute
¶
fixed_temp_sampler_num_sweeps
class-attribute
instance-attribute
¶
model_config
class-attribute
instance-attribute
¶
get_compatible_backends
classmethod
¶
get_compatible_backends() -> tuple[type[DWave], ...]
Check at runtime if the used backend is compatible with the solver.
Returns:
Type | Description |
---|---|
tuple[type[IBackend], ...]
|
True if the backend is compatible with the solver, False otherwise. |
get_default_backend
classmethod
¶
get_default_backend() -> DWave
Return the default backend implementation.
This property must be implemented by subclasses to provide the default backend instance to use when no specific backend is specified.
Returns:
Type | Description |
---|---|
IBackend
|
An instance of a class implementing the IBackend interface that serves as the default backend. |
run ¶
run(
model: Model | str,
name: str | None = None,
backend: BACKEND_TYPE | None = None,
client: LunaSolve | str | None = None,
*args: Any,
**kwargs: Any,
) -> SolveJob
Run the configured solver.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Model or str
|
The model to be optimized or solved. It could be an Model instance or a string identifier representing the model id. |
required |
name
|
str | None
|
If provided, the name of the job. Defaults to None. |
None
|
backend
|
BACKEND_TYPE | None
|
Backend to use for the solver. If not provided, the default backend is used. |
None
|
client
|
LunaSolve or str
|
The client interface used to interact with the backend services. If not provided, a default client will be used. |
None
|
*args
|
Any
|
Additional arguments that will be passed to the solver or client. |
()
|
**kwargs
|
Any
|
Additional keyword parameters for configuration or customization. |
{}
|
Returns:
Type | Description |
---|---|
SolveJob
|
The job object containing the information about the solve process. |