cunqa.mappers.QJobMapper
- class cunqa.mappers.QJobMapper(qjobs: list[QJob])
Bases:
object
Class to map the method
upgrade_parameters()
to a set of jobs sent to virtual QPUs.The core of the class is on its
__call__()
method, to which parameters that the methodupgrade_parameters()
takes are passed toguether with a cost function, so that a the value for this cost for each initialQJob
is returned.An example is shown below, once we have a list of
QJob
objects as qjobs:>>> mapper = QJobMapper(qjobs) >>> >>> # 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)
We intuitively see how convinient this class can be for optimization algorithms: one has a parametric circuit to which updated sets of parameters can be sent obtaining the value of the cost back. Examples applied to optimizations are shown at the Examples gallery.
Attributes
|
List of jobs that are mapped. |
Methods
- QJobMapper.__call__(func, population)
Callable method to map the function func to the results of assigning population to the given jobs. Regarding the population, each set of parameters will be assigned to each
QJob
object, so the list must have size (N,p), being N the lenght ofqjobs
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 (
callable
) – function to be passed to the results of the jobs.population (
list[list[int
|float]]
) – list of vectors to be mapped to the jobs.
- Returns:
List of outputs of the function applied to the results of each job for the given population.