QuOp Functions
- QuOp Function
QuOp Functions define the various aspects of a QVA or modify the simulation methods used by the
quop_mpi.Ansatz
class.- FunctionDict
Prior to QVA simulation, positional arguments of a QuOp Function are bound to the attributes of the receiving class if a match is found. Additional positional and keyword are specified via a FunctionDict:
function_dict : {"args":List[Any], "kwargs":Dict}
The
"args"
and"kwargs"
elements of a FunctionDict are both optional. If present, these are passed to a bound QuOp Function as:bound_quop_function(*function_dict["args"], **function_dict["kwargs"])
- Observables Function
Returns a 1-D real array containing
local_i
elements of the observables with global offsetlocal_i_offset
. Passed to thequop_mpi.Ansatz.set_observables()
method and bound to the attributes of thequop_mpi.Ansatz
class.Predefined Observables Functions are included in the
quop_mpi.state
module. Seequop_mpi.Ansatz
for a selected list of available attributes.Typical structure:
def observables_function( system_size : int local_i : int, local_i_offset : int, *args, **kwargs) -> np.ndarray[np.complex128]: ... return observables
- Initial State Function
Returns a 1-D complex array containing
local_i
elements of the initial state with global offsetlocal_i_offset
. Passed to thequop_mpi.Ansatz.set_initial_state()
method and bound to the attributes of thequop_mpi.Ansatz
class.Typical structure:
Predefined Initial State Functions are included in the
quop_mpi.state
module. Seequop_mpi.Ansatz
for a selected list of available attributes.See
quop_mpi.Ansatz
for a selected list of available attributes.def initial_state_function( system_size : int local_i : int, local_i_offset : int, *args, **kwargs) -> np.ndarray[np.complex128]: ... return initial_state
- Free Parameters Function
Returns an array of integers that specifies a subset of free parameters. Passed to
quop_mpi.Ansatz.set_free_params()
.See
quop_mpi.Ansatz
for a selected list of available attributes,Typical Structure
def free_params_function( ansatz_depth : int, total_params : int, *args, **kwargs ) -> List[int] ... return free_params
- Sampling Function
Returns an objective function value computed from batches of observables values that are sampled based on the probability distribution of the wavefunction state vector during simulation together with a boolean that specifies wether the objective function value should be passed to the optimiser or more sample batches taken. Passed to
quop_mpi.Ansatz.set_sampling()
.See
quop_mpi.Ansatz
for a selected list of available attributes,Note
The
quop_mpi.Ansatz
class computes the expectation value exactly by default.Typical Structure
def sampling_function( samples : List[ndarray[float64]], *args, **kwargs ) -> (float, bool) ... return objective_function_value, value_accepted
The
samples
argument is a list of 1-D real arrays containingsample_block_size
observables values. Ifvalue_accepted
is notTrue
, an additional sample block is appended tosamples
.- Jacobian Function
Enables distributed parallel computation of the objective function gradient. Returns the partial derivative of the objective function with respect to the variational parameter with index
var
. Used to compute the objective function gradient is parallel if using a gradient-informed optimiser. Passed toquop_mpi.Ansatz.set_parallel_jacobian()
.The
quop_mpi.Ansatz
supports numerical approximation of the gradient using the forward and central finite difference methods (specified viaquop_mpi.Ansatz.set_parallel_jacobian()
). Seequop_mpi.Ansatz
for a list of available attributes.Note
The
quop_mpi.Ansatz
class computes the objective function gradient sequentially by default.The default optimisation method of the
quop_mpi.Ansatz
class, the BFGS algorithm, is gradient informed.
Typical Structure
def jacobian_function( variational_parameters: np.ndarray[np.float], evaluate: Callable, var: int, *args, **kwargs ) -> float: ... return partial_derivative_value
The
evaluate
argument is bound to thequop_mpi.Ansatz.evaluate()
method which implements lazy computation of the objective function. This is the recommended method for use in numerical approximation of the gradient by finite-difference methods.- Operator Function
Returns an operator object that is compatible with the propagation method of specific
unitary
class. Seequop_mpi.Unitary()
.Predefined Operator Functions are included with each
unitary
class in thequop_mpi.propagator
module underquop_mpi.propagator.<unitary>.operator
. Seequop_mpi.Unitary
and the predefinedunitary
classes in thequop_mpi.propagator
module for lists of available attributes.Typical Structure
def operator_function( system_size : int, local_i : int, local_i_offset : int, variational_parameters : ndarray[float], *args, **kwargs ) -> Any: ... return operator
Operator Functions with one or more variational parameters require the
variational_parameters
positional argument. Operator Functions with no variational parameters do not.- Parameter Function
Returns initial values for the variational parameters associated with an instance of the
quop_mpi.Unitary()
class.Predefined Parameter Functions are included in the
quop_mpi.param
module. Seequop_mpi.Unitary
for a list of available attributes.Typical Structure
def param_function( n_params : int, *args, **kwargs ) -> List[float]: ... return variational_parameters