cunqa.mappers.QPUCircuitMapper
- class cunqa.mappers.QPUCircuitMapper(qpus: list[QPU], circuit: dict | qiskit.QuantumCircuit | CunqaCircuit, transpile: bool | None = False, initial_layout: list[int] | None = None, **run_parameters: Any)
Bases:
object
Class to map the method
run()
to a list of QPUs.The class is initialized with a list of
QPU
objects associated to the virtual QPUs that are intended to work with, toguether with the circuit and the simulation instructions needed for its execution.Then, its
__call__()
method takes a set of parameters as population to assing to the circuit. Each assembled circuit is sent to each virtual QPU with the instructions provided on the instatiation of the mapper. The method returns the value for the provided function func for the result of each simulation.Its use is pretty similar to
QJobMapper
, but not needing to create theQJob
objects ahead:>>> qpus = get_QPUs(...) >>> >>> # creating the mapper with the pre-defined parametric circuit and other simulation instructions. >>> mapper = QPUCircuitMapper(qpus, circuit, shots = 1000, ...) >>> >>> # defining the parameters set accordingly to the number of parameters >>> # of the circuit and the number of QJobs in the list. >>> new_parameters = [...] >>> >>> # defining the cost function passed to the result of each QJob >>> def cost_function(result): >>> counts = result.counts >>> ... >>> return cost_value >>> >>> cost_values = mapper(cost_function, new_parameters)
For each call of the mapper, circuits are assembled, jobs are sent, results are gathered and cost values are calculated. Its implementation for optimization problems is shown at the Examples gallery.
Attributes
|
|
|
Circuit to which parameters are assigned at the |
|
Weather transpilation is wanted to be done before sending each circuit. |
|
Transpilation information, qubits of the backend to which the qubits of the circuit are mapped. |
|
Any other run instructions needed for the simulation. |
Methods
- QPUCircuitMapper.__init__(qpus: list[QPU], circuit: dict | qiskit.QuantumCircuit | CunqaCircuit, transpile: bool | None = False, initial_layout: list[int] | None = None, **run_parameters: Any)
Class constructor.
- Parameters:
qpus (
list[
QPU
]
) – list of objects linked to the virtual QPUs intended to be used.circuit (
dict
|CunqaCircuit
|qiskit.QuantumCirucit
) – circuit to be run in the QPUs.transpile (
bool
) – if True, transpilation will be done with respect to the backend of the given QPU. Default is set to False.initial_layout (
list[int]
) – Initial position of virtual qubits on physical qubits for transpilation.**run_parameters – any other simulation instructions.
- QPUCircuitMapper.__call__(func, population)
Callable method to map the function func to the results of the circuits sent to the given QPUs after assigning them population. Regarding the population, each set of parameters will be assigned to each circuit, so the list must have size (N,p), being N the lenght of
qpus
and p the number of parameters in the circuit. Mainly, this is thought for the function to take aResult
object and to return a value. For example, the function can evaluate the expected value of an observable from the output of the circuit.- Parameters:
func (
func
) – function to be mapped to the QPUs. It must take as argument the an object <class ‘qjob.Result’>.params (
list[list[float
|int]]
) – population of vectors to be mapped to the circuits sent to the QPUs.
- Returns:
List of the results of the function applied to the output of the circuits sent to the QPUs.