cunqa.mappers
Contains map-like callables to distribute circuits in virtual QPUS, needed when communications among circuits are present.
Submitting circuits with classical or quantum communications
When having classical or quantum communications among circuits, method run()
is obsolete, circuits must be sent as an ensemble in order to ensure correct functioning of the communication protocols.
So, once the virtual QPUs that allow the desired type of communications are raised and circuits have been defined using CunqaCircuit
,
they can be sent using the run_distributed()
function:
>>> circuit1 = CunqaCircuit(1, "circuit_1")
>>> circuit2 = CunqaCircuit(1, "circuit_2")
>>> circuit1.h(0)
>>> circuit1.measure_and_send(0, "circuit_2")
>>> circuit2.remote_c_if("x", 0, "circuit_1")
>>>
>>> qpus = get_QPUs()
>>>
>>> qjobs = run_distributed([circuit1, circuit2], qpus)
>>> results = gather(qjobs)
Mapping circuits to virtual QPUs in optimization problems
Variational Quantum Algorithms [1] require from numerous executions of parametric cirucits, while in each step of the optimization process new parameters are assigned to them.
This implies that, after parameters are updated, a new circuit must be created, transpiled and then sent to the quantum processor or simulator.
For simplifying this process, we have QJobMapper
and QPUCircuitMapper
classes. Both classes are thought to be used for Scipy optimizers [2] as the workers argument in global optimizers.
QJobMapper
QJobMapper
takes a list of existing QJob
objects, then, the class can be called passing a set of parameters and a cost function.
This callable updates the each existing QJob
object with such parameters through the upgrade_parameters()
method.
Then, it gathers the results of the executions and returns the value of the cost function for each.
QPUCircuitMapper
On the other hand, QPUCircuitMapper
is instanciated with a circuit and instructions for its execution, toguether with a list of the QPU
objects.
The difference with QJobMapper
is that here the method run()
is mapped to each QPU, passing it the circuit with the given parameters assigned so that for this case several QJob
objects are created.
Examples utilizing both classes can be found in the Examples gallery. These examples focus on optimization of VQAs, using a global optimizer called Differential Evolution [3].
References:
Functions
Function to send circuits to serveral virtual QPUs allowing classical or quantum communications among them. |
Classes
Class to map the method |
|
Class to map the method |