Interfaces (ports)#
from DMDO import Discipline, SubproblemSolver, SolverRequest, SolverOutcome, Executor, RunObserver, IterationRecord
Disciplines#
- class DMDO.Discipline(*args, **kwargs)#
Bases:
ProtocolA disciplinary analysis.
computereceives the analysis inputs keyed by variable name (scalars or arrays) and returns a mapping that contains every output variable of the analysis, keyed by name. Implementations may also exposeinput_names/output_namessequences for validation, but they are not required.Example adapter around a model from another framework (kept in user code, not in DMDO):
class ExternalModelDiscipline: def __init__(self, model, inputs, outputs): self.model, self.input_names, self.output_names = model, inputs, outputs def compute(self, inputs): for name in self.input_names: self.model.set_input(name, inputs[name]) # whatever the framework's API is self.model.evaluate() return {name: self.model.get_output(name) for name in self.output_names}
Subproblem solvers#
- class DMDO.SubproblemSolver#
An optimizer for one subproblem (a protocol; subclass
BaseSolverto implement one).- objective_form#
"vector":request.objective(x)returns[f + penalty, [g1, g2, ...]].
- solve(request)#
Optimize the subproblem described by
request(aSolverRequest) and return aSolverOutcome.
- report_hmin(hmin)#
The constraint violation of a solve in the form recorded by the coordination loop (identity by default).
- class DMDO.SolverRequest(name, objective, constraints, x0, lb, ub, var_names, var_types, var_sets, constants, constants_names, budget, budget_scale, seed, iteration, tol=1e-12, display=False, post_dir=None, config=None, warm_start=<factory>)#
Bases:
objectEverything a solver needs to optimize one subproblem.
objective(x, *args)evaluates the augmented subproblem atx. Its return value has the form the solver declared viaSubproblemSolver.objective_form:"vector"->[f + penalty, constraints],"scalar"-> a single penalized float.constraints(x)returns the inequality constraint values (g <= 0).- Parameters:
name (str)
objective (Callable[[...], Any])
constraints (Callable[[Sequence[float]], List[float]])
x0 (List[Any])
lb (List[Any])
ub (List[Any])
var_names (List[str])
var_types (List[Any])
var_sets (Dict[str, Any] | None)
constants (List[Any])
constants_names (List[str])
budget (int)
budget_scale (float)
seed (int)
iteration (int)
tol (float)
display (bool)
post_dir (str | None)
config (Dict[str, Any] | None)
warm_start (Dict[str, Any])
- class DMDO.SolverOutcome(x, fmin, hmin, raw=None, warm_start=<factory>)#
Bases:
objectResult of one subproblem solve.
- Parameters:
x (List[Any])
fmin (Any)
hmin (Any)
raw (Any)
warm_start (Dict[str, Any])
Executors#
- class DMDO.Executor(*args, **kwargs)#
Bases:
ProtocolRuns independent tasks and returns their results in task order.
The coordination loop hands an executor
DMDO.workflow.execution.SubproblemTaskmessages together with the module-level function that solves one (DMDO.workflow.execution.solve_task()). Local executors call it in this process or in worker processes; a remote executor (an HTTP/gRPC/queue client, a Ray or Dask cluster, …) ships the pickled task to a worker that calls the same function. Whether subproblems see each other’s updates within an outer iteration is decided by the coordination sweep, not by the executor.Register an implementation with
DMDO.registry.executors.register("name", factory)(or via thedmdo.executorsentry-point group); the factory is called asfactory(max_workers=n).
Observers#
- class DMDO.RunObserver#
Hooks called by the coordination loop. Subclass and override the hooks you need; every hook is optional, and any object that defines some of them can be used as an observer.
runis theMDOobject: read its state (run.Coordinator,run.subProblems,run.fmin, …) rather than keeping references to it. Observers are called in the order they are given, after DMDO’s own, and are not pickled into checkpoints.- on_run_start(run)#
Once, before the first outer iteration.
- on_iteration_start(run, iteration)#
Before the subproblems are solved.
- on_resume(run, iteration)#
Instead of
on_iteration_startfor the first iteration of a run resumed from a checkpoint.
- on_sweep_end(run, iteration)#
All subproblems solved and the inconsistencies computed, before the penalty update.
- on_iteration_end(run, record)#
The iteration is final for reporting;
recordis anIterationRecord.
- on_multipliers_updated(run, iteration)#
After the multipliers and penalty weights were updated, before the stopping test.
- on_run_end(run)#
Once, after the last outer iteration (not called when the run raises).
- class DMDO.IterationRecord(iteration, objective, max_inconsistency, max_penalty_weight, variables_change, worst_link)#
Bases:
objectSummary of one finished outer iteration, passed to
RunObserver.on_iteration_end().- Parameters:
iteration (int)
objective (Any)
max_inconsistency (float)
max_penalty_weight (float)
variables_change (float)
worst_link (int)