Problem generators
myQLM provides batch generators used to both generate a quantum job (used to solve a combintorial problem) and parse the result to return a user friendly data-structure.
These batch generators can generate different types of job, to be compatible with different types of QPUs. The different types of jobs are:
These jobs are generated using the method qaoa_ansatz()
of CircuitGenerator
by passing job_type="qaoa"
to the constructor of the generator and are designed to be executed on a digital QPU. Two jobs will be submitted to the QPU:
a variational job to determine the best parameters
a sampling job to find an actual solution to the combinatorial problem
For instance, the following example uses MaxCutGenerator
to generate jobs solving
the NP-Hard problem Max Cut on a graph given to this generator:
import networkx as nx
from qat.generators import MaxCutGenerator
graph = nx.full_rary_tree(3, 6)
# The job_type here can also be "schedule" or "annealing"
batches = MaxCutGenerator(job_type="qaoa").generate(None, graph)
This generator can be piped to a computation stack of plugins and a QPU, creating an Application
. The Max Cut problem can then be solved by calling the execute()
method.
import networkx as nx
from qat.generators import MaxCutGenerator
from qat.plugins import ScipyMinimizePlugin
from qat.qpus import get_default_qpu
graph = nx.full_rary_tree(3, 6)
max_cut_application = (
MaxCutGenerator(job_type="qaoa")
| ScipyMinimizePlugin(method="COBYLA", tol=1e-5, options={"maxiter": 200})
| get_default_qpu()
)
combinatorial_result = max_cut_application.execute(graph)
print(combinatorial_result.subsets)
print(combinatorial_result.cost)
[[0, 4, 5], [1, 2, 3]]
-5.0
The parsed combinatorial result can also be displayed with NetworkX:
combinatorial_result.display()
These jobs are generated using the method to_job()
of Ising
by passing job_type="annealing"
to the constructor of the generator and are designed to be executed with SimulatedAnnealing
.
For instance, the following example uses MaxCutGenerator
to generate jobs solving the NP-Hard problem Max Cut on a graph given to this generator:
import networkx as nx
from qat.generators import MaxCutGenerator
graph = nx.full_rary_tree(3, 6)
# The job_type here can also be "qaoa" or "schedule"
batches = MaxCutGenerator(job_type="annealing").generate(None, graph)
This generator can be piped to a computation stack of plugins and a QPU, creating an Application
. The Max Cut problem can then be solved by calling the execute()
method.
import networkx as nx
from qat.generators import MaxCutGenerator
from qat.qpus import SimulatedAnnealing
graph = nx.full_rary_tree(3, 6)
max_cut_application = (
MaxCutGenerator(job_type="annealing")
| SimulatedAnnealing()
)
combinatorial_result = max_cut_application.execute(graph)
print(combinatorial_result.subsets)
print(combinatorial_result.cost)
Traceback (most recent call last):
File "<stdin>", line 9, in <module>
TypeError: __init__() missing 2 required positional arguments: 'temp_t' and 'n_steps'
The parsed combinatorial result can also be displayed with NetworkX:
combinatorial_result.display()
These jobs are generated by passing job_type="schedule"
to the constructor of the generator
and are designed to be executed on an analog QPU.
Note
Analog QPUs are currently not available in myQLM. Instead, they can be found in the full Qaptiva appliance.