π Get Started
In this tutorial, we will develop a quantum-powered optimization application using Luna, capable of:
- Solving complex optimization problems through the integration of quantum and classical computing
- Seamlessly accessing quantum hardware via automated backend integration
- Customizing problem configurations to meet specific requirements
- Evaluating and analyzing results effectively
We will begin by addressing a basic optimization problem and gradually introduce advanced features, highlighting key capabilities of Luna throughout the process. Letβs begin! π
LunaSolve is part of the luna-quantum SDK and can be installed with:
Solve Your First Optimization Problem
Let's solve a simple optimization problem with the QAOA.
First, authenticate with your LUNA_API_KEY:
Create Your Model
Create your model that represents the optimization problem. In this example, we create a simple constrained optimization problem:
from luna_quantum import Variable, Model, Vtype
# Beach items
beach_items = ["surfboard", "book", "speaker", "cooler"]
fun_values = {"surfboard":40, "book":15, "speaker":25, "cooler":35}
# Interaction dictionary: positive = synergy, negative = conflict
interactions = {
("surfboard", "book"): -25, # wet board ruins book!
("surfboard", "speaker"): 10, # music while surfing
("surfboard", "cooler"): 15, # cold drink after surfing
("book", "speaker"): -30, # can't read with loud music
("book", "cooler"): 20, # relaxing read with cold drink
("speaker", "cooler"): 30, # perfect beach party combo
}
model = Model("beach_packing_simple")
with model.environment:
# Create binary variables from the list
items = {name: Variable(name, vtype=Vtype.BINARY) for name in beach_items}
# Invert objective values to match minimization problem
model.objective = (-1) * sum(f_val * items[i] for i, f_val in fun_values.items())
# Invert interaction terms to match minimization problem
model.objective += (-1) * sum(val * items[i] * items[j] for (i,j), val in interactions.items())
print(model)
Tip
Check out the Model docs for more information how to build your model programmatically or from various formats.
Solve the Optimization Problem
Solve the optimization problem with QAOA and analyze the results.
from luna_quantum.algorithms import QAOA
from luna_quantum.backends import IBM
# Define the algorithm and backend
algorithm = QAOA(
backend=IBM(
backend=IBM.SimulatorBackend(
backend_type='simulator',
backend_name='aer'
)
),
reps=1,
shots=1024
)
# Run your algorithm
solve_job = algorithm.run(model, name="beach-packing-with-qaoa")
solution = solve_job.result()
Modeling Your Optimization Problem
Understand how to effectively structure and formulate your optimization problem using the Model component.
Select Your Algorithm and Backend
Learn how to choose and implement the most suitable algorithm for your problem, and configure your preferred backend for optimal performance.
Additional Resources
For further guidance, explore the following references:
- Model β Detailed instructions on modeling optimization problems
- Algorithms β Comprehensive list of available algorithms and their configurations
- Backends β Comprehensive list of available backends and their configurations
- LunaSolve β Overview of the LunaSolve platform for optimization