qat.plugins.Optimizer

class qat.plugins.Optimizer(collective=False, **binding_kwargs)

A particulized Junction that provides a higher level, QLM independant interface to perform variational optimization.

Instead of providing a .execute method, it provides a .evaluate method that takes a map of <variablename, value> and returns a float.

The administrative burden on binding the variables of the abstract job and fetching the result’s value is done by the class itself, under the hood.

Parameters
  • collective (optional, bool) – see Junction class constructor arguments

  • **binding_kwargs (dict) – a collection of arguments passed to the variable binding method of the job. E.g gate set, matrix generation parameters, etc.

evaluate(values)

Bind variables into the abstract job/batch, execute the job/batch and return the “value” field of the returned Result object or the sum of the result values if a BatchResult is returned.

Parameters

values (dict) – a dictionary of values (str, float)

Returns

a floating point number or a complex, depending on the structure of the Job

Return type

float or complex

abstract optimize(var_names)

This function will be called upon the reception of a fresh abstract QLM object (e.g a Job or a Batch depending the Junction configuration).

Upon reception of a fresh QLM object (Job, Batch), the object is stored in the self.job attribute, and this method is called with as single argument the list of all the variables appearing inside the object.

Warning

This is an abstract method with no default implementation. You should build your own optimizer by inheriting from this class and implementing your own .optimize method.

Parameters

var_names (list) – the list of variables to optimize upon

Returns

this method should return a triplet of values with:

  • the optimal value found (this will correspond to the .value field in the final result object)

  • the optimal values of the parameters (these will be stored in the meta_data using the “parameters” key in the final result object)

  • any additional information (these will be also stored in the meta_data field using the “optimizer_data” key)

Return type

(float, list/np.ndarray, object)