schrodinger.application.matsci.mlip.writer module

Asynchronous writers for trajectory and log output.

Provides background-threaded sinks for writing XYZ and log files, one per replica.

Copyright Schrodinger, LLC. All rights reserved.

class schrodinger.application.matsci.mlip.writer.AsyncWriter(sink, max_queue=512, block_when_full=True, put_timeout=None)

Bases: object

Background writer that executes sink.write(payload) on a dedicated thread. It blocks on put() when the queue is full to guarantee no drops. Call finish() to flush remaining tasks.

__init__(sink, max_queue=512, block_when_full=True, put_timeout=None)
Parameters:
  • sink – Object with write(payload) and close() methods

  • max_queue (int) – Max number of pending write tasks

  • block_when_full (bool) – If True, put() will wait until there is space (no drops)

  • put_timeout (float or None) – Timeout in seconds for put(). None means wait indefinitely.

put(payload)

Submit a write task; blocks if the queue is full (no drops).

finish()

Flush all pending tasks before exiting.

class schrodinger.application.matsci.mlip.writer.XYZPerReplicaSink(traj_prefix, symbols, mode='a', flush_every_write=True)

Bases: object

Writes one .xyz file per replica without retaining open file handles.

__init__(traj_prefix, symbols, mode='a', flush_every_write=True)
Parameters:
  • traj_prefix (str) – Prefix for trajectory file paths

  • symbols (list) – Element symbols with shape (M, N)

  • mode (str) – Initial file mode (‘a’ for append, ‘w’ for truncate)

  • flush_every_write (bool) – Whether to flush after each write

write(payload)

Write one trajectory frame for all replicas.

Parameters:

payload (dict) – Must contain ‘r_tensor’ (M, N, 3) array, ‘energy_eV’ (M,) array, and ‘step’ (int).

close()

Complete the sink interface. No file handles are retained.

class schrodinger.application.matsci.mlip.writer.LogPerReplicaSink(log_prefix, replicas, mode='a', flush_every_write=True)

Bases: object

Writes one .log file per replica without retaining open file handles.

__init__(log_prefix, replicas, mode='a', flush_every_write=True)
Parameters:
  • log_prefix (str) – Prefix for log file paths

  • replicas (int) – Number of replicas (M)

  • mode (str) – Initial file mode (‘a’ for append, ‘w’ for truncate)

  • flush_every_write (bool) – Whether to flush after each write

write(payload)

Write log data for all replicas at the current step.

Parameters:

payload (dict) – Must contain ‘step’ (int) and ‘batch_log’ (dict of arrays)

close()

Complete the sink interface. No file handles are retained.