### Install luna-quantum SDK Source: https://docs.aqarios.com/luna-solve/get-started Install the luna-quantum SDK using pip or poetry. ```bash uv add luna-quantum ``` ```bash pip install luna-quantum ``` ```bash poetry add luna-quantum ``` -------------------------------- ### Production Planning Example Source: https://docs.aqarios.com/luna-model/user-guide/modeling-basics A complete example demonstrating how to set up a production planning problem, including defining variables, resource constraints, demand constraints, and the objective function. ```python from luna_model import Model, Vtype, Sense model = Model() # Products to manufacture products = ['Widget', 'Gadget', 'Doohickey'] # Production variables (units to produce) production = {} for p in products: production[p] = model.add_variable( f"produce_{p}", vtype=Vtype.INTEGER, lower=0, upper=1000 ) # Resource requirements (hours per unit) labor = {'Widget': 2, 'Gadget': 3, 'Doohickey': 1} machine = {'Widget': 1, 'Gadget': 2, 'Doohickey': 1} # Resource availability (hours) labor_available = 500 machine_available = 400 # Resource constraints model.add_constraint( sum(labor[p] * production[p] for p in products) <= labor_available ) model.add_constraint( sum(machine[p] * production[p] for p in products) <= machine_available ) # Demand constraints (minimum production) demand = {'Widget': 50, 'Gadget': 30, 'Doohickey': 40} for p in products: model.add_constraint(production[p] >= demand[p]) # Profit per unit profit = {'Widget': 12, 'Gadget': 20, 'Doohickey': 8} # Maximize profit model.set_objective( sum(profit[p] * production[p] for p in products), sense=Sense.MAX ) print(model) ``` -------------------------------- ### Install luna_quantum Library Source: https://docs.aqarios.com/tutorials/use_case_set_partitioning_tutorial.ipynb Installs the necessary luna_quantum Python package. Run this cell if the library is not already installed. ```python # Install the python packages that are needed for the notebook %pip install --upgrade pip %pip install luna_quantum --upgrade ``` -------------------------------- ### Install luna_quantum Library Source: https://docs.aqarios.com/tutorials/use_case_set_packing_tutorial.ipynb Installs the luna_quantum library and upgrades pip. Run this cell if the library is not already installed. ```python # Install the python package that is needed for the notebook %pip install --upgrade pip %pip install luna_quantum --upgrade ``` -------------------------------- ### Initialize AqariosGpu Backend (Usage Example) Source: https://docs.aqarios.com/luna-solve/backends/simulated/aqarios-gpu Demonstrates the import and initialization of the AqariosGpu backend for use in quantum simulations. ```python from luna_quantum.backends import AqariosGpu backend = AqariosGpu() ``` -------------------------------- ### Install luna-quantum Source: https://docs.aqarios.com/luna-model/intro Install the luna-quantum package to access Luna Platform's optimization solvers and quantum computing resources. ```bash pip install luna-quantum ``` -------------------------------- ### Install Luna Quantum and NumPy Source: https://docs.aqarios.com/tutorials/qubo-problem-with-qaga-plus.ipynb Install the necessary libraries for Luna Quantum and numerical operations. Ensure pip is up-to-date before installation. ```python %pip install --upgrade pip %pip install luna_quantum numpy --upgrade ``` -------------------------------- ### Install LunaModel with uv Source: https://docs.aqarios.com/luna-model/intro Use 'uv add' for installing LunaModel. ```terminal uv add luna-model ``` -------------------------------- ### Install Libraries for Hamiltonian Cycle Problem Source: https://docs.aqarios.com/tutorials/use_case_hamiltonian_cycle_tutorial.ipynb Installs necessary Python libraries: luna_quantum, matplotlib, and networkx. Restart the kernel if prompted after installation. ```python import sys !{sys.executable} -m pip install luna_quantum matplotlib networkx ``` -------------------------------- ### Complete Model Structure Example Source: https://docs.aqarios.com/luna-model/user-guide/core-concepts An example demonstrating the creation of a model, adding variables of binary type, and setting up the basic structure for an optimization problem. ```python from luna_model import Model, Vtype, Sense # Create model model = Model() # Add variables x = model.add_variable("x", vtype=Vtype.BINARY) y = model.add_variable("y", vtype=Vtype.BINARY) z = model.add_variable("z", vtype=Vtype.BINARY) ``` -------------------------------- ### Install LunaModel with poetry Source: https://docs.aqarios.com/luna-model/intro Use 'poetry add' for installing LunaModel. ```terminal poetry add luna-model ``` -------------------------------- ### Use ZIB Backend Source: https://docs.aqarios.com/luna-solve/backends/classical/zib Import and initialize the ZIB backend for usage. This is a common way to start interacting with the backend. ```python from luna_quantum.backends import ZIB backend = ZIB() ``` -------------------------------- ### Measure execution time with Timer Source: https://docs.aqarios.com/luna-model/api/utils Use the Timer class to measure the duration of operations. Start the timer before the operation and stop it afterwards to get timing information. ```python >>> from luna_model.timer import Timer >>> timer = Timer.start() >>> # ... perform operations ... >>> timing = timer.stop() >>> print(f"Elapsed: {timing.total_seconds} seconds") Elapsed: ... seconds ``` -------------------------------- ### Initialization Source: https://docs.aqarios.com/luna-solve/algorithms/search/qbsolv-like-tabu-search Demonstrates how to initialize the QBSolvLikeTabuSearch algorithm with various parameters. ```APIDOC ## Initialization Python ```python from luna_quantum.solve.parameters.algorithms.base_params.tabu_search_params import TabuSearchBaseParams from luna_quantum.solve.parameters.algorithms.search_algorithms.qbsolv_like_tabu_search import QBSolvLikeTabuSearch algorithm = QBSolvLikeTabuSearch( backend=None, decomposer_size=50, rolling=True, rolling_history=0.15, max_iter=100, max_time=5, convergence=3, target=None, rtol=1e-05, atol=1e-08, tabu_search_params=TabuSearchBaseParams( num_reads=None, tenure=None, timeout=100 ) ) ``` ``` -------------------------------- ### Install LunaModel using uv Source: https://docs.aqarios.com/luna-model/getting-started Install LunaModel using the uv package installer. Ensure uv is installed and configured in your environment. ```bash uv add luna-model ``` -------------------------------- ### Install LunaModel with pip Source: https://docs.aqarios.com/luna-model/intro Use 'pip install' for installing LunaModel. ```terminal pip install luna-model ``` -------------------------------- ### Create and Configure a Model Source: https://docs.aqarios.com/luna-model/api/model Demonstrates basic model creation, adding variables, setting an objective, and defining constraints. Use this for general optimization problem setup. ```python >>> from luna_model import Model, Variable, Sense >>> model = Model("MyModel", sense=Sense.MAX) >>> x = model.add_variable("x") >>> y = model.add_variable("y") >>> model.objective = x * y + x >>> model.constraints += x >= 0 >>> model.constraints += y <= 5 >>> print(model) Model: MyModel Maximize x * y + x Subject To c0: x >= 0 c1: y <= 5 Binary x y ``` -------------------------------- ### Create Solution from Samples Source: https://docs.aqarios.com/luna-model/api/solution Demonstrates how to initialize a Solution object with sample data, counts, objective values, and feasibility status. Ensure the environment and variables are defined before creating samples. ```python >>> from luna_model import Solution, Environment, Variable >>> env = Environment() >>> x = Variable("x", env=env) >>> y = Variable("y", env=env) >>> samples = [{"x": 0, "y": 1}, {"x": 1, "y": 0}] >>> solution = Solution( ... samples, ... counts=[1, 1], ... obj_values=[5.0, 3.0], ... feasible=[True, True], ... env=env, ... ) ``` -------------------------------- ### QBSolv-like QPU Initialization and Usage Source: https://docs.aqarios.com/luna-solve/algorithms/quantum-annealing Demonstrates how to initialize and use the QBSolv-like QPU solver, which decomposes problems into subproblems solved on a QPU. ```APIDOC ## QBSolv-like QPU ### Initialization Python``` from luna_quantum.solve.parameters.algorithms.base_params.decomposer import Decomposer from luna_quantum.solve.parameters.algorithms.base_params.quantum_annealing_params import QuantumAnnealingParams from luna_quantum.solve.parameters.algorithms.quantum_annealing.qbsolv_like_qpu import QBSolvLikeQpu algorithm = QBSolvLikeQpu( backend=None, decomposer_size=50, rolling=True, rolling_history=0.15, max_iter=100, max_time=5, convergence=3, target=None, rtol=1e-05, atol=1e-08, num_reads=100, num_retries=0, quantum_annealing_params=QuantumAnnealingParams( anneal_offsets=None, anneal_schedule=None, annealing_time=None, auto_scale=None, fast_anneal=False, flux_biases=None, flux_drift_compensation=True, h_gain_schedule=None, initial_state=None, max_answers=None, num_reads=1, programming_thermalization=None, readout_thermalization=None, reduce_intersample_correlation=False, reinitialize_state=None ), decomposer=Decomposer( size=10, min_gain=None, rolling=True, rolling_history=1.0, silent_rewind=True, traversal='energy' ) ) ``` ### Usage Python``` from luna_quantum.algorithms import QBSolvLikeQpu algorithm = QBSolvLikeQpu() solve_job = algorithm.run(model, name="my-solve-job") ``` ``` -------------------------------- ### Initialize FlexQAOA Algorithm Source: https://docs.aqarios.com/luna-solve/algorithms/quantum-gate/flexqaoa Instantiate the FlexQAOA algorithm with custom pipeline and optimizer configurations. This example shows how to set up various constraint handling methods and an optimizer. ```python from luna_quantum.solve.parameters.algorithms.base_params.qaoa_circuit_params import LinearQAOAParams from luna_quantum.solve.parameters.algorithms.base_params.scipy_optimizer import ScipyOptimizerParams from luna_quantum.solve.parameters.algorithms.quantum_gate.flexqaoa.config import CustomConfig from luna_quantum.solve.parameters.algorithms.quantum_gate.flexqaoa.flexqaoa import FlexQAOA from luna_quantum.solve.parameters.algorithms.quantum_gate.flexqaoa.pipeline import ( IndicatorFunctionConfig, InequalityToEqualityConfig, PenaltySetting, PipelineParams, QuadraticPenaltyConfig, SetpackingAsOnehotConfig, XYMixerConfig ) algorithm = FlexQAOA( backend=None, shots=1024, reps=1, pipeline=PipelineParams( penalty=PenaltySetting( override=None, scaling=2.0 ), inequality_to_equality=InequalityToEqualityConfig( enable=True, max_slack=10 ), setpacking_as_onehot=SetpackingAsOnehotConfig( enable=True ), xy_mixer=XYMixerConfig( enable=True, trotter=1, method='ring' ), indicator_function=IndicatorFunctionConfig( enable=True, penalty=PenaltySetting( override=None, scaling=1.0 ), method='const' ), sp_quadratic_penalty=QuadraticPenaltyConfig( enable=True, penalty=PenaltySetting( override=None, scaling=2.0 ) ), quadratic_penalty=QuadraticPenaltyConfig( enable=True, penalty=PenaltySetting( override=None, scaling=2.0 ) ) ), optimizer=ScipyOptimizerParams( method='cobyla', tol=None, bounds=None, jac=None, hess=None, maxiter=100, options={} ), initial_params=LinearQAOAParams( delta_beta=0.5, delta_gamma=0.5 ), param_conversion='basic', custom_config=CustomConfig( max_qubits=None, minimize_qubits=False, wstate='log', qft_synth='full' ) ) ``` -------------------------------- ### Install Required Libraries Source: https://docs.aqarios.com/tutorials/use_case_maxindependantset_tutorial.ipynb Installs the necessary Python packages: luna-quantum, matplotlib, and networkx. Run this cell if the libraries are not already installed. ```python # Install the python packages that are needed for the notebook %pip install --upgrade pip %pip install luna-quantum --upgrade %pip install matplotlib networkx ``` -------------------------------- ### Kerberos Initialization and Usage Source: https://docs.aqarios.com/luna-solve/algorithms/quantum-annealing Demonstrates how to initialize and use the Kerberos algorithm, which combines Tabu Search, Simulated Annealing, and QPU Subproblem Sampling. ```APIDOC ## Kerberos Kerberos divides the problem into subproblems and solves them using Tabu Search, Simulated Annealing and QPU Subproblem Sampling. These algorithms are executed in parallel and afterwards the best solutions are combined. This procedure is applied iteratively until the best solution is found or a termination criterion is met. ### Initialization ```python from luna_quantum.solve.parameters.algorithms.base_params.decomposer import Decomposer from luna_quantum.solve.parameters.algorithms.base_params.quantum_annealing_params import QuantumAnnealingParams from luna_quantum.solve.parameters.algorithms.base_params.simulated_annealing_params import SimulatedAnnealingBaseParams from luna_quantum.solve.parameters.algorithms.base_params.tabu_kerberos_params import TabuKerberosParams from luna_quantum.solve.parameters.algorithms.quantum_annealing.kerberos import Kerberos algorithm = Kerberos( backend=None, num_reads=100, num_retries=0, max_iter=100, max_time=5, convergence=3, target=None, rtol=1e-05, atol=1e-08, simulated_annealing_params=SimulatedAnnealingBaseParams( num_reads=None, num_sweeps=1000, beta_range=None, beta_schedule_type='geometric', initial_states_generator='random' ), quantum_annealing_params=QuantumAnnealingParams( anneal_offsets=None, anneal_schedule=None, annealing_time=None, auto_scale=None, fast_anneal=False, flux_biases=None, flux_drift_compensation=True, h_gain_schedule=None, initial_state=None, max_answers=None, num_reads=1, programming_thermalization=None, readout_thermalization=None, reduce_intersample_correlation=False, reinitialize_state=None ), tabu_kerberos_params=TabuKerberosParams( num_reads=None, tenure=None, timeout=100, initial_states_generator='random', max_time=None ), decomposer=Decomposer( size=10, min_gain=None, rolling=True, rolling_history=1.0, silent_rewind=True, traversal='energy' ) ) ``` ### Usage ```python from luna_quantum.algorithms import Kerberos algorithm = Kerberos() solve_job = algorithm.run(model, name="my-solve-job") ``` ``` -------------------------------- ### Initialize DWave Backend Source: https://docs.aqarios.com/luna-solve/backends/classical/dwave Instantiate the DWave backend. This is the first step to using the DWave solver. ```Python from luna_quantum.solve.parameters.backends.dwave import DWave backend = DWave() ``` -------------------------------- ### Initialize Aqarios Backend Source: https://docs.aqarios.com/luna-solve/backends/simulated/aqarios Import and instantiate the Aqarios backend for use. ```python from luna_quantum.solve.parameters.backends.aqarios import Aqarios backend = Aqarios() ``` -------------------------------- ### Initialize ZIB Backend Source: https://docs.aqarios.com/luna-solve/backends/classical/zib Instantiate the ZIB backend. This is the first step before using any ZIB-related functionalities. ```python from luna_quantum.solve.parameters.backends.zib import ZIB backend = ZIB() ``` -------------------------------- ### Complete Integration Example with D-Wave and NumPy Source: https://docs.aqarios.com/luna-model/translators/solution-translators Demonstrates a full workflow: creating an optimization model, solving it with D-Wave's SimulatedAnnealingSampler, and converting the results using DwaveTranslator and NumpyTranslator. ```python from luna_model import Model, Vtype, Sense from luna_model.utils import quicksum from luna_model.translator import ( BqmTranslator, DwaveTranslator, NumpyTranslator ) from dimod import SimulatedAnnealingSampler import numpy as np # Create optimization model model = Model(name="Portfolio", sense=Sense.MIN) n_assets = 5 allocations = [ model.add_variable(f"a_{i}", vtype=Vtype.BINARY) for i in range(n_assets) ] # Objective: minimize risk, maximize return returns = [0.05, 0.08, 0.06, 0.07, 0.09] risk_matrix = np.random.rand(n_assets, n_assets) # Quadratic risk term risk = quicksum( risk_matrix[i, j] * allocations[i] * allocations[j] for i in range(n_assets) for j in range(n_assets) ) # Linear return term expected_return = quicksum(returns[i] * allocations[i] for i in range(n_assets)) model.objective = risk - 0.5 * expected_return # Constraint: select at least 2 assets model.constraints += quicksum(allocations) >= 2 # Method 1: Solve with D-Wave bqm_translator = BqmTranslator() bqm = bqm_translator.from_lm(model) sampler = SimulatedAnnealingSampler() sampleset = sampler.sample(bqm, num_reads=100) dwave_translator = DwaveTranslator() solution_dwave = dwave_translator.to_lm(sampleset) print("D-Wave solution:") print(f" Best: {solution_dwave.best()}") print(f" Objective: {min(solution_dwave.obj_values)}") # Method 2: Custom solver returning NumPy # Simulate custom solver result result_array = np.random.randint(0, 2, size=(10, n_assets)) obj_values = np.random.rand(10) * 10 numpy_translator = NumpyTranslator() solution_numpy = numpy_translator.to_lm( result_array, variable_names=[f"a_{i}" for i in range(n_assets)], obj_values=obj_values.tolist() ) print("\nNumPy solution:") print(f" Best: {solution_numpy.best()}") print(f" Objective: {min(solution_numpy.obj_values)}") ``` -------------------------------- ### Install BqmTranslator Source: https://docs.aqarios.com/luna-model/translators/model-translators Install the luna-model package with dimod support to use the BqmTranslator. ```bash pip install luna-model[dimod] ``` -------------------------------- ### Install luna-model with D-Wave support Source: https://docs.aqarios.com/luna-model/translators/solution-translators To use the DwaveTranslator, install the luna-model package with the 'dimod' extra. ```bash pip install luna-model[dimod] ``` -------------------------------- ### Initialize DWaveQpu Backend Source: https://docs.aqarios.com/luna-solve/backends/qpu/dwave-qpu Initialize the DWaveQpu backend. If the token is not provided, it will attempt to read it from environment variables. ```python from luna_quantum.backends import DWaveQpu backend = DWaveQpu() ``` -------------------------------- ### Install luna-model with Qiskit support Source: https://docs.aqarios.com/luna-model/translators/solution-translators To utilize the IbmTranslator for Qiskit results, install the luna-model package with the 'qiskit' extra. ```bash pip install luna-model[qiskit] ``` -------------------------------- ### QAOA_FO Initialization Source: https://docs.aqarios.com/luna-solve/algorithms/quantum-gate/qaoa-fo Demonstrates how to initialize the QAOA_FO algorithm. ```APIDOC ## Initialization Python``` from luna_quantum.solve.parameters.algorithms.quantum_gate.qaoa_fo import QAOA_FO algorithm = QAOA_FO( backend=None ) ``` ``` -------------------------------- ### Initialize QBSolvLikeQpu Algorithm Source: https://docs.aqarios.com/luna-solve/algorithms/quantum-annealing/qbsolv-like-qpu Initializes the QBSolvLikeQpu algorithm with custom parameters for decomposition and quantum annealing. Ensure all necessary parameters are correctly configured for your specific problem. ```python from luna_quantum.solve.parameters.algorithms.base_params.decomposer import Decomposer from luna_quantum.solve.parameters.algorithms.base_params.quantum_annealing_params import QuantumAnnealingParams from luna_quantum.solve.parameters.algorithms.quantum_annealing.qbsolv_like_qpu import QBSolvLikeQpu algorithm = QBSolvLikeQpu( backend=None, decomposer_size=50, rolling=True, rolling_history=0.15, max_iter=100, max_time=5, convergence=3, target=None, rtol=1e-05, atol=1e-08, num_reads=100, num_retries=0, quantum_annealing_params=QuantumAnnealingParams( anneal_offsets=None, anneal_schedule=None, annealing_time=None, auto_scale=None, fast_anneal=False, flux_biases=None, flux_drift_compensation=True, h_gain_schedule=None, initial_state=None, max_answers=None, num_reads=1, programming_thermalization=None, readout_thermalization=None, reduce_intersample_correlation=False, reinitialize_state=None ), decomposer=Decomposer( size=10, min_gain=None, rolling=True, rolling_history=1.0, silent_rewind=True, traversal='energy' ) ) ``` -------------------------------- ### Install pyscipopt for ZIB SCIP solver Source: https://docs.aqarios.com/luna-model/translators/solution-translators To use the ZibTranslator for SCIP solver results, you need to install the 'pyscipopt' library. ```bash pip install pyscipopt ``` -------------------------------- ### Install LunaModel using pip Source: https://docs.aqarios.com/luna-model/getting-started Use pip to install the LunaModel package. This is a common method for Python package management. ```bash pip install luna-model ``` -------------------------------- ### QBSolv-like Tabu Search Initialization and Usage Source: https://docs.aqarios.com/luna-solve/algorithms/search Demonstrates how to initialize and use the QBSolv-like Tabu Search algorithm. ```APIDOC ## QBSolv-like Tabu Search QBSolv Like Tabu Search breaks down the problem and solves the parts individually using a classic solver that uses Tabu Search. This particular implementation uses hybrid.TabuSubproblemSampler as a sampler for the subproblems to achieve a QBSolv like behaviour. ### Initialization ```python from luna_quantum.solve.parameters.algorithms.base_params.tabu_search_params import TabuSearchBaseParams from luna_quantum.solve.parameters.algorithms.search_algorithms.qbsolv_like_tabu_search import QBSolvLikeTabuSearch algorithm = QBSolvLikeTabuSearch( backend=None, decomposer_size=50, rolling=True, rolling_history=0.15, max_iter=100, max_time=5, convergence=3, target=None, rtol=1e-05, atol=1e-08, tabu_search_params=TabuSearchBaseParams( num_reads=None, tenure=None, timeout=100 ) ) ``` ### Usage ```python from luna_quantum.algorithms import QBSolvLikeTabuSearch algorithm = QBSolvLikeTabuSearch() solve_job = algorithm.run(model, name="my-solve-job") ``` ``` -------------------------------- ### Install luna-model with AWS Braket support Source: https://docs.aqarios.com/luna-model/translators/solution-translators To use the AwsTranslator for AWS Braket results, install the luna-model package with the 'braket' extra. ```bash pip install luna-model[braket] ``` -------------------------------- ### Create Constant Expression Example Source: https://docs.aqarios.com/luna-model/api/expression A minimal example showing the creation of a constant expression using `Expression.const()`. Requires an active environment. ```python >>> from luna_model import Environment, Expression >>> with Environment(): ... const = Expression.const(5.0) ``` -------------------------------- ### Initialize IQM Backend Using Environment Variables Source: https://docs.aqarios.com/luna-solve/backends/qpu/iqm Initialize the IQM backend. If AWS credentials are not explicitly provided, they will be sourced from environment variables. ```python from luna_quantum.backends import IQM backend = IQM() ``` -------------------------------- ### Install LunaSolve Dependencies Source: https://docs.aqarios.com/tutorials/your-first-optimization.ipynb Installs or upgrades necessary Python packages for LunaSolve, including networkx, matplotlib, luna_quantum, and dimod. Restart the kernel if prompted. ```python %pip install --upgrade pip %pip install networkx matplotlib luna_quantum dimod --upgrade ``` -------------------------------- ### Initialize Qctrl Backend (Simplified) Source: https://docs.aqarios.com/luna-solve/backends/qpu/qctrl Initialize the Qctrl backend with default settings. Assumes Q-CTRL API token is configured via environment variables. ```python from luna_quantum.backends import Qctrl backend = Qctrl() ``` -------------------------------- ### Usage Source: https://docs.aqarios.com/luna-solve/algorithms/search/qbsolv-like-tabu-search Shows how to use the initialized QBSolvLikeTabuSearch algorithm to run a solve job. ```APIDOC ## Usage Python ```python from luna_quantum.algorithms import QBSolvLikeTabuSearch algorithm = QBSolvLikeTabuSearch() solve_job = algorithm.run(model, name="my-solve-job") ``` ``` -------------------------------- ### Initialize AqariosGpu Backend Source: https://docs.aqarios.com/luna-solve/backends/simulated/aqarios-gpu Import and initialize the AqariosGpu backend. This backend is used for simulating QAOA on CUDA-enabled hardware. ```python from luna_quantum.solve.parameters.backends.aqarios_gpu import AqariosGpu backend = AqariosGpu() ``` -------------------------------- ### Install Python Packages for LunaSolve Source: https://docs.aqarios.com/tutorials/use_case_hamiltonian_cycle_tutorial.ipynb Installs or upgrades pip and essential Python packages like luna_quantum, matplotlib, and networkx. Ensure your environment is set up correctly before running. ```python # Install the python packages that are needed for the notebook %pip install --upgrade pip %pip install luna_quantum --upgrade %pip install matplotlib networkx ``` -------------------------------- ### QBSolvLikeSimulatedAnnealing Initialization and Usage Source: https://docs.aqarios.com/luna-solve/algorithms/simulated-annealing Demonstrates how to initialize and use the QBSolvLikeSimulatedAnnealing algorithm. ```APIDOC ## QBSolvLikeSimulatedAnnealing Initialization ### Description Initializes the QBSolvLikeSimulatedAnnealing algorithm with specified parameters. This solver is only available for commercial and academic licenses. ### Parameters - **decomposer_size** (int) - Optional - The size of the decomposer. - **rolling** (bool) - Optional - Whether to use rolling window. - **rolling_history** (float) - Optional - The history for rolling window. - **max_iter** (int) - Optional - Maximum number of iterations. - **max_time** (float) - Optional - Maximum time in seconds. - **convergence** (int) - Optional - Convergence criteria. - **target** (float) - Optional - Target value for convergence. - **rtol** (float) - Optional - Relative tolerance for convergence. - **atol** (float) - Optional - Absolute tolerance for convergence. - **backend** (any) - Optional - The backend to use for computation. - **simulated_annealing** (SimulatedAnnealingBaseParams) - Optional - Parameters for the underlying Simulated Annealing. - **num_reads** (int) - Optional - The number of reads to perform. - **num_sweeps** (int) - Optional - The number of sweeps to perform. - **beta_range** (tuple) - Optional - The range of beta values. - **beta_schedule_type** (str) - Optional - The type of beta schedule ('geometric' is default). - **initial_states_generator** (str) - Optional - The method to generate initial states ('random' is default). ### Initialization Example ```python from luna_quantum.solve.parameters.algorithms.base_params.simulated_annealing_params import SimulatedAnnealingBaseParams from luna_quantum.solve.parameters.algorithms.simulated_annealing.qbsolv_like_simulated_annealing import QBSolvLikeSimulatedAnnealing algorithm = QBSolvLikeSimulatedAnnealing( decomposer_size=50, rolling=True, rolling_history=0.15, max_iter=100, max_time=5, convergence=3, target=None, rtol=1e-05, atol=1e-08, backend=None, simulated_annealing=SimulatedAnnealingBaseParams( num_reads=None, num_sweeps=1000, beta_range=None, beta_schedule_type='geometric', initial_states_generator='random' ) ) ``` ## QBSolvLikeSimulatedAnnealing Usage ### Description Runs the QBSolvLikeSimulatedAnnealing algorithm on a given model. ### Method ```python algorithm.run(model, name="my-solve-job") ``` ### Parameters - **model** (any) - Required - The model to solve. - **name** (str) - Optional - The name of the solve job. ``` -------------------------------- ### Complete D-Wave Workflow with LunaModel Source: https://docs.aqarios.com/luna-model/translators/solution-translators This example demonstrates a full workflow: creating a LunaModel, converting it to a BQM, solving it on a D-Wave system, and then converting the results back to a LunaModel solution. ```python from luna_model import Model, Vtype from luna_model.translator import BqmTranslator, DwaveTranslator from dwave.system import DWaveSampler, EmbeddingComposite # Create model model = Model() x = model.add_variable("x", vtype=Vtype.BINARY) y = model.add_variable("y", vtype=Vtype.BINARY) model.objective = x * y - x - 2 * y # Convert to BQM bqm_translator = BqmTranslator() bqm = bqm_translator.from_lm(model) # Solve on D-Wave sampler = EmbeddingComposite(DWaveSampler()) sampleset = sampler.sample(bqm, num_reads=100) # Convert solution solution_translator = DwaveTranslator() solution = solution_translator.to_lm(sampleset) # Analyze print(f"Got {len(solution.samples)} samples") feasible_count = sum(solution.feasible) print(f"Feasible solutions: {feasible_count}") ``` -------------------------------- ### Get Backend Provider Name Source: https://docs.aqarios.com/luna-solve/qpu-tokens Access the 'provider' property of a backend instance to get its provider name. This is useful for identifying which quantum hardware provider the backend is associated with. ```python from luna_quantum.backends import DWave backend = DWave() print(backend.provider) ``` -------------------------------- ### name Source: https://docs.aqarios.com/luna-model/api/transformations Gets the unique identifier for this pass. ```APIDOC ## name() -> str ### Description Get the unique identifier for this pass. ### Returns - **str** - The unique pass name. ``` -------------------------------- ### Initialize QAOA_FO Algorithm Source: https://docs.aqarios.com/luna-solve/algorithms/quantum-gate/qaoa-fo Instantiate the QAOA_FO algorithm. The backend parameter can be set to None or a specific Q-CTRL compatible backend. ```python from luna_quantum.solve.parameters.algorithms.quantum_gate.qaoa_fo import QAOA_FO algorithm = QAOA_FO( backend=None ) ``` -------------------------------- ### Parallel Tempering QPU Initialization and Usage Source: https://docs.aqarios.com/luna-solve/algorithms/quantum-annealing Shows how to initialize and use the Parallel Tempering QPU solver, which employs multiple optimization procedures per temperature to overcome energy barriers. ```APIDOC ## Parallel Tempering QPU ### Initialization Python``` from luna_quantum.solve.parameters.algorithms.base_params.decomposer import Decomposer from luna_quantum.solve.parameters.algorithms.base_params.quantum_annealing_params import QuantumAnnealingParams from luna_quantum.solve.parameters.algorithms.quantum_annealing.parallel_tempering_qpu import ParallelTemperingQpu algorithm = ParallelTemperingQpu( 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, num_reads=100, num_retries=0, fixed_temp_sampler_num_sweeps=10000, fixed_temp_sampler_num_reads=None, quantum_annealing_params=QuantumAnnealingParams( anneal_offsets=None, anneal_schedule=None, annealing_time=None, auto_scale=None, fast_anneal=False, flux_biases=None, flux_drift_compensation=True, h_gain_schedule=None, initial_state=None, max_answers=None, num_reads=1, programming_thermalization=None, readout_thermalization=None, reduce_intersample_correlation=False, reinitialize_state=None ), decomposer=Decomposer( size=10, min_gain=None, rolling=True, rolling_history=1.0, silent_rewind=True, traversal='energy' ) ) ``` ### Usage Python``` from luna_quantum.algorithms import ParallelTemperingQpu algorithm = ParallelTemperingQpu() solve_job = algorithm.run(model, name="my-solve-job") ``` ``` -------------------------------- ### name Source: https://docs.aqarios.com/luna-model/api/transformations Gets the unique identifier for this pass. ```APIDOC ## name ### Description Get the unique identifier for this pass. ### Method `name() -> str` ### Endpoint N/A (Method) ### Parameters None ### Request Example ```python # Assuming 'pass_instance' is an instance of a transformation pass # pass_name = pass_instance.name() ``` ### Response #### Success Response (200) - **str** - The unique pass name. #### Response Example ```json { "pass_name": "EqualityConstraintsToQuadraticPenaltyPass" } ``` ``` -------------------------------- ### __getitem__(item: int) Source: https://docs.aqarios.com/luna-model/api/solution Get a result by index. ```APIDOC ## __getitem__(item: int) -> ResultView ### Description Get a result by index. ### Parameters #### Path Parameters * **`item`** (int) - Required - Index of the result to retrieve. ### Returns * `ResultView` – The result at the given index. ``` -------------------------------- ### Initialize QBSolvLikeSimulatedAnnealing Solver Source: https://docs.aqarios.com/luna-solve/algorithms/simulated-annealing/qbsolv-like-simulated-annealing Instantiate the QBSolvLikeSimulatedAnnealing solver with custom parameters for decomposition, rolling behavior, iteration limits, and simulated annealing settings. Ensure all necessary imports are included. ```python from luna_quantum.solve.parameters.algorithms.base_params.simulated_annealing_params import SimulatedAnnealingBaseParams from luna_quantum.solve.parameters.algorithms.simulated_annealing.qbsolv_like_simulated_annealing import QBSolvLikeSimulatedAnnealing algorithm = QBSolvLikeSimulatedAnnealing( decomposer_size=50, rolling=True, rolling_history=0.15, max_iter=100, max_time=5, convergence=3, target=None, rtol=1e-05, atol=1e-08, backend=None, simulated_annealing=SimulatedAnnealingBaseParams( num_reads=None, num_sweeps=1000, beta_range=None, beta_schedule_type='geometric', initial_states_generator='random' ) ) ``` -------------------------------- ### Initialize IQM Backend with Explicit Credentials Source: https://docs.aqarios.com/luna-solve/backends/qpu/iqm Initialize the IQM backend by explicitly providing AWS credentials and specifying the desired device. ```python from luna_quantum.solve.parameters.backends.aws.iqm import IQM backend = IQM( aws_access_key=None, aws_secret_access_key=None, aws_session_token=None, device='Garnet' ) ``` -------------------------------- ### `__repr__` Source: https://docs.aqarios.com/luna-model/api/variable Gets the debug string representation of the variable. ```APIDOC ## `__repr__() -> str` ### Description Get debug string representation. ``` -------------------------------- ### `__str__` Source: https://docs.aqarios.com/luna-model/api/variable Gets the human-readable string representation of the variable. ```APIDOC ## `__str__() -> str` ### Description Get human-readable string representation. ``` -------------------------------- ### Initialize QBSolvLikeTabuSearch with Custom Parameters Source: https://docs.aqarios.com/luna-solve/algorithms/search/qbsolv-like-tabu-search Instantiate the QBSolvLikeTabuSearch algorithm with specific parameters for decomposer size, rolling behavior, iteration limits, convergence criteria, and tabu search sub-parameters. ```python from luna_quantum.solve.parameters.algorithms.base_params.tabu_search_params import TabuSearchBaseParams from luna_quantum.solve.parameters.algorithms.search_algorithms.qbsolv_like_tabu_search import QBSolvLikeTabuSearch algorithm = QBSolvLikeTabuSearch( backend=None, decomposer_size=50, rolling=True, rolling_history=0.15, max_iter=100, max_time=5, convergence=3, target=None, rtol=1e-05, atol=1e-08, tabu_search_params=TabuSearchBaseParams( num_reads=None, tenure=None, timeout=100 ) ) ``` -------------------------------- ### Get Default Backend Source: https://docs.aqarios.com/luna-solve/api/algorithms/overview Returns the default backend implementation. ```APIDOC ## get_default_backend ### Description 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. ### Method `get_default_backend() -> DWave` `classmethod` ### Returns - `IBackend` - An instance of a class implementing the IBackend interface that serves as the default backend. ``` -------------------------------- ### Initialize SimulatedAnnealing with DWave Backend Source: https://docs.aqarios.com/tutorials/use_case_maxclique_tutorial.ipynb Select the SimulatedAnnealing algorithm and configure it with the DWave backend and number of reads. This setup is for solving optimization problems. ```python from luna_quantum.algorithms import SimulatedAnnealing from luna_quantum.backends import DWave # Select the SimulatedAnnealingSolver algorithm. algorithm = SimulatedAnnealing( backend=DWave(), num_reads=1000, ) # Execute an outbound solve request. job = algorithm.run(model, name="Max-Clique with SA") ``` -------------------------------- ### SCIP Initialization Source: https://docs.aqarios.com/luna-solve/algorithms/optimization/scip Demonstrates how to initialize the SCIP solver, optionally specifying a backend. ```APIDOC ## Initialization Python ```python from luna_quantum.solve.parameters.algorithms.optimization_solvers.scip import SCIP algorithm = SCIP( backend=None ) ``` ``` -------------------------------- ### Get Default Backend Source: https://docs.aqarios.com/luna-solve/api/algorithms/overview Returns the default backend implementation. ```APIDOC ## get_default_backend() -> DWave ### Description 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 * `IBackend` – An instance of a class implementing the IBackend interface that serves as the default backend. ``` -------------------------------- ### Get Default Backend Source: https://docs.aqarios.com/luna-solve/api/algorithms/overview Returns the default backend implementation. ```APIDOC ## get_default_backend() -> DWave ### Description 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 * `IBackend` - An instance of a class implementing the IBackend interface that serves as the default backend. ``` -------------------------------- ### Initialize DWaveQpu Backend with Parameters Source: https://docs.aqarios.com/luna-solve/backends/qpu/dwave-qpu Initialize the DWaveQpu backend with specific embedding parameters and QPU backend. The token can be passed directly or will be read from environment variables if None. ```python from luna_quantum.solve.parameters.backends.dwave_qpu import DWaveQpu backend = DWaveQpu( embedding_parameters=None, qpu_backend='default', token=None ) ``` -------------------------------- ### Get Default Backend Source: https://docs.aqarios.com/luna-solve/api/algorithms/overview Returns the default backend implementation. ```APIDOC ## get_default_backend ### Description 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. ### Method `get_default_backend() -> DWaveQpu` `classmethod` ### Returns * `IBackend` - An instance of a class implementing the IBackend interface that serves as the default backend. ``` -------------------------------- ### Import LunaSolve and Setup Client Source: https://docs.aqarios.com/tutorials/use_case_longest_path_tutorial.ipynb Imports the LunaSolve library and sets up the client for interacting with Luna's quantum optimization services. Ensure your API key is configured for authentication. ```python import getpass import os from luna_quantum import LunaSolve ``` -------------------------------- ### penalty_scaling Source: https://docs.aqarios.com/luna-model/api/transformations Gets the penalty scaling factor used by the pass. ```APIDOC ## penalty_scaling ### Description Get the penalty scaling factor. ### Method `penalty_scaling: float` `property` ### Endpoint N/A (Property) ### Parameters None ### Request Example ```python # Assuming 'pass_instance' is an instance of EqualityConstraintsToQuadraticPenaltyPass # scaling_factor = pass_instance.penalty_scaling ``` ### Response #### Success Response (200) - **float** - The penalty scaling factor. #### Response Example ```json { "penalty_scaling": 10.0 } ``` ``` -------------------------------- ### SAGA Initialization Source: https://docs.aqarios.com/luna-solve/algorithms/genetic/saga Demonstrates how to initialize the SAGA algorithm with various parameters. ```APIDOC ## Initialization Python ```python from luna_quantum.solve.parameters.algorithms.genetic_algorithms.saga import SAGA algorithm = SAGA( backend=None, p_size=20, p_inc_num=5, p_max=160, pct_random_states=0.25, mut_rate=0.5, rec_rate=1, rec_method='random_crossover', select_method='simple', target=None, atol=1e-08, rtol=1e-05, timeout=60.0, max_iter=100, num_sweeps=10, num_sweeps_inc_factor=1.2, num_sweeps_inc_max=7000, beta_range_type='default', beta_range=None ) ``` ``` -------------------------------- ### Create a Knapsack Optimization Model Source: https://docs.aqarios.com/luna-model/intro Demonstrates creating a maximization model with binary variables, objective function, and a weight constraint using LunaModel's Model, Sense, Vtype, and quicksum utility. ```python from luna_model import Model, Sense, Vtype from luna_model.utils import quicksum # Create a model model = Model(name="Knapsack", sense=Sense.MAX) # Define problem data n_items = 5 max_weight = 25 weights = [1.5, 10.0, 5.2, 3.5, 8.32] values = [10.0, 22.0, 3.2, 1.99, 6.25] # Add binary variables (1 = take item, 0 = don't take) items = [ model.add_variable(f"item_{i}", vtype=Vtype.BINARY) for i in range(n_items) ] # Set objective: maximize total value model.objective = quicksum(values[i] * items[i] for i in range(n_items)) # Add constraint: don't exceed weight limit model.constraints += quicksum(weights[i] * items[i] for i in range(n_items)) <= max_weight print(model) ``` -------------------------------- ### ControlFlowPass - name Source: https://docs.aqarios.com/luna-model/api/transformations Gets the unique identifier for this control-flow pass. ```APIDOC ## name() -> str ### Description Get the unique identifier for this pass. ### Returns - `str` - The unique pass name. ``` -------------------------------- ### AnalysisPass - name Source: https://docs.aqarios.com/luna-model/api/transformations Gets the unique name for this analysis pass. ```APIDOC ## name() -> str ### Description Get the name for this pass. ### Returns - `str` - The unique pass name. ``` -------------------------------- ### Set Up LunaSolve Client Source: https://docs.aqarios.com/tutorials/use_case_set_partitioning_tutorial.ipynb Initializes the LunaSolve client, securely prompts for an API key if not found in environment variables, and sets up logging. ```python import getpass import os from luna_quantum import LunaSolve from dotenv import load_dotenv load_dotenv() if "LUNA_API_KEY" not in os.environ: # Prompt securely for the key if not already set os.environ["LUNA_API_KEY"] = getpass.getpass("Enter your Luna API key: ") ls = LunaSolve() ``` -------------------------------- ### Model.num_constraints Source: https://docs.aqarios.com/luna-model/api/model Get the number of constraints currently defined in the model. ```APIDOC ## Model.num_constraints ### Description Get the number of constraints currently defined in the model. ### Property `num_constraints: int` (read-only) ### Returns * `int` – The total number of constraints. ### Examples ```python >>> model = Model() >>> x = model.add_variable("x") >>> model.constraints += x <= 5 >>> model.num_constraints 1 ``` ``` -------------------------------- ### Model.num_variables Source: https://docs.aqarios.com/luna-model/api/model Get the number of variables currently defined in the model. ```APIDOC ## Model.num_variables ### Description Get the number of variables currently defined in the model. ### Property `num_variables: int` (read-only) ### Returns * `int` – The total number of variables. ### Examples ```python >>> model = Model() >>> x = model.add_variable("x") >>> y = model.add_variable("y") >>> model.objective += x + y >>> model.num_variables 2 ``` ``` -------------------------------- ### Basic Usage Source: https://docs.aqarios.com/luna-solve/backends/qpu/ionq A simplified way to initialize the IonQ backend, assuming AWS credentials are set up. ```APIDOC ## Usage Python ```python from luna_quantum.backends import IonQ backend = IonQ() ``` ``` -------------------------------- ### Cancel a SolveJob Source: https://docs.aqarios.com/luna-solve/solve-job Cancel a SolveJob that has not yet started execution. ```APIDOC ## Cancel a SolveJob You can cancel a SolveJob as long as it hasn't started yet. To cancel a SolveJob use: ```python solve_job.cancel() ``` ``` -------------------------------- ### Initialize ParallelTemperingQpu Algorithm Source: https://docs.aqarios.com/luna-solve/algorithms/quantum-annealing/parallel-tempering-qpu Instantiate the ParallelTemperingQpu algorithm with various parameters. Ensure all necessary imports are present. ```python from luna_quantum.solve.parameters.algorithms.base_params.decomposer import Decomposer from luna_quantum.solve.parameters.algorithms.base_params.quantum_annealing_params import QuantumAnnealingParams from luna_quantum.solve.parameters.algorithms.quantum_annealing.parallel_tempering_qpu import ParallelTemperingQpu algorithm = ParallelTemperingQpu( 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, num_reads=100, num_retries=0, fixed_temp_sampler_num_sweeps=10000, fixed_temp_sampler_num_reads=None, quantum_annealing_params=QuantumAnnealingParams( anneal_offsets=None, anneal_schedule=None, annealing_time=None, auto_scale=None, fast_anneal=False, flux_biases=None, flux_drift_compensation=True, h_gain_schedule=None, initial_state=None, max_answers=None, num_reads=1, programming_thermalization=None, readout_thermalization=None, reduce_intersample_correlation=False, reinitialize_state=None ), decomposer=Decomposer( size=10, min_gain=None, rolling=True, rolling_history=1.0, silent_rewind=True, traversal='energy' ) ) ```