Skip to content

geope.grape¤

geope.grape.Grape ¤

Gradient/Hessian-based GRAPE optimiser for quantum gate synthesis.

Mirrors the Geope usage pattern: it is constructed from a Parameters object (the single source of truth for all configuration and the live optimisation state), while the optimiser method, its hyperparameters and max_steps are arguments of :meth:optimize.

Attributes:

Name Type Description
params

The bound Parameters object (also the source of the lazily-built/cached optimisation functions).

precision

Target fidelity threshold.

method

Optimiser method from the most recent :meth:optimize call ('gd', 'adam', 'nr-trm' or 'nr-rfo'); None until :meth:optimize is first called.

step_size

Transient last step size (always 0 for GRAPE).

history

Optional History logger (None unless supplied).

__dict__ class-attribute ¤
__doc__ class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.

__module__ class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.

__weakref__ property ¤

list of weak references to the object

__init__(params, precision=0.9999999, verbose=False, history=None) ¤

Initialise the Grape optimiser.

Grape requires a Parameters object — the engine, initial parameters, drift, seed, initialisation spread, projective flag and param_transform are all read from it.

Parameters:

Name Type Description Default
params Parameters

A Parameters instance bundling every input the optimiser needs.

required
precision float

Target fidelity. Defaults to 0.9999999.

0.9999999
verbose bool

Whether to print progress. Defaults to False.

False
history History | None

Optional History logger. When supplied, the full run trajectory is recorded into it; when None (default), no history is kept.

None

Raises:

Type Description
TypeError

If params is not a Parameters instance.

init(init_parameters=None, drift_parameters=None, seed=None) ¤

(Re-)initialise optimiser state.

Sets up initial parameters, drift parameters and the live state (params.parameters / params.fidelity), and records step 0 into history when one is attached.

Parameters:

Name Type Description Default
init_parameters ndarray | None

Initial parameter array. Defaults to random.

None
drift_parameters ndarray | None

Fixed drift parameter values. Defaults to ones.

None
seed int | Array | None

Random seed (int) or JAX key for reproducibility.

None
optimize(max_steps=100, method='nr-trm', **optimizer_kwargs) ¤

Run the GRAPE optimisation loop.

Iterates gradient/Hessian update steps until the fidelity exceeds self.precision or max_steps is reached.

Parameters:

Name Type Description Default
max_steps int

Maximum number of optimisation steps. Defaults to 100.

100
method str

'gd', 'adam', 'nr-trm' (default) or 'nr-rfo'.

'nr-trm'
**optimizer_kwargs float

Method hyperparameters — learning_rate for 'gd'/'adam', delta for 'nr-trm', kappa for 'nr-rfo'.

required

Returns:

Type Description
Parameters

The bound Parameters instance, carrying the final

Parameters

parameters (current array) and fidelity (scalar). The full

Parameters

trajectory and best_* live on grape.history when a

Parameters

History was supplied.