SequenceDesign#
- class blochsim.optim.SequenceDesign[source]#
Bases:
ModuleA cost, the parameters it is minimized over, and their limits.
- Parameters:
cost (callable) – Called with the designed parameters by keyword, each a tensor inside its limits; returns a one-element tensor, differentiable with respect to them.
**parameters (Bounded or array-like) – One entry per designed parameter, under the keyword the cost reads it by. A
Boundedcarries its limits; a bare array is unbounded. At least one.
- Raises:
ValueError – If no parameter is given, or a lower limit is not below its upper.
Notes
A preference (a soft penalty) belongs in the cost; a hard scanner limit belongs in
Bounded.Examples
design = SequenceDesign( sharpness, flip=Bounded(torch.full((8, 120), 120.0), 20.0, 180.0) ) result = design.minimize(iterations=120)
Methods
Minimize the cost over the designed parameters.
Return the parameters as passed to the cost, inside their limits.
- forward()[source]#
Evaluate the cost at the current parameters.
- Returns:
The cost, one number, attached to the autograd graph.
- Return type:
torch.Tensor
- Raises:
ValueError – If the cost does not return one number.
- minimize()[source]#
Minimize the cost over the designed parameters.
- Parameters:
iterations (int, default=200) – Number of updates, at least 1.
learning_rate (float, default=0.05) – Adam step size on the unconstrained variables, used when
0. (optimizer_factory is None. Above)
optimizer_factory (callable, default=None) – Maps the list of unconstrained variables to a
torch.optim.Optimizer.Noneis Adam.callback (callable, default=None) – Called after each update as
callback(step, parameters, loss)with detached values; returningTruestops early.
- Returns:
Parameters after the last update, inside their limits, and the cost before each update. Early stopping shortens the history.
- Return type:
SequenceOptimization
- Raises:
ValueError – If
iterationsorlearning_rateis not positive.