uclchem.advanced.worker_state#

Snapshot and restore of advanced settings for multiprocessing propagation.

When UCLCHEM runs grid models or managed-mode models, worker processes are spawned via mp.Pool or mp.Process with the spawn context. These fresh processes import uclchemwrap from scratch, losing any runtime modifications made through GeneralSettings, HeatingSettings, or NetworkState.

This module provides create_snapshot() / restore_snapshot() to capture the current Fortran module state into a picklable dict and re-apply it in a worker process before the model runs.

Module Contents#

Functions#

create_snapshot(→ dict[str, Any])

Capture the current Fortran module state into a picklable dict.

restore_snapshot(→ None)

Apply a previously captured snapshot to the current process.

Attributes#

uclchem.advanced.worker_state.create_snapshot() dict[str, Any][source]#

Capture the current Fortran module state into a picklable dict.

Reads directly from Fortran memory (not cached Python values) to ensure accuracy even when settings were modified outside the wrapper classes.

The returned dict has three sections:

  • "general" – scalar settings from all uclchemwrap sub-modules (excluding PARAMETERs, INTERNAL, FILE_PATH, and arrays).

  • "heating" – heating/cooling boolean arrays, scalars, and coolant configuration.

  • "network" – Everything in _NETWORK_ARRAYS_TO_TAKE_SNAPSHOT_OF.

Returns:

Fully picklable dict suitable for passing to restore_snapshot().

Return type:

dict[str, Any]

uclchem.advanced.worker_state.restore_snapshot(snapshot: dict[str, Any]) None[source]#

Apply a previously captured snapshot to the current process.

Must be called before running any model in the worker process.

Parameters:

snapshot (dict[str, Any]) – Dict produced by create_snapshot().

uclchem.advanced.worker_state.logger[source]#