geope.grape¤
geope.grape.Grape
¤
Gradient/Hessian-based GRAPE optimiser for quantum gate synthesis.
Mirrors the Geope usage pattern in every respect: it is constructed from a
Parameters object (the single source of truth for all configuration and the
live optimisation state), while the update rule and max_steps are
arguments of :meth:optimize; and it builds one GeometricContext per
step inside a single jitted update_step.
Where Geope walks the geodesic toward the target, Grape walks the
infidelity's own gradient. The step is therefore assembled from the context's
cost tier — value_and_grad, and cost_hessian for the Newton rules —
and never from point, jacobian or A. Because every context
quantity is lazy, that is the whole reason a GRAPE run traces no matrix
logarithm and never builds the Jacobian; see geope.optimizers for the rule
an update rule has to obey to keep it that way.
Attributes:
| Name | Type | Description |
|---|---|---|
params |
The bound |
|
precision |
Target fidelity threshold. |
|
optimizer |
The active |
|
optimizer_state |
The current optimiser state pytree (re- |
|
method |
The active rule's |
|
step_size |
Transient last accepted step (the optimiser result's
|
|
history |
Optional |
__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
method
property
¤
The active update rule's name, or None before the first run.
__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 |
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 |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
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
|
get_update_step()
¤
Build the JIT-compiled GRAPE update step.
One jitted function per update rule, and one
geope.geometry.GeometricContext per call of it. The step is: open the
context, let the rule read the cost tier off it and choose a descent
direction and a (positive) step, then move.
The context is built inside this function and never leaves it — it is a trace-time object, not a pytree. Everything the rule needs it reads off that one context, and everything it does not read costs nothing, which is why no matrix logarithm and no Jacobian is traced here.
Returns:
| Type | Description |
|---|---|
Callable[..., tuple]
|
A JIT-compiled callable |
Callable[..., tuple]
|
returning |
Callable[..., tuple]
|
where |
Callable[..., tuple]
|
|
optimize(max_steps=100, optimizer=None, callbacks=None)
¤
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
|
optimizer
|
Optimizer | None
|
The |
None
|
callbacks
|
Callable | list[Callable] | tuple[Callable, ...] | None
|
Optional callback, or list/tuple of callbacks, invoked at
the end of every step with the signature
|
None
|
Returns:
| Type | Description |
|---|---|
Parameters
|
The bound |
Parameters
|
|
Parameters
|
describe the same pulse, since the reported infidelity is measured |
Parameters
|
at the step just taken. The full trajectory and |
Parameters
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |