SequenceDesign#

class torchsim.SequenceDesign(cost, **parameters)[source]#

Bases: Module

A 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 Bounded carries 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

minimize

Run the design to iterations steps.

values

The designed parameters as the cost sees them, inside their limits.

values()[source]#

The designed parameters as the cost sees them, inside their limits.

forward()[source]#

Evaluate the cost at the parameters as they stand.

minimize(*, iterations=200, learning_rate=0.05, optimizer_factory=None, callback=None)[source]#

Run the design to iterations steps.

Parameters:
  • iterations (int, optional) – How many updates to take.

  • learning_rate (float, optional) – Adam step size, used when optimizer_factory is 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 True stops early.

Returns:

The parameters as they finished, and the loss at every step.

Return type:

SequenceOptimization