Writers#
Writers record training statistics at each step. JaQMC ships with console, CSV, and HDF5 writers. See Writers for background on output files and customizing console output.
Configuration#
For writer config keys, see the configuration reference: Molecule, Solid, or Hall.
Base class#
- class jaqmc.writer.base.Writer[source]#
Base class for statistics writers.
Note
Do all I/O setup (file creation, opening handles) in the
opencontext manager, not in__init__. In distributed runs, multiple processes may share the same filesystem, and side effects in__init__can cause resource conflicts.- open(working_dir, stage_name, initial_step=0)[source]#
Context manager for resource handling.
This method manages resource lifecycle and side effects, such as initializing files or other I/O operations.
When restoring from a checkpoint,
initial_stepindicates where training will resume. Writers that persist to files should truncate any data beyond this point so that stale entries from a previous (interrupted) run are discarded.- Parameters:
working_dir (
UPath|Path) – The directory where artifacts should be stored.stage_name (
str) – Name of the current training stage. File-backed writers may use it when resolving their output path template.initial_step (
int, default:0) – The step from which training will resume. Data written for steps >=initial_stepshould be discarded.
- static resolve_path_template(working_dir, path_template, stage_name)[source]#
Resolve a writer path template against the working directory.
The template may contain
{stage}, which is replaced with the current stage name before the path is resolved.- Parameters:
- Return type:
- Returns:
The resolved output path.
- Raises:
ValueError – If
stage_nameis empty or the template uses unsupported fields.
- class jaqmc.writer.base.Writers(writers=())[source]#
A collection of writers with master-process guarding.
Wraps multiple
Writerinstances and ensures thatopenandwriteonly execute on the master process in distributed settings.- open(working_dir, stage_name, *, is_master=True, initial_step=0)[source]#
Open all writers on the master process.
- Parameters:
working_dir (
UPath|Path) – Directory where artifacts should be stored.stage_name (
str) – Name of the current training stage.is_master (
bool, default:True) – Whether this is the master process.initial_step (
int, default:0) – The step from which training will resume. Data written for steps >=initial_stepshould be discarded.
- Yields:
None.
Built-in writers#
- class jaqmc.writer.console.ConsoleWriter(*, interval=1, fields='loss')[source]#
Bases:
WriterWrites statistics to the console via the standard logger.
Each field spec is
[alias=]key[:format]:total_energy— displaytotal_energy=...total_energy:.6f— with explicit formatenergy=total_energy— display asenergy=...Lz=angular_momentum_z:+.4f— alias + format
- Parameters:
- open(working_dir, stage_name, initial_step=0)[source]#
Context manager for resource handling.
This method manages resource lifecycle and side effects, such as initializing files or other I/O operations.
When restoring from a checkpoint,
initial_stepindicates where training will resume. Writers that persist to files should truncate any data beyond this point so that stale entries from a previous (interrupted) run are discarded.- Parameters:
working_dir – The directory where artifacts should be stored.
stage_name – Name of the current training stage. File-backed writers may use it when resolving their output path template.
initial_step (
int, default:0) – The step from which training will resume. Data written for steps >=initial_stepshould be discarded.
- class jaqmc.writer.console.FieldSpec(key, alias=None, fmt=None)[source]#
A single console output field.
- Parameters:
- static parse(spec)[source]#
Parse
[alias=]key[:format].Stat keys may contain colons (e.g.
energy:kinetic). The last:-separated segment is treated as a format specifier only when it contains a digit (e.g..4f,+.4f).- Return type:
- Returns:
The parsed field specification.
Examples
>>> FieldSpec.parse("total_energy:.6f") FieldSpec(key='total_energy', alias=None, fmt='.6f')
>>> FieldSpec.parse("Lz=angular_momentum_z:+.4f") FieldSpec(key='angular_momentum_z', alias='Lz', fmt='+.4f')
Colons in stat keys are preserved (only the last segment is checked for format specifiers):
>>> FieldSpec.parse("energy:kinetic") FieldSpec(key='energy:kinetic', alias=None, fmt=None)
- class jaqmc.writer.csv.CSVWriter(*, path_template='{stage}_stats.csv')[source]#
Bases:
WriterWrites statistics to a CSV file.
Existing files are truncated to
initial_stepdata rows uponopen()before new rows are appended, so resumed runs discard stale rows past the restored checkpoint.- Parameters:
path_template (
str, default:'{stage}_stats.csv') – Output path template. Relative paths are resolved under the working directory. The template may contain{stage}.
- open(working_dir, stage_name, initial_step=0)[source]#
Context manager for resource handling.
This method manages resource lifecycle and side effects, such as initializing files or other I/O operations.
When restoring from a checkpoint,
initial_stepindicates where training will resume. Writers that persist to files should truncate any data beyond this point so that stale entries from a previous (interrupted) run are discarded.- Parameters:
working_dir – The directory where artifacts should be stored.
stage_name – Name of the current training stage. File-backed writers may use it when resolving their output path template.
initial_step (
int, default:0) – The step from which training will resume. Data written for steps >=initial_stepshould be discarded.
- class jaqmc.writer.hdf5.HDF5Writer(*, path_template='{stage}_stats.h5')[source]#
Bases:
WriterWrites statistics to an HDF5 file.
Existing files are truncated to
initial_stepdata rows uponopen()before new rows are appended, so resumed runs discard stale rows past the restored checkpoint.- Parameters:
path_template (
str, default:'{stage}_stats.h5') – Output path template. Relative paths are resolved under the working directory. The template may contain{stage}.
- open(working_dir, stage_name, initial_step=0)[source]#
Context manager for resource handling.
This method manages resource lifecycle and side effects, such as initializing files or other I/O operations.
When restoring from a checkpoint,
initial_stepindicates where training will resume. Writers that persist to files should truncate any data beyond this point so that stale entries from a previous (interrupted) run are discarded.- Parameters:
working_dir – The directory where artifacts should be stored.
stage_name – Name of the current training stage. File-backed writers may use it when resolving their output path template.
initial_step (
int, default:0) – The step from which training will resume. Data written for steps >=initial_stepshould be discarded.