Sessions and problem building#

from DMDO import Session, RunResult, load_setup, build_mdo, main

Session#

class DMDO.Session(mdo, *, mode='serial', sweep=None, executor=None, max_workers=None, observers=(), resume=False, file=None)#

Bases: object

Build and drive one DMDO coordination run.

Parameters:
  • mdo (MDO) – the problem (built with from_yaml(), from_dict(), from_checkpoint() or by hand).

  • mode (str) – "serial" (Gauss-Seidel, in-process) or "parallel" (Jacobi, process pool) defaults.

  • sweep (str | None) – "gauss_seidel" or "jacobi", overriding mode.

  • executor (Any) – executor used by run() and step() (an Executor or a registered name); not used by ask/tell.

  • max_workers (int | None) – worker count for executors created from a name.

  • observers (Iterable[Any]) – extra RunObserver objects.

  • resume (bool) – continue a checkpointed run (see from_checkpoint()).

  • file (str | None)

classmethod from_dict(data, *, working_dir='.', mdo_name='MDO', blackboxes=None, **options)#

Build from a problem definition dictionary (the content of a DMDO YAML file).

blackboxes maps the blackbox:/opt: names of the definition to callables or Discipline objects (names can also come from DMDO.register_blackbox() or be "module:attr" import paths). Outputs go to <working_dir>/<mdo_name>_post.

Parameters:
  • data (Mapping[str, Any])

  • working_dir (str)

  • mdo_name (str)

  • blackboxes (Mapping[str, Any] | None)

Return type:

Session

classmethod from_yaml(setup_file, *, working_dir='.', mdo_name=None, blackboxes=None, **options)#

Build from a DMDO YAML (or JSON) problem file; mdo_name defaults to the file name.

Parameters:
  • setup_file (str)

  • working_dir (str)

  • mdo_name (str | None)

  • blackboxes (Mapping[str, Any] | None)

Return type:

Session

classmethod from_checkpoint(checkpoint_file, **options)#

Resume from a coord_chk.pkl checkpoint written by a previous run.

Parameters:

checkpoint_file (str)

Return type:

Session

property iteration: int#

Number of completed outer iterations (including those before a resumed checkpoint).

request_stop()#

End the run after the current outer iteration (thread-safe).

Return type:

None

ask()#

The subproblem tasks to solve next ([] once the run is over).

Tasks of one batch are independent (Jacobi: every subproblem; Gauss-Seidel: one subproblem at a time). Calling ask again before tell returns the same batch.

Return type:

List[SubproblemTask]

tell(results)#

Hand back the results of the last ask() batch (any order).

Returns the IterationRecord when these results completed an outer iteration, else None.

Parameters:

results (Sequence[SubproblemResult])

Return type:

IterationRecord | None

step()#

Run one outer iteration with the session’s executor; None when the run is already over.

Return type:

IterationRecord | None

run()#

Run (or continue) to the end of the coordination and return the result.

Return type:

RunResult

result()#

The current outcome (final once done).

Return type:

RunResult

close()#

Stop the run (if still going) and release the executor.

Return type:

None

class DMDO.RunResult(status, stop_reason, iterations, objective, max_inconsistency, feasible, variables, history=<factory>, post_dir=None)#

Bases: object

Outcome of a session: final design, objective, consistency and the per-iteration history.

Parameters:
  • status (str)

  • stop_reason (str)

  • iterations (int)

  • objective (Any)

  • max_inconsistency (float)

  • feasible (bool)

  • variables (Dict[str, Any])

  • history (List[IterationRecord])

  • post_dir (str | None)

exception DMDO.SessionError#

Bases: RuntimeError

A session method was called in a state that does not allow it.

Building problems#

DMDO.load_setup(setup_file, log=None)#

Read a DMDO problem definition (.yaml/.yml/.json) into a dictionary.

Parameters:
  • setup_file (str)

  • log (logger)

Return type:

Dict[str, Any]

DMDO.build_mdo(data, working_dir='.', mdo_name='MDO', blackboxes=None, log=None, post_dir=None)#

Build an MDO from a problem definition dictionary (the content of a DMDO YAML file).

Outputs go to <working_dir>/<mdo_name>_post unless post_dir is given. The problem definition is not modified.

Parameters:
  • data (Dict[str, Any])

  • working_dir (str)

  • mdo_name (str)

  • blackboxes (Dict)

  • log (logger)

  • post_dir (str)

Return type:

MDO

DMDO.main(options)#

Build and run a problem from a YAML file, as in earlier releases. options is a dictionary with the keys setup_file, mdo_name, working_dir, and optionally run_mode ("run" or "build"), exec_mode ("serial" or "parallel"), is_resume with restart_file (resume from a checkpoint), and blackboxes (name -> callable or discipline). Returns the MDO object.

mdo = main({"setup_file": "problem.yaml", "mdo_name": "wing", "working_dir": "runs",
            "blackboxes": {"A1": aero, "A2": structures}})