luna-quantum 1.1.0__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- luna_quantum/__init__.py +139 -0
- luna_quantum/__init__.pyi +98 -0
- luna_quantum/_core.cp312-win_amd64.pyd +0 -0
- luna_quantum/_core.pyi +4286 -0
- luna_quantum/_utility.py +148 -0
- luna_quantum/_utility.pyi +20 -0
- luna_quantum/algorithms/__init__.py +1 -0
- luna_quantum/aqm_overwrites/__init__.py +3 -0
- luna_quantum/aqm_overwrites/model.py +184 -0
- luna_quantum/backends/__init__.py +1 -0
- luna_quantum/client/__init__.py +0 -0
- luna_quantum/client/controllers/__init__.py +4 -0
- luna_quantum/client/controllers/luna_http_client.py +37 -0
- luna_quantum/client/controllers/luna_platform_client.py +256 -0
- luna_quantum/client/controllers/luna_q.py +67 -0
- luna_quantum/client/controllers/luna_solve.py +129 -0
- luna_quantum/client/error/__init__.py +0 -0
- luna_quantum/client/error/luna_api_key_invalid_error.py +10 -0
- luna_quantum/client/error/luna_api_key_missing_error.py +10 -0
- luna_quantum/client/error/luna_error.py +2 -0
- luna_quantum/client/error/luna_server_error.py +20 -0
- luna_quantum/client/error/timeout_error.py +12 -0
- luna_quantum/client/error/transformation_error.py +18 -0
- luna_quantum/client/error/utils/__init__.py +0 -0
- luna_quantum/client/error/utils/http_error_utils.py +112 -0
- luna_quantum/client/interfaces/__init__.py +4 -0
- luna_quantum/client/interfaces/clients/__init__.py +25 -0
- luna_quantum/client/interfaces/clients/circuit_rest_client_i.py +68 -0
- luna_quantum/client/interfaces/clients/info_rest_client_i.py +53 -0
- luna_quantum/client/interfaces/clients/model_rest_client_i.py +139 -0
- luna_quantum/client/interfaces/clients/qpu_token_rest_client_i.py +364 -0
- luna_quantum/client/interfaces/clients/rest_client_i.py +21 -0
- luna_quantum/client/interfaces/clients/solve_job_rest_client_i.py +201 -0
- luna_quantum/client/interfaces/clients/users_rest_client_i.py +29 -0
- luna_quantum/client/interfaces/services/__init__.py +0 -0
- luna_quantum/client/interfaces/services/luna_q_i.py +34 -0
- luna_quantum/client/interfaces/services/luna_solve_i.py +72 -0
- luna_quantum/client/interfaces/services/service_i.py +56 -0
- luna_quantum/client/rest_client/__init__.py +15 -0
- luna_quantum/client/rest_client/circuit_rest_client.py +107 -0
- luna_quantum/client/rest_client/info_rest_client.py +74 -0
- luna_quantum/client/rest_client/model_rest_client.py +216 -0
- luna_quantum/client/rest_client/qpu_token_rest_client.py +508 -0
- luna_quantum/client/rest_client/solve_job_rest_client.py +286 -0
- luna_quantum/client/rest_client/users_rest_client.py +35 -0
- luna_quantum/client/schemas/__init__.py +26 -0
- luna_quantum/client/schemas/circuit.py +48 -0
- luna_quantum/client/schemas/create/__init__.py +15 -0
- luna_quantum/client/schemas/create/circuit.py +30 -0
- luna_quantum/client/schemas/create/optimization.py +39 -0
- luna_quantum/client/schemas/create/qpu_token.py +22 -0
- luna_quantum/client/schemas/create/qpu_token_time_quota.py +35 -0
- luna_quantum/client/schemas/create/qpu_token_time_quota_update.py +24 -0
- luna_quantum/client/schemas/create/qubo.py +19 -0
- luna_quantum/client/schemas/create/solve_job_create.py +43 -0
- luna_quantum/client/schemas/enums/__init__.py +0 -0
- luna_quantum/client/schemas/enums/call_style.py +13 -0
- luna_quantum/client/schemas/enums/circuit.py +42 -0
- luna_quantum/client/schemas/enums/model_format.py +11 -0
- luna_quantum/client/schemas/enums/problem.py +50 -0
- luna_quantum/client/schemas/enums/qpu_token_type.py +20 -0
- luna_quantum/client/schemas/enums/sense.py +8 -0
- luna_quantum/client/schemas/enums/status.py +40 -0
- luna_quantum/client/schemas/enums/timeframe.py +11 -0
- luna_quantum/client/schemas/error_message.py +14 -0
- luna_quantum/client/schemas/model_metadata.py +35 -0
- luna_quantum/client/schemas/qpu_token/__init__.py +0 -0
- luna_quantum/client/schemas/qpu_token/qpu_token.py +154 -0
- luna_quantum/client/schemas/qpu_token/qpu_token_source.py +19 -0
- luna_quantum/client/schemas/qpu_token/qpu_token_time_quota.py +30 -0
- luna_quantum/client/schemas/qpu_token/token_provider.py +132 -0
- luna_quantum/client/schemas/representation.py +19 -0
- luna_quantum/client/schemas/solution.py +106 -0
- luna_quantum/client/schemas/solve_job.py +50 -0
- luna_quantum/client/schemas/solver_info.py +11 -0
- luna_quantum/client/schemas/user.py +11 -0
- luna_quantum/client/schemas/wrappers/__init__.py +5 -0
- luna_quantum/client/schemas/wrappers/datetime_wrapper.py +32 -0
- luna_quantum/client/utils/__init__.py +0 -0
- luna_quantum/client/utils/qpu_token_utils.py +147 -0
- luna_quantum/config.py +11 -0
- luna_quantum/decorators.py +248 -0
- luna_quantum/errors.py +34 -0
- luna_quantum/errors.pyi +287 -0
- luna_quantum/exceptions/__init__.py +0 -0
- luna_quantum/exceptions/base_luna_quantum_error.py +2 -0
- luna_quantum/exceptions/luna_quantum_call_type_error.py +9 -0
- luna_quantum/exceptions/patch_class_field_exists_error.py +10 -0
- luna_quantum/factories/__init__.py +4 -0
- luna_quantum/factories/luna_solve_client_factory.py +100 -0
- luna_quantum/factories/usecase_factory.py +489 -0
- luna_quantum/py.typed +0 -0
- luna_quantum/solve/__init__.py +13 -0
- luna_quantum/solve/default_token.py +304 -0
- luna_quantum/solve/domain/__init__.py +0 -0
- luna_quantum/solve/domain/abstract/__init__.py +4 -0
- luna_quantum/solve/domain/abstract/luna_algorithm.py +205 -0
- luna_quantum/solve/domain/abstract/qpu_token_backend.py +34 -0
- luna_quantum/solve/domain/model_metadata.py +56 -0
- luna_quantum/solve/domain/solve_job.py +230 -0
- luna_quantum/solve/errors/__init__.py +0 -0
- luna_quantum/solve/errors/incompatible_backend_error.py +15 -0
- luna_quantum/solve/errors/model_metadata_missing_error.py +11 -0
- luna_quantum/solve/errors/solve_base_error.py +5 -0
- luna_quantum/solve/errors/token_missing_error.py +11 -0
- luna_quantum/solve/interfaces/__init__.py +0 -0
- luna_quantum/solve/interfaces/algorithm_i.py +49 -0
- luna_quantum/solve/interfaces/backend_i.py +28 -0
- luna_quantum/solve/interfaces/usecases/__init__.py +59 -0
- luna_quantum/solve/interfaces/usecases/model_delete_usecase_i.py +27 -0
- luna_quantum/solve/interfaces/usecases/model_fetch_metadata_usecase_i.py +33 -0
- luna_quantum/solve/interfaces/usecases/model_get_solutions_usecase_i.py +33 -0
- luna_quantum/solve/interfaces/usecases/model_get_solve_jobs_usecase_i.py +33 -0
- luna_quantum/solve/interfaces/usecases/model_load_by_id_usecase_i.py +32 -0
- luna_quantum/solve/interfaces/usecases/model_load_by_metadata_usecase_i.py +37 -0
- luna_quantum/solve/interfaces/usecases/model_load_metadata_by_hash_usecase_i.py +38 -0
- luna_quantum/solve/interfaces/usecases/model_save_usecase_i.py +36 -0
- luna_quantum/solve/interfaces/usecases/solve_job_cancel_usecase_i.py +33 -0
- luna_quantum/solve/interfaces/usecases/solve_job_create_usecase_i.py +44 -0
- luna_quantum/solve/interfaces/usecases/solve_job_delete_usecase_i.py +32 -0
- luna_quantum/solve/interfaces/usecases/solve_job_fetch_updates_usecase_i.py +38 -0
- luna_quantum/solve/interfaces/usecases/solve_job_get_by_id_usecase_i.py +27 -0
- luna_quantum/solve/interfaces/usecases/solve_job_get_result_usecase_i.py +63 -0
- luna_quantum/solve/parameters/__init__.py +0 -0
- luna_quantum/solve/parameters/algorithms/__init__.py +51 -0
- luna_quantum/solve/parameters/algorithms/base_params/__init__.py +24 -0
- luna_quantum/solve/parameters/algorithms/base_params/decomposer.py +57 -0
- luna_quantum/solve/parameters/algorithms/base_params/qaoa_circuit_params.py +95 -0
- luna_quantum/solve/parameters/algorithms/base_params/quantum_annealing_params.py +79 -0
- luna_quantum/solve/parameters/algorithms/base_params/scipy_optimizer.py +122 -0
- luna_quantum/solve/parameters/algorithms/base_params/simulated_annealing_params.py +106 -0
- luna_quantum/solve/parameters/algorithms/base_params/tabu_kerberos_params.py +39 -0
- luna_quantum/solve/parameters/algorithms/base_params/tabu_search_params.py +129 -0
- luna_quantum/solve/parameters/algorithms/flexible_parameter_algorithm.py +59 -0
- luna_quantum/solve/parameters/algorithms/genetic_algorithms/__init__.py +4 -0
- luna_quantum/solve/parameters/algorithms/genetic_algorithms/qaga.py +131 -0
- luna_quantum/solve/parameters/algorithms/genetic_algorithms/saga.py +139 -0
- luna_quantum/solve/parameters/algorithms/lq_fda/__init__.py +3 -0
- luna_quantum/solve/parameters/algorithms/lq_fda/fujits_da_base.py +85 -0
- luna_quantum/solve/parameters/algorithms/lq_fda/fujitsu_da_v3c.py +155 -0
- luna_quantum/solve/parameters/algorithms/optimization_solvers/__init__.py +3 -0
- luna_quantum/solve/parameters/algorithms/optimization_solvers/scip.py +51 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/__init__.py +19 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/kerberos.py +149 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/leap_hybrid_bqm.py +75 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/leap_hybrid_cqm.py +75 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/parallel_tempering_qpu.py +139 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/population_annealing_qpu.py +109 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/qbsolv_like_qpu.py +111 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/quantum_annealing.py +121 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/repeated_reverse_quantum_annealing.py +174 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/__init__.py +6 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/__init__.py +10 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/__init__.py +29 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/config.py +58 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/flexqaoa.py +188 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/optimizers.py +53 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/pipeline.py +164 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/qaoa.py +112 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/qaoa_fo.py +69 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/vqe.py +108 -0
- luna_quantum/solve/parameters/algorithms/search_algorithms/__init__.py +5 -0
- luna_quantum/solve/parameters/algorithms/search_algorithms/dialectic_search.py +136 -0
- luna_quantum/solve/parameters/algorithms/search_algorithms/qbsolv_like_tabu_search.py +117 -0
- luna_quantum/solve/parameters/algorithms/search_algorithms/tabu_search.py +126 -0
- luna_quantum/solve/parameters/algorithms/simulated_annealing/__init__.py +13 -0
- luna_quantum/solve/parameters/algorithms/simulated_annealing/parallel_tempering.py +131 -0
- luna_quantum/solve/parameters/algorithms/simulated_annealing/population_annealing.py +95 -0
- luna_quantum/solve/parameters/algorithms/simulated_annealing/qbsolv_like_simulated_annealing.py +141 -0
- luna_quantum/solve/parameters/algorithms/simulated_annealing/repeated_reverse_simulated_annealing.py +172 -0
- luna_quantum/solve/parameters/algorithms/simulated_annealing/simulated_annealing.py +126 -0
- luna_quantum/solve/parameters/backends/__init__.py +27 -0
- luna_quantum/solve/parameters/backends/aqarios.py +17 -0
- luna_quantum/solve/parameters/backends/aqarios_gpu.py +17 -0
- luna_quantum/solve/parameters/backends/aws/__init__.py +11 -0
- luna_quantum/solve/parameters/backends/aws/aws.py +36 -0
- luna_quantum/solve/parameters/backends/aws/aws_backend_base.py +74 -0
- luna_quantum/solve/parameters/backends/aws/ionq.py +43 -0
- luna_quantum/solve/parameters/backends/aws/iqm.py +31 -0
- luna_quantum/solve/parameters/backends/aws/rigetti.py +31 -0
- luna_quantum/solve/parameters/backends/cudaq/__init__.py +5 -0
- luna_quantum/solve/parameters/backends/cudaq/cudaq_base.py +16 -0
- luna_quantum/solve/parameters/backends/cudaq/cudaq_cpu.py +30 -0
- luna_quantum/solve/parameters/backends/cudaq/cudaq_gpu.py +32 -0
- luna_quantum/solve/parameters/backends/dwave.py +17 -0
- luna_quantum/solve/parameters/backends/dwave_qpu.py +166 -0
- luna_quantum/solve/parameters/backends/fda.py +17 -0
- luna_quantum/solve/parameters/backends/ibm.py +138 -0
- luna_quantum/solve/parameters/backends/qctrl.py +103 -0
- luna_quantum/solve/parameters/backends/zib.py +17 -0
- luna_quantum/solve/parameters/constants.py +11 -0
- luna_quantum/solve/parameters/errors.py +30 -0
- luna_quantum/solve/parameters/mixins/__init__.py +0 -0
- luna_quantum/solve/parameters/mixins/fujitsu_common_params_mixin.py +239 -0
- luna_quantum/solve/parameters/mixins/fujitsu_v2_mixin.py +70 -0
- luna_quantum/solve/parameters/mixins/qbsolv_like_mixin.py +60 -0
- luna_quantum/solve/use_cases/__init__.py +119 -0
- luna_quantum/solve/use_cases/arbitrage_edge_based.py +50 -0
- luna_quantum/solve/use_cases/arbitrage_node_based.py +55 -0
- luna_quantum/solve/use_cases/base.py +7 -0
- luna_quantum/solve/use_cases/binary_integer_linear_programming.py +54 -0
- luna_quantum/solve/use_cases/binary_paint_shop_problem.py +37 -0
- luna_quantum/solve/use_cases/credit_scoring_feature_selection.py +40 -0
- luna_quantum/solve/use_cases/dynamic_portfolio_optimization.py +64 -0
- luna_quantum/solve/use_cases/exact_cover.py +51 -0
- luna_quantum/solve/use_cases/flight_gate_assignment.py +79 -0
- luna_quantum/solve/use_cases/graph_coloring.py +42 -0
- luna_quantum/solve/use_cases/graph_isomorphism.py +52 -0
- luna_quantum/solve/use_cases/graph_partitioning.py +46 -0
- luna_quantum/solve/use_cases/hamiltonian_cycle.py +49 -0
- luna_quantum/solve/use_cases/induced_subgraph_isomorphism.py +50 -0
- luna_quantum/solve/use_cases/job_shop_scheduling.py +44 -0
- luna_quantum/solve/use_cases/k_medoids_clustering.py +49 -0
- luna_quantum/solve/use_cases/knapsack_integer_weights.py +56 -0
- luna_quantum/solve/use_cases/linear_regression.py +60 -0
- luna_quantum/solve/use_cases/lmwcs.py +84 -0
- luna_quantum/solve/use_cases/longest_path.py +50 -0
- luna_quantum/solve/use_cases/market_graph_clustering.py +61 -0
- luna_quantum/solve/use_cases/max2sat.py +54 -0
- luna_quantum/solve/use_cases/max3sat.py +55 -0
- luna_quantum/solve/use_cases/max_clique.py +60 -0
- luna_quantum/solve/use_cases/max_cut.py +48 -0
- luna_quantum/solve/use_cases/max_independent_set.py +37 -0
- luna_quantum/solve/use_cases/minimal_maximal_matching.py +54 -0
- luna_quantum/solve/use_cases/minimal_spanning_tree.py +90 -0
- luna_quantum/solve/use_cases/minimum_vertex_cover.py +45 -0
- luna_quantum/solve/use_cases/number_partitioning.py +32 -0
- luna_quantum/solve/use_cases/portfolio_optimization.py +46 -0
- luna_quantum/solve/use_cases/portfolio_optimization_ib_tv.py +63 -0
- luna_quantum/solve/use_cases/quadratic_assignment.py +49 -0
- luna_quantum/solve/use_cases/quadratic_knapsack.py +48 -0
- luna_quantum/solve/use_cases/satellite_scheduling.py +73 -0
- luna_quantum/solve/use_cases/sensor_placement.py +58 -0
- luna_quantum/solve/use_cases/set_cover.py +56 -0
- luna_quantum/solve/use_cases/set_packing.py +54 -0
- luna_quantum/solve/use_cases/set_partitioning.py +52 -0
- luna_quantum/solve/use_cases/subgraph_isomorphism.py +55 -0
- luna_quantum/solve/use_cases/subset_sum.py +37 -0
- luna_quantum/solve/use_cases/support_vector_machine.py +64 -0
- luna_quantum/solve/use_cases/traffic_flow.py +35 -0
- luna_quantum/solve/use_cases/travelling_salesman_problem.py +53 -0
- luna_quantum/solve/use_cases/type_aliases.py +9 -0
- luna_quantum/solve/use_cases/weighted_max_cut.py +37 -0
- luna_quantum/solve/usecases/__init__.py +45 -0
- luna_quantum/solve/usecases/model_delete_usecase.py +49 -0
- luna_quantum/solve/usecases/model_fetch_metadata_usecase.py +50 -0
- luna_quantum/solve/usecases/model_get_solution_usecase.py +59 -0
- luna_quantum/solve/usecases/model_get_solve_jobs_usecase.py +62 -0
- luna_quantum/solve/usecases/model_load_by_id_usecase.py +47 -0
- luna_quantum/solve/usecases/model_load_by_metadata_usecase.py +52 -0
- luna_quantum/solve/usecases/model_load_metadata_by_hash_usecase.py +51 -0
- luna_quantum/solve/usecases/model_save_usecase.py +63 -0
- luna_quantum/solve/usecases/solve_job_cancel_usecase.py +51 -0
- luna_quantum/solve/usecases/solve_job_create_usecase.py +112 -0
- luna_quantum/solve/usecases/solve_job_delete_usecase.py +38 -0
- luna_quantum/solve/usecases/solve_job_fetch_updates_usecase.py +49 -0
- luna_quantum/solve/usecases/solve_job_get_by_id_usecase.py +44 -0
- luna_quantum/solve/usecases/solve_job_get_result_usecase.py +105 -0
- luna_quantum/transformations.py +18 -0
- luna_quantum/transformations.pyi +371 -0
- luna_quantum/translator.py +23 -0
- luna_quantum/translator.pyi +869 -0
- luna_quantum/util/__init__.py +0 -0
- luna_quantum/util/active_waiting.py +79 -0
- luna_quantum/util/class_patcher.py +164 -0
- luna_quantum/util/debug_info.py +52 -0
- luna_quantum/util/log_utils.py +187 -0
- luna_quantum/util/pretty_base.py +67 -0
- luna_quantum/util/pydantic_utils.py +38 -0
- luna_quantum/utils.py +3 -0
- luna_quantum/utils.pyi +67 -0
- luna_quantum-1.1.0.dist-info/METADATA +36 -0
- luna_quantum-1.1.0.dist-info/RECORD +276 -0
- luna_quantum-1.1.0.dist-info/WHEEL +4 -0
- luna_quantum-1.1.0.dist-info/licenses/LICENSE +176 -0
- luna_quantum-1.1.0.dist-info/licenses/NOTICE +13 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .parallel_tempering import ParallelTempering
|
|
2
|
+
from .population_annealing import PopulationAnnealing
|
|
3
|
+
from .qbsolv_like_simulated_annealing import QBSolvLikeSimulatedAnnealing
|
|
4
|
+
from .repeated_reverse_simulated_annealing import RepeatedReverseSimulatedAnnealing
|
|
5
|
+
from .simulated_annealing import SimulatedAnnealing
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"ParallelTempering",
|
|
9
|
+
"PopulationAnnealing",
|
|
10
|
+
"QBSolvLikeSimulatedAnnealing",
|
|
11
|
+
"RepeatedReverseSimulatedAnnealing",
|
|
12
|
+
"SimulatedAnnealing",
|
|
13
|
+
]
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
from luna_quantum.solve.domain.abstract import LunaAlgorithm
|
|
2
|
+
from luna_quantum.solve.parameters.backends import DWave
|
|
3
|
+
from luna_quantum.solve.parameters.constants import DEFAULT_ATOL, DEFAULT_RTOL
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ParallelTempering(LunaAlgorithm[DWave]):
|
|
7
|
+
"""
|
|
8
|
+
Parameters for the Parallel Tempering (replica exchange) optimization algorithm.
|
|
9
|
+
|
|
10
|
+
Parallel Tempering runs multiple copies ("replicas") of the system simultaneously
|
|
11
|
+
at different temperatures. Periodically, replicas at adjacent temperatures can swap
|
|
12
|
+
configurations, allowing high-temperature replicas to explore widely while
|
|
13
|
+
low-temperature replicas exploit promising regions.
|
|
14
|
+
|
|
15
|
+
This approach is particularly effective for problems with many local minima, as it
|
|
16
|
+
combines the exploration benefits of high temperature with the exploitation benefits
|
|
17
|
+
of low temperature.
|
|
18
|
+
|
|
19
|
+
Attributes
|
|
20
|
+
----------
|
|
21
|
+
n_replicas: int
|
|
22
|
+
Number of system replicas to simulate at different temperatures. More replicas
|
|
23
|
+
provide better temperature coverage but increase computational cost.
|
|
24
|
+
Higher values allow for finer gradations between temperature levels, potentially
|
|
25
|
+
improving the exchange of configurations between adjacent replicas.
|
|
26
|
+
Default is 2, which is minimal but can still provide benefits over
|
|
27
|
+
single-temperature methods.
|
|
28
|
+
random_swaps_factor: int
|
|
29
|
+
Factor controlling how frequently random swap attempts occur between replicas.
|
|
30
|
+
Higher values increase mixing between replicas but add computational overhead.
|
|
31
|
+
More frequent swaps help configurations move more quickly between temperature
|
|
32
|
+
levels, allowing good solutions found at high temperatures to be refined at
|
|
33
|
+
lower temperatures. Default is 1, balancing mixing with efficiency.
|
|
34
|
+
max_iter: int | None
|
|
35
|
+
Maximum number of iterations (temperature cycles) to perform. Each iteration
|
|
36
|
+
involves sampling at all temperature levels and attempting exchanges between
|
|
37
|
+
replicas. Higher values allow more thorough exploration but increase runtime.
|
|
38
|
+
Default is 100.
|
|
39
|
+
max_time: int
|
|
40
|
+
Maximum time in seconds for the algorithm to run. Provides a hard time limit
|
|
41
|
+
regardless of convergence or iteration status. Useful for time-constrained
|
|
42
|
+
scenarios where some solution is needed within a specific timeframe.
|
|
43
|
+
Default is 5.
|
|
44
|
+
convergence: int
|
|
45
|
+
Number of consecutive iterations without improvement before declaring
|
|
46
|
+
convergence. Higher values ensure more stable solutions but may increase
|
|
47
|
+
computation time unnecessarily if the algorithm has already found the best
|
|
48
|
+
solution. Default is 3.
|
|
49
|
+
target: float | None
|
|
50
|
+
Target objective value that triggers termination if reached. Allows early
|
|
51
|
+
stopping when a sufficiently good solution is found. Default is None, which
|
|
52
|
+
means the algorithm will run until other stopping criteria are met.
|
|
53
|
+
rtol: float
|
|
54
|
+
Relative tolerance for convergence detection. Used when comparing objective
|
|
55
|
+
values between iterations to determine if significant improvement has occurred.
|
|
56
|
+
Default is DEFAULT_RTOL.
|
|
57
|
+
atol: float
|
|
58
|
+
Absolute tolerance for convergence detection. Used alongside rtol when comparing
|
|
59
|
+
objective values to determine if the algorithm has converged. Default is
|
|
60
|
+
DEFAULT_ATOL.
|
|
61
|
+
fixed_temp_sampler_num_sweeps: int
|
|
62
|
+
Number of Monte Carlo sweeps to perform at each temperature level, where one
|
|
63
|
+
sweep attempts to update all variables once. More sweeps produce better
|
|
64
|
+
equilibrated samples but increase computation time. This parameter controls
|
|
65
|
+
how thoroughly each replica explores its local solution space before exchange
|
|
66
|
+
attempts. Default is 10,000, which is suitable for thorough exploration of
|
|
67
|
+
moderate-sized problems.
|
|
68
|
+
fixed_temp_sampler_num_reads: int | None
|
|
69
|
+
Number of independent sampling runs to perform at each temperature level.
|
|
70
|
+
Each run produces one sample from the equilibrium distribution. Multiple reads
|
|
71
|
+
provide better statistical coverage of the solution space at each temperature.
|
|
72
|
+
Default is None, which typically defaults to 1 or matches the number of initial
|
|
73
|
+
states provided.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
n_replicas: int = 2
|
|
77
|
+
random_swaps_factor: int = 1
|
|
78
|
+
max_iter: int | None = 100
|
|
79
|
+
max_time: int = 5
|
|
80
|
+
convergence: int = 3
|
|
81
|
+
target: float | None = None
|
|
82
|
+
rtol: float = DEFAULT_RTOL
|
|
83
|
+
atol: float = DEFAULT_ATOL
|
|
84
|
+
|
|
85
|
+
fixed_temp_sampler_num_sweeps: int = 10_000
|
|
86
|
+
fixed_temp_sampler_num_reads: int | None = None
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def algorithm_name(self) -> str:
|
|
90
|
+
"""
|
|
91
|
+
Returns the name of the algorithm.
|
|
92
|
+
|
|
93
|
+
This abstract property method is intended to be overridden by subclasses.
|
|
94
|
+
It should provide the name of the algorithm being implemented.
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
str
|
|
99
|
+
The name of the algorithm.
|
|
100
|
+
"""
|
|
101
|
+
return "PT"
|
|
102
|
+
|
|
103
|
+
@classmethod
|
|
104
|
+
def get_default_backend(cls) -> DWave:
|
|
105
|
+
"""
|
|
106
|
+
Return the default backend implementation.
|
|
107
|
+
|
|
108
|
+
This property must be implemented by subclasses to provide
|
|
109
|
+
the default backend instance to use when no specific backend
|
|
110
|
+
is specified.
|
|
111
|
+
|
|
112
|
+
Returns
|
|
113
|
+
-------
|
|
114
|
+
IBackend
|
|
115
|
+
An instance of a class implementing the IBackend interface that serves
|
|
116
|
+
as the default backend.
|
|
117
|
+
"""
|
|
118
|
+
return DWave()
|
|
119
|
+
|
|
120
|
+
@classmethod
|
|
121
|
+
def get_compatible_backends(cls) -> tuple[type[DWave], ...]:
|
|
122
|
+
"""
|
|
123
|
+
Check at runtime if the used backend is compatible with the solver.
|
|
124
|
+
|
|
125
|
+
Returns
|
|
126
|
+
-------
|
|
127
|
+
tuple[type[IBackend], ...]
|
|
128
|
+
True if the backend is compatible with the solver, False otherwise.
|
|
129
|
+
|
|
130
|
+
"""
|
|
131
|
+
return (DWave,)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
from luna_quantum.solve.domain.abstract import LunaAlgorithm
|
|
2
|
+
from luna_quantum.solve.parameters.backends import DWave
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class PopulationAnnealing(LunaAlgorithm[DWave]):
|
|
6
|
+
"""
|
|
7
|
+
Parameters for the Population Annealing algorithm.
|
|
8
|
+
|
|
9
|
+
Population Annealing uses a sequential Monte Carlo method to minimize the energy of
|
|
10
|
+
a population. The population consists of walkers that can explore their neighborhood
|
|
11
|
+
during the cooling process. Afterwards, walkers are removed and duplicated using
|
|
12
|
+
bias to lower energy. Eventually, a population collapse occurs where all walkers are
|
|
13
|
+
in the lowest energy state.
|
|
14
|
+
|
|
15
|
+
Attributes
|
|
16
|
+
----------
|
|
17
|
+
max_iter: int
|
|
18
|
+
Maximum number of annealing iterations (temperature steps) to perform. Each
|
|
19
|
+
iteration involves lowering the temperature, allowing walkers to explore
|
|
20
|
+
locally, and then resampling the population based on Boltzmann weights.
|
|
21
|
+
Higher values allow for a more gradual cooling schedule, potentially finding
|
|
22
|
+
better solutions but increasing computation time. Default is 20,
|
|
23
|
+
which provides a reasonable balance for most problems.
|
|
24
|
+
max_time: int
|
|
25
|
+
Maximum time in seconds that the algorithm is allowed to run. Provides a hard
|
|
26
|
+
time limit regardless of convergence or iteration status. Useful for
|
|
27
|
+
time-constrained scenarios where some solution is needed within a specific
|
|
28
|
+
timeframe. Default is 2, which is relatively aggressive and may need to be
|
|
29
|
+
increased for complex problems.
|
|
30
|
+
fixed_temp_sampler_num_sweeps: int
|
|
31
|
+
Number of Monte Carlo sweeps to perform at each temperature level, where one
|
|
32
|
+
sweep attempts to update all variables once. More sweeps allow walkers to
|
|
33
|
+
explore their local configuration space more thoroughly, producing better
|
|
34
|
+
equilibrated samples but increasing computation time. This parameter directly
|
|
35
|
+
affects how well each walker samples its local energy landscape before
|
|
36
|
+
resampling occurs. Default is 10,000, which is suitable for thorough exploration
|
|
37
|
+
of moderate-sized problems.
|
|
38
|
+
fixed_temp_sampler_num_reads: int | None
|
|
39
|
+
Number of independent sampling runs to perform at each temperature level.
|
|
40
|
+
Each run effectively initializes a separate walker in the population. Multiple
|
|
41
|
+
reads provide better coverage of the solution space, increasing the diversity
|
|
42
|
+
of the initial population and improving the chances of finding the global
|
|
43
|
+
optimum. Default is None, which typically defaults to 1 or matches the number
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
max_iter: int = 20
|
|
47
|
+
max_time: int = 2
|
|
48
|
+
|
|
49
|
+
fixed_temp_sampler_num_sweeps: int = 10_000
|
|
50
|
+
fixed_temp_sampler_num_reads: int | None = None
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def algorithm_name(self) -> str:
|
|
54
|
+
"""
|
|
55
|
+
Returns the name of the algorithm.
|
|
56
|
+
|
|
57
|
+
This abstract property method is intended to be overridden by subclasses.
|
|
58
|
+
It should provide the name of the algorithm being implemented.
|
|
59
|
+
|
|
60
|
+
Returns
|
|
61
|
+
-------
|
|
62
|
+
str
|
|
63
|
+
The name of the algorithm.
|
|
64
|
+
"""
|
|
65
|
+
return "PA"
|
|
66
|
+
|
|
67
|
+
@classmethod
|
|
68
|
+
def get_default_backend(cls) -> DWave:
|
|
69
|
+
"""
|
|
70
|
+
Return the default backend implementation.
|
|
71
|
+
|
|
72
|
+
This property must be implemented by subclasses to provide
|
|
73
|
+
the default backend instance to use when no specific backend
|
|
74
|
+
is specified.
|
|
75
|
+
|
|
76
|
+
Returns
|
|
77
|
+
-------
|
|
78
|
+
IBackend
|
|
79
|
+
An instance of a class implementing the IBackend interface that serves
|
|
80
|
+
as the default backend.
|
|
81
|
+
"""
|
|
82
|
+
return DWave()
|
|
83
|
+
|
|
84
|
+
@classmethod
|
|
85
|
+
def get_compatible_backends(cls) -> tuple[type[DWave], ...]:
|
|
86
|
+
"""
|
|
87
|
+
Check at runtime if the used backend is compatible with the solver.
|
|
88
|
+
|
|
89
|
+
Returns
|
|
90
|
+
-------
|
|
91
|
+
tuple[type[IBackend], ...]
|
|
92
|
+
True if the backend is compatible with the solver, False otherwise.
|
|
93
|
+
|
|
94
|
+
"""
|
|
95
|
+
return (DWave,)
|
luna_quantum/solve/parameters/algorithms/simulated_annealing/qbsolv_like_simulated_annealing.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
|
|
5
|
+
from luna_quantum.solve.domain.abstract import LunaAlgorithm
|
|
6
|
+
from luna_quantum.solve.parameters.algorithms.base_params import (
|
|
7
|
+
SimulatedAnnealingBaseParams,
|
|
8
|
+
)
|
|
9
|
+
from luna_quantum.solve.parameters.backends import DWave
|
|
10
|
+
from luna_quantum.solve.parameters.mixins.qbsolv_like_mixin import QBSolvLikeMixin
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class QBSolvLikeSimulatedAnnealing(LunaAlgorithm[DWave], QBSolvLikeMixin):
|
|
14
|
+
"""
|
|
15
|
+
QBSolv Like Simulated Annealing solver.
|
|
16
|
+
|
|
17
|
+
QBSolv Like Simulated Annealing breaks down the problem and solves the parts
|
|
18
|
+
individually using a classic solver that uses Simulated Annealing.
|
|
19
|
+
This particular implementation uses hybrid.SimulatedAnnealingSubproblemSampler
|
|
20
|
+
(https://docs.ocean.dwavesys.com/projects/hybrid/en/stable/reference/samplers.html#simulatedannealingsubproblemsampler)
|
|
21
|
+
as a sampler for the subproblems to achieve a QBSolv like behaviour.
|
|
22
|
+
|
|
23
|
+
This class combines parameters from multiple sources:
|
|
24
|
+
- QBSolvLikeMixin: Provides parameters for the QBSolv-like decomposition approach
|
|
25
|
+
- SimulatedAnnealingParams: Provides parameters specific to simulated annealing
|
|
26
|
+
|
|
27
|
+
Attributes
|
|
28
|
+
----------
|
|
29
|
+
decomposer_size: int
|
|
30
|
+
Size for the decomposer, which determines the maximum subproblem size to be
|
|
31
|
+
handled in each iteration. Larger values may produce better solutions but
|
|
32
|
+
increase computational complexity exponentially. Default is 50, which balances
|
|
33
|
+
solution quality with reasonable runtime.
|
|
34
|
+
rolling: bool
|
|
35
|
+
Whether to use rolling window decomposition for the solver. When enabled,
|
|
36
|
+
this allows for overlapping subproblems with shared variables, which can
|
|
37
|
+
improve solution quality by better handling interactions across subproblem
|
|
38
|
+
boundaries. Default is True.
|
|
39
|
+
rolling_history: float
|
|
40
|
+
Rolling history factor controlling how much of previous subproblem solutions
|
|
41
|
+
are considered when solving subsequent subproblems. Higher values incorporate
|
|
42
|
+
more historical information but may slow convergence to new solutions.
|
|
43
|
+
Default is 0.15 (15% retention).
|
|
44
|
+
max_iter: int | None
|
|
45
|
+
Maximum number of iterations (decomposition and solving cycles) to perform.
|
|
46
|
+
Higher values allow for more thorough optimization but increase runtime.
|
|
47
|
+
Default is 100.
|
|
48
|
+
max_time: int
|
|
49
|
+
Time in seconds after which the algorithm will stop, regardless of convergence
|
|
50
|
+
status. Provides a hard time limit for time-constrained applications.
|
|
51
|
+
Default is 5.
|
|
52
|
+
convergence: int
|
|
53
|
+
Number of iterations with unchanged output to terminate algorithm. Higher values
|
|
54
|
+
ensure more stable solutions but may increase computation time unnecessarily
|
|
55
|
+
if the algorithm has already found the best solution. Default is 3.
|
|
56
|
+
target: float | None
|
|
57
|
+
Energy level that the algorithm tries to reach. If this target energy is
|
|
58
|
+
achieved, the algorithm will terminate early. Default is None, meaning the
|
|
59
|
+
algorithm will run until other stopping criteria are met.
|
|
60
|
+
rtol: float
|
|
61
|
+
Relative tolerance for convergence. Used when comparing energy values between
|
|
62
|
+
iterations to determine if significant improvement has occurred. Default uses
|
|
63
|
+
DEFAULT_RTOL.
|
|
64
|
+
atol: float
|
|
65
|
+
Absolute tolerance for convergence. Used alongside rtol when comparing energy
|
|
66
|
+
values to determine if the algorithm has converged. Default uses DEFAULT_ATOL.
|
|
67
|
+
num_reads : Union[int, None]
|
|
68
|
+
Number of independent runs of the algorithm, each producing one solution sample.
|
|
69
|
+
Multiple reads with different random starting points increase the chance of
|
|
70
|
+
finding the global optimum. Default is None, which matches the number of initial
|
|
71
|
+
states (or just one read if no initial states are provided).
|
|
72
|
+
num_sweeps : Union[int, None]
|
|
73
|
+
Number of iterations/sweeps per run, where each sweep updates all variables
|
|
74
|
+
once. More sweeps allow more thorough exploration but increase runtime.
|
|
75
|
+
Default is 1,000, suitable for small to medium problems.
|
|
76
|
+
beta_range : Union[List[float], Tuple[float, float], None]
|
|
77
|
+
The inverse temperature (β=1/T) schedule endpoints, specified as [start, end].
|
|
78
|
+
A wider range allows more exploration. Default is calculated based on the
|
|
79
|
+
problem's energy scale to ensure appropriate acceptance probabilities.
|
|
80
|
+
beta_schedule_type : Literal["linear", "geometric"]
|
|
81
|
+
How beta values change between endpoints:
|
|
82
|
+
- "linear": Equal steps (β₁, β₂, ...) - smoother transitions
|
|
83
|
+
- "geometric": Multiplicative steps (β₁, r·β₁, r²·β₁, ...) - spends more time at
|
|
84
|
+
lower temperatures for fine-tuning
|
|
85
|
+
Default is "geometric", which often performs better for optimization problems.
|
|
86
|
+
initial_states_generator : Literal["none", "tile", "random"]
|
|
87
|
+
How to handle cases with fewer initial states than num_reads:
|
|
88
|
+
- "none": Raises error if insufficient initial states
|
|
89
|
+
- "tile": Reuses provided states by cycling through them
|
|
90
|
+
- "random": Generates additional random states as needed
|
|
91
|
+
Default is "random", which maximizes exploration.
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
simulated_annealing: SimulatedAnnealingBaseParams = Field(
|
|
95
|
+
default_factory=SimulatedAnnealingBaseParams
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def algorithm_name(self) -> str:
|
|
100
|
+
"""
|
|
101
|
+
Returns the name of the algorithm.
|
|
102
|
+
|
|
103
|
+
This abstract property method is intended to be overridden by subclasses.
|
|
104
|
+
It should provide the name of the algorithm being implemented.
|
|
105
|
+
|
|
106
|
+
Returns
|
|
107
|
+
-------
|
|
108
|
+
str
|
|
109
|
+
The name of the algorithm.
|
|
110
|
+
"""
|
|
111
|
+
return "QLSA"
|
|
112
|
+
|
|
113
|
+
@classmethod
|
|
114
|
+
def get_default_backend(cls) -> DWave:
|
|
115
|
+
"""
|
|
116
|
+
Return the default backend implementation.
|
|
117
|
+
|
|
118
|
+
This property must be implemented by subclasses to provide
|
|
119
|
+
the default backend instance to use when no specific backend
|
|
120
|
+
is specified.
|
|
121
|
+
|
|
122
|
+
Returns
|
|
123
|
+
-------
|
|
124
|
+
IBackend
|
|
125
|
+
An instance of a class implementing the IBackend interface that serves
|
|
126
|
+
as the default backend.
|
|
127
|
+
"""
|
|
128
|
+
return DWave()
|
|
129
|
+
|
|
130
|
+
@classmethod
|
|
131
|
+
def get_compatible_backends(cls) -> tuple[type[DWave]]:
|
|
132
|
+
"""
|
|
133
|
+
Check at runtime if the used backend is compatible with the solver.
|
|
134
|
+
|
|
135
|
+
Returns
|
|
136
|
+
-------
|
|
137
|
+
tuple[type[IBackend], ...]
|
|
138
|
+
True if the backend is compatible with the solver, False otherwise.
|
|
139
|
+
|
|
140
|
+
"""
|
|
141
|
+
return (DWave,)
|
luna_quantum/solve/parameters/algorithms/simulated_annealing/repeated_reverse_simulated_annealing.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
|
|
7
|
+
from luna_quantum.solve.domain.abstract import LunaAlgorithm
|
|
8
|
+
from luna_quantum.solve.parameters.algorithms.base_params import (
|
|
9
|
+
SimulatedAnnealingParams,
|
|
10
|
+
)
|
|
11
|
+
from luna_quantum.solve.parameters.backends import DWave
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class RepeatedReverseSimulatedAnnealing(SimulatedAnnealingParams, LunaAlgorithm[DWave]):
|
|
15
|
+
"""
|
|
16
|
+
Parameters for the Repeated Reverse Simulated Annealing solver.
|
|
17
|
+
|
|
18
|
+
This algorithm applies principles similar to quantum reverse annealing but in a
|
|
19
|
+
classical context. It starts from specified states, partially "reverses" the
|
|
20
|
+
annealing by increasing temperature to explore nearby states, then re-anneals to
|
|
21
|
+
find improved solutions. This process repeats for multiple iterations, refining
|
|
22
|
+
solutions progressively.
|
|
23
|
+
|
|
24
|
+
The approach is particularly effective for problems with complex energy landscapes
|
|
25
|
+
where standard simulated annealing might get trapped in local optima.
|
|
26
|
+
|
|
27
|
+
Attributes
|
|
28
|
+
----------
|
|
29
|
+
num_reads_per_iter: list[int] | None
|
|
30
|
+
Number of reads (independent runs) to perform in each iteration.
|
|
31
|
+
Uses num_reads_per_iter[i] in iteration i, and num_reads_per_iter[-1] once
|
|
32
|
+
the list is exhausted. If None, uses the num_reads value inherited from
|
|
33
|
+
SimulatedAnnealingParams. This allows dynamic control of sampling intensity
|
|
34
|
+
across iterations, typically starting with broader exploration and focusing
|
|
35
|
+
on refinement in later iterations. Minimum list length: 1.
|
|
36
|
+
Default is None.
|
|
37
|
+
initial_states: Any | None
|
|
38
|
+
Starting states for the first iteration. Each state defines values for all
|
|
39
|
+
problem variables and serves as a starting point for the reverse annealing
|
|
40
|
+
process. If fewer states than reads are provided, additional states are
|
|
41
|
+
generated according to the initial_states_generator setting inherited from
|
|
42
|
+
SimulatedAnnealingParams. Providing good initial states (e.g., from classical
|
|
43
|
+
heuristics) can significantly improve solution quality.
|
|
44
|
+
Default is None, which generates random initial states.
|
|
45
|
+
timeout: float
|
|
46
|
+
Maximum runtime in seconds before termination, regardless of other stopping
|
|
47
|
+
criteria. Provides a hard time limit for time-constrained applications.
|
|
48
|
+
Default is 5.0 seconds, which is suitable for small to medium-sized problems.
|
|
49
|
+
For larger or more complex problems, consider increasing this value.
|
|
50
|
+
max_iter: int
|
|
51
|
+
Maximum number of reverse annealing iterations to perform. Each iteration
|
|
52
|
+
involves: starting from the best states found so far, raising temperature to
|
|
53
|
+
explore nearby configurations, then gradually cooling to refine solutions.
|
|
54
|
+
More iterations generally improve solution quality but increase runtime.
|
|
55
|
+
Default is 10, providing a good balance for most problems.
|
|
56
|
+
target: Any | None
|
|
57
|
+
Target energy value that triggers early termination if reached. Allows the
|
|
58
|
+
algorithm to stop when a solution of sufficient quality is found, even before
|
|
59
|
+
reaching max_iter or timeout. Default is None, which means the algorithm will
|
|
60
|
+
run until other stopping criteria are met.
|
|
61
|
+
|
|
62
|
+
num_sweeps_per_beta: int
|
|
63
|
+
Number of sweeps to perform at each temperature before cooling. More sweeps
|
|
64
|
+
per temperature allow better exploration at each temperature level.
|
|
65
|
+
Default is 1, which works well for many problems.
|
|
66
|
+
seed: Optional[int]
|
|
67
|
+
Random seed for reproducible results. Using the same seed with identical
|
|
68
|
+
parameters produces identical results. Default is None (random seed).
|
|
69
|
+
beta_schedule: Sequence[float] | None
|
|
70
|
+
Explicit sequence of beta (inverse temperature) values to use. Provides
|
|
71
|
+
complete control over the cooling schedule. Format must be compatible
|
|
72
|
+
with numpy.array.
|
|
73
|
+
Default is None, which generates a schedule based on beta_range and
|
|
74
|
+
beta_schedule_type.
|
|
75
|
+
initial_states: Optional[Any]
|
|
76
|
+
One or more starting states, each defining values for all problem variables.
|
|
77
|
+
This allows the algorithm to start from promising regions rather than random
|
|
78
|
+
points.
|
|
79
|
+
Default is None (random starting states).
|
|
80
|
+
randomize_order: bool
|
|
81
|
+
When True, variables are updated in random order during each sweep.
|
|
82
|
+
When False, variables are updated sequentially. Random updates preserve
|
|
83
|
+
symmetry of the model but are slightly slower. Default is False for
|
|
84
|
+
efficiency.
|
|
85
|
+
proposal_acceptance_criteria: Literal["Gibbs", "Metropolis"]
|
|
86
|
+
Method for accepting or rejecting proposed moves:
|
|
87
|
+
- "Gibbs": Samples directly from conditional probability distribution
|
|
88
|
+
- "Metropolis": Uses Metropolis-Hastings rule (accept if improving,
|
|
89
|
+
otherwise accept with probability based on energy difference and
|
|
90
|
+
temperature)
|
|
91
|
+
Default is "Metropolis", which is typically faster and works well for most
|
|
92
|
+
problems.
|
|
93
|
+
num_reads : Union[int, None]
|
|
94
|
+
Number of independent runs of the algorithm, each producing one solution
|
|
95
|
+
sample. Multiple reads with different random starting points increase the
|
|
96
|
+
chance of finding the global optimum. Default is None, which matches the
|
|
97
|
+
number of initial
|
|
98
|
+
states (or just one read if no initial states are provided).
|
|
99
|
+
num_sweeps : Union[int, None]
|
|
100
|
+
Number of iterations/sweeps per run, where each sweep updates all variables
|
|
101
|
+
once. More sweeps allow more thorough exploration but increase runtime.
|
|
102
|
+
Default is 1,000, suitable for small to medium problems.
|
|
103
|
+
beta_range : Union[List[float], Tuple[float, float], None]
|
|
104
|
+
The inverse temperature (β=1/T) schedule endpoints, specified as [start,
|
|
105
|
+
end]. A wider range allows more exploration. Default is calculated based
|
|
106
|
+
on the
|
|
107
|
+
problem's energy scale to ensure appropriate acceptance probabilities.
|
|
108
|
+
beta_schedule_type : Literal["linear", "geometric"]
|
|
109
|
+
How beta values change between endpoints:
|
|
110
|
+
- "linear": Equal steps (β₁, β₂, ...) - smoother transitions
|
|
111
|
+
- "geometric": Multiplicative steps (β₁, r·β₁, r²·β₁, ...) - spends more
|
|
112
|
+
time at lower temperatures for fine-tuning
|
|
113
|
+
Default is "geometric", which often performs better for optimization
|
|
114
|
+
problems.
|
|
115
|
+
initial_states_generator : Literal["none", "tile", "random"]
|
|
116
|
+
How to handle cases with fewer initial states than num_reads:
|
|
117
|
+
- "none": Raises error if insufficient initial states
|
|
118
|
+
- "tile": Reuses provided states by cycling through them
|
|
119
|
+
- "random": Generates additional random states as needed
|
|
120
|
+
Default is "random", which maximizes exploration.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
num_reads_per_iter: list[int] | None = Field(default=None, min_length=1)
|
|
124
|
+
initial_states: Any | None = None
|
|
125
|
+
timeout: float = 5.0
|
|
126
|
+
max_iter: int = 10
|
|
127
|
+
target: Any | None = None
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def algorithm_name(self) -> str:
|
|
131
|
+
"""
|
|
132
|
+
Returns the name of the algorithm.
|
|
133
|
+
|
|
134
|
+
This abstract property method is intended to be overridden by subclasses.
|
|
135
|
+
It should provide the name of the algorithm being implemented.
|
|
136
|
+
|
|
137
|
+
Returns
|
|
138
|
+
-------
|
|
139
|
+
str
|
|
140
|
+
The name of the algorithm.
|
|
141
|
+
"""
|
|
142
|
+
return "RRSA"
|
|
143
|
+
|
|
144
|
+
@classmethod
|
|
145
|
+
def get_default_backend(cls) -> DWave:
|
|
146
|
+
"""
|
|
147
|
+
Return the default backend implementation.
|
|
148
|
+
|
|
149
|
+
This property must be implemented by subclasses to provide
|
|
150
|
+
the default backend instance to use when no specific backend
|
|
151
|
+
is specified.
|
|
152
|
+
|
|
153
|
+
Returns
|
|
154
|
+
-------
|
|
155
|
+
IBackend
|
|
156
|
+
An instance of a class implementing the IBackend interface that serves
|
|
157
|
+
as the default backend.
|
|
158
|
+
"""
|
|
159
|
+
return DWave()
|
|
160
|
+
|
|
161
|
+
@classmethod
|
|
162
|
+
def get_compatible_backends(cls) -> tuple[type[DWave], ...]:
|
|
163
|
+
"""
|
|
164
|
+
Check at runtime if the used backend is compatible with the solver.
|
|
165
|
+
|
|
166
|
+
Returns
|
|
167
|
+
-------
|
|
168
|
+
tuple[type[IBackend], ...]
|
|
169
|
+
True if the backend is compatible with the solver, False otherwise.
|
|
170
|
+
|
|
171
|
+
"""
|
|
172
|
+
return (DWave,)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from luna_quantum.solve.domain.abstract import LunaAlgorithm
|
|
2
|
+
from luna_quantum.solve.parameters.algorithms.base_params import (
|
|
3
|
+
SimulatedAnnealingParams,
|
|
4
|
+
)
|
|
5
|
+
from luna_quantum.solve.parameters.backends import DWave
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SimulatedAnnealing(SimulatedAnnealingParams, LunaAlgorithm[DWave]):
|
|
9
|
+
"""
|
|
10
|
+
Simulated Annealing optimization algorithm.
|
|
11
|
+
|
|
12
|
+
Simulated Annealing mimics the physical annealing process where a material is heated
|
|
13
|
+
and then slowly cooled to remove defects. In optimization, this translates to
|
|
14
|
+
initially accepting many non-improving moves (high temperature) and gradually
|
|
15
|
+
becoming more selective (cooling) to converge to an optimum.
|
|
16
|
+
|
|
17
|
+
This class inherits all parameters from SimulatedAnnealingParams, providing a
|
|
18
|
+
complete set of controls for fine-grained customization of the annealing process.
|
|
19
|
+
|
|
20
|
+
Attributes
|
|
21
|
+
----------
|
|
22
|
+
num_sweeps_per_beta: int
|
|
23
|
+
Number of sweeps to perform at each temperature before cooling. More sweeps
|
|
24
|
+
per temperature allow better exploration at each temperature level.
|
|
25
|
+
Default is 1, which works well for many problems.
|
|
26
|
+
seed: Optional[int]
|
|
27
|
+
Random seed for reproducible results. Using the same seed with identical
|
|
28
|
+
parameters produces identical results. Default is None (random seed).
|
|
29
|
+
beta_schedule: Sequence[float] | None
|
|
30
|
+
Explicit sequence of beta (inverse temperature) values to use. Provides
|
|
31
|
+
complete control over the cooling schedule. Format must be compatible
|
|
32
|
+
with numpy.array. Default is None, which generates a schedule based on
|
|
33
|
+
beta_range and
|
|
34
|
+
beta_schedule_type.
|
|
35
|
+
initial_states: Optional[Any]
|
|
36
|
+
One or more starting states, each defining values for all problem variables.
|
|
37
|
+
This allows the algorithm to start from promising regions rather than random
|
|
38
|
+
points.
|
|
39
|
+
Default is None (random starting states).
|
|
40
|
+
randomize_order: bool
|
|
41
|
+
When True, variables are updated in random order during each sweep.
|
|
42
|
+
When False, variables are updated sequentially. Random updates preserve
|
|
43
|
+
symmetry of the model but are slightly slower. Default is False for
|
|
44
|
+
efficiency.
|
|
45
|
+
proposal_acceptance_criteria: Literal["Gibbs", "Metropolis"]
|
|
46
|
+
Method for accepting or rejecting proposed moves:
|
|
47
|
+
- "Gibbs": Samples directly from conditional probability distribution
|
|
48
|
+
- "Metropolis": Uses Metropolis-Hastings rule (accept if improving,
|
|
49
|
+
otherwise accept with probability based on energy difference and
|
|
50
|
+
temperature)
|
|
51
|
+
Default is "Metropolis", which is typically faster and works well for most
|
|
52
|
+
problems.
|
|
53
|
+
num_reads : Union[int, None]
|
|
54
|
+
Number of independent runs of the algorithm, each producing one solution
|
|
55
|
+
sample. Multiple reads with different random starting points increase the
|
|
56
|
+
chance of finding the global optimum. Default is None, which matches the
|
|
57
|
+
number of initial states (or just one read if no initial states are
|
|
58
|
+
provided).
|
|
59
|
+
num_sweeps : Union[int, None]
|
|
60
|
+
Number of iterations/sweeps per run, where each sweep updates all variables
|
|
61
|
+
once. More sweeps allow more thorough exploration but increase runtime.
|
|
62
|
+
Default is 1,000, suitable for small to medium problems.
|
|
63
|
+
beta_range : Union[List[float], Tuple[float, float], None]
|
|
64
|
+
The inverse temperature (β=1/T) schedule endpoints, specified as [start,
|
|
65
|
+
end]. A wider range allows more exploration. Default is calculated based
|
|
66
|
+
on the
|
|
67
|
+
problem's energy scale to ensure appropriate acceptance probabilities.
|
|
68
|
+
beta_schedule_type : Literal["linear", "geometric"]
|
|
69
|
+
How beta values change between endpoints:
|
|
70
|
+
- "linear": Equal steps (β₁, β₂, ...) - smoother transitions
|
|
71
|
+
- "geometric": Multiplicative steps (β₁, r·β₁, r²·β₁, ...) - spends more
|
|
72
|
+
time at lower temperatures for fine-tuning
|
|
73
|
+
Default is "geometric", which often performs better for optimization
|
|
74
|
+
problems.
|
|
75
|
+
initial_states_generator : Literal["none", "tile", "random"]
|
|
76
|
+
How to handle cases with fewer initial states than num_reads:
|
|
77
|
+
- "none": Raises error if insufficient initial states
|
|
78
|
+
- "tile": Reuses provided states by cycling through them
|
|
79
|
+
- "random": Generates additional random states as needed
|
|
80
|
+
Default is "random", which maximizes exploration.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def algorithm_name(self) -> str:
|
|
85
|
+
"""
|
|
86
|
+
Returns the name of the algorithm.
|
|
87
|
+
|
|
88
|
+
This abstract property method is intended to be overridden by subclasses.
|
|
89
|
+
It should provide the name of the algorithm being implemented.
|
|
90
|
+
|
|
91
|
+
Returns
|
|
92
|
+
-------
|
|
93
|
+
str
|
|
94
|
+
The name of the algorithm.
|
|
95
|
+
"""
|
|
96
|
+
return "SA"
|
|
97
|
+
|
|
98
|
+
@classmethod
|
|
99
|
+
def get_default_backend(cls) -> DWave:
|
|
100
|
+
"""
|
|
101
|
+
Return the default backend implementation.
|
|
102
|
+
|
|
103
|
+
This property must be implemented by subclasses to provide
|
|
104
|
+
the default backend instance to use when no specific backend
|
|
105
|
+
is specified.
|
|
106
|
+
|
|
107
|
+
Returns
|
|
108
|
+
-------
|
|
109
|
+
IBackend
|
|
110
|
+
An instance of a class implementing the IBackend interface that serves
|
|
111
|
+
as the default backend.
|
|
112
|
+
"""
|
|
113
|
+
return DWave()
|
|
114
|
+
|
|
115
|
+
@classmethod
|
|
116
|
+
def get_compatible_backends(cls) -> tuple[type[DWave], ...]:
|
|
117
|
+
"""
|
|
118
|
+
Check at runtime if the used backend is compatible with the solver.
|
|
119
|
+
|
|
120
|
+
Returns
|
|
121
|
+
-------
|
|
122
|
+
tuple[type[IBackend], ...]
|
|
123
|
+
True if the backend is compatible with the solver, False otherwise.
|
|
124
|
+
|
|
125
|
+
"""
|
|
126
|
+
return (DWave,)
|