progress
Progress reporting for the long-running calculations.
Every function here that can take a while -- relax, elastic_tensor,
force_constants, lattice_energy -- takes one argument for it, progress:
None(the default) orFalse: silent;True: print a readable line per event, indented by how deeply it is nested;-
a callable: called with a
Progressfor every event.result = calc.lattice_energy(crystal, progress=True)
def bar(event): if event.depth == 0 and event.total: print(f"{event.index + 1}/{event.total} {event.stage}")
elastic_tensor(crystal, calc, progress=bar)
Events nest. A lattice energy is a crystal relaxation followed by one per
molecule, and each relaxation reports its own steps one level further down, so
a hook that only wants the outline can ignore everything with depth > 0.
Progress
dataclass
One thing that happened.
Attributes:
| Name | Type | Description |
|---|---|---|
task |
str
|
what is running: "relax", "elastic", "force constants", "lattice energy" |
stage |
str
|
which part of it: "crystal", "molecule 1", "voigt 3 +0.01", "atom 0 along [1, 0, 0]", "step" |
index |
int | None
|
position of this stage among |
total |
int | None
|
how many such stages there are, when known. For a relaxation this is the step cap, which the run may well finish under. |
message |
str
|
the line |
depth |
int
|
how deeply nested the task is; zero for the call the user made |
parents |
tuple
|
the |
step |
object
|
the optimiser's |
done |
bool
|
whether this event reports a stage finishing rather than starting |
Source code in chmpy/opt/progress.py
Reporter
dataclass
Where events go, and the context they are nested in.
Built from the user's progress argument with reporter, and handed down
with nested so that the events from an inner calculation say what they
are part of.
Source code in chmpy/opt/progress.py
nested(task, stage)
The reporter for work done inside (task, stage)
print_progress(event, stream=None)
The hook progress=True installs: one indented line per event.
Source code in chmpy/opt/progress.py
reporter(progress)
Turn a progress argument into a Reporter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress
|
None or False for silence, True to print, a callable taking
a |
required |