SequenceDesign#
- class torchsim.SequenceDesign(cost, **parameters)[source]#
Bases:
ModuleA cost, the parameters it is minimized over, and the limits on them.
- Parameters:
cost (callable) – Called with the designed parameters by keyword, returning one number. Everything sequence-specific lives here: what is simulated, what is measured about it, and what is penalized.
parameters (Bounded or torch.Tensor, optional) – One entry per designed parameter. A
Boundedcarries its own limits; a bare array is left free.
Examples
design = SequenceDesign( sharpness, flip=Bounded(torch.full((8, 120), 120.0), 20.0, 180.0) ) result = design.minimize(iterations=120)
Notes
A feasibility term the scanner would merely prefer belongs in the cost, where it trades against everything else. A limit the scanner cannot exceed belongs in
Bounded, where no iterate can cross it.Methods
Run the design to
iterationssteps.The designed parameters as the cost sees them, inside their limits.
- minimize(*, iterations=200, learning_rate=0.05, optimizer_factory=None, callback=None)[source]#
Run the design to
iterationssteps.- Parameters:
iterations (int, optional) – How many updates to take.
learning_rate (float, optional) – Adam step size, used when
optimizer_factoryis omitted.optimizer_factory (callable, optional) – Called with the unconstrained variables, returning the optimizer to drive them.
callback (callable, optional) – Called after each update with the step number, the parameters and the loss, both detached. Returning
Truestops early.
- Returns:
The parameters as they finished, and the loss at every step.
- Return type:
SequenceOptimization