Skip to content

Add callbacks to the optimisation loop #2

Description

@therooler

Users currently have no way to hook into the running optimisation loop — e.g. to implement early stopping based on a custom criterion, log to an external system, or visualise intermediate pulses.

The History class (history.py) covers post-hoc logging but requires the full run to finish.

Proposed change:
Add an optional callbacks argument to Geope.optimize — a list of callables with the signature:

def cb(step: int, history: History, geope: Geope) -> bool:
    ...  # return False to request early stop

Callbacks are called after each optimisation step (after add_parameters in the main loop, geope.py:615–647). If any callback returns False the loop exits cleanly.

Acceptance criteria:

  • callbacks=[cb] is accepted and called each step.
  • Returning True from a callback terminates the loop early.
  • Default (callbacks=None) preserves current behaviour with zero overhead.
  • At least one test covering early-stop and logging callbacks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions