Problem generators
Qaptiva provides batch generators used to both generate a quantum job (used to solve a combinatorial problem) and parse the result to return a user-friendly 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_job() 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 "aqo" or "sqa"
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()ofIsingby passingjob_type="sqa"to the constructor of the generator and are designed to be executed withSimulatedAnnealing.For instance, the following example uses
MaxCutGeneratorto 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 "aqo" batches = MaxCutGenerator(job_type="sqa").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 theexecute()method.
These jobs are generated by passing job_type="aqo" to the constructor of the generator
and are designed to be executed on an analog QPU (or job_type="ryd" for Rydberg atom QPU).
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 "sqa"
batches = MaxCutGenerator(job_type="aqo").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 QutipQPU
graph = nx.full_rary_tree(3, 6)
max_cut_application = (
MaxCutGenerator(job_type="aqo")
| QutipQPU()
)
combinatorial_result = max_cut_application.execute(graph, tmax=3)
print(combinatorial_result.subsets)
print(combinatorial_result.cost)
[1/1] Cythonizing qtcoeff_e7561c7f293b92d11d7146d6be5392.pyx
running build_ext
building 'qtcoeff_e7561c7f293b92d11d7146d6be5392' extension
g++ -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -I/usr/local/lib64/openmpi/../../include/openmpi-x86_64 -fPIC -I/usr/local/qaptiva/python_references/112/rhel9/ref314/lib/python3.14/site-packages/qutip/core/data -I/usr/local/qaptiva/python_references/112/rhel9/ref314/lib/python3.14/site-packages/numpy/_core/include -I/usr/local/qaptiva/python_references/112/rhel9/ref314/include -I/usr/local/include/python3.14 -c qtcoeff_e7561c7f293b92d11d7146d6be5392.cpp -o build/temp.linux-x86_64-cpython-314/qtcoeff_e7561c7f293b92d11d7146d6be5392.o -w -O3 -funroll-loops
g++ -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -I/usr/local/lib64/openmpi/../../include/openmpi-x86_64 -shared -L/usr/local/cuda/lib64 -L/usr/local/lib64/openmpi/lib -I/usr/local/lib64/openmpi/../../include/openmpi-x86_64 build/temp.linux-x86_64-cpython-314/qtcoeff_e7561c7f293b92d11d7146d6be5392.o -L/usr/local/lib -o build/lib.linux-x86_64-cpython-314/qtcoeff_e7561c7f293b92d11d7146d6be5392.cpython-314-x86_64-linux-gnu.so
copying build/lib.linux-x86_64-cpython-314/qtcoeff_e7561c7f293b92d11d7146d6be5392.cpython-314-x86_64-linux-gnu.so ->
[1/1] Cythonizing qtcoeff_b6166a34d0ff3a8b9cb42b5d6525de.pyx
running build_ext
building 'qtcoeff_b6166a34d0ff3a8b9cb42b5d6525de' extension
g++ -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -I/usr/local/lib64/openmpi/../../include/openmpi-x86_64 -fPIC -I/usr/local/qaptiva/python_references/112/rhel9/ref314/lib/python3.14/site-packages/qutip/core/data -I/usr/local/qaptiva/python_references/112/rhel9/ref314/lib/python3.14/site-packages/numpy/_core/include -I/usr/local/qaptiva/python_references/112/rhel9/ref314/include -I/usr/local/include/python3.14 -c qtcoeff_b6166a34d0ff3a8b9cb42b5d6525de.cpp -o build/temp.linux-x86_64-cpython-314/qtcoeff_b6166a34d0ff3a8b9cb42b5d6525de.o -w -O3 -funroll-loops
g++ -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -I/usr/local/lib64/openmpi/../../include/openmpi-x86_64 -shared -L/usr/local/cuda/lib64 -L/usr/local/lib64/openmpi/lib -I/usr/local/lib64/openmpi/../../include/openmpi-x86_64 build/temp.linux-x86_64-cpython-314/qtcoeff_b6166a34d0ff3a8b9cb42b5d6525de.o -L/usr/local/lib -o build/lib.linux-x86_64-cpython-314/qtcoeff_b6166a34d0ff3a8b9cb42b5d6525de.cpython-314-x86_64-linux-gnu.so
copying build/lib.linux-x86_64-cpython-314/qtcoeff_b6166a34d0ff3a8b9cb42b5d6525de.cpython-314-x86_64-linux-gnu.so ->
Done
Wrapping results using 1 quantum registers
Post processing a list of results of length 1
[[0, 4, 5], [1, 2, 3]]
-5.0
The parsed combinatorial result can also be displayed with NetworkX:
combinatorial_result.display()