odatse.util.separateT module#
- class odatse.util.separateT.Entry(step, walker, Tstr, fx, xs)#
Bases:
tupleCreate new instance of Entry(step, walker, Tstr, fx, xs)
- Tstr#
Alias for field number 2
- _asdict()#
Return a new dict which maps field names to their values.
- classmethod _make(iterable)#
Make a new Entry object from a sequence or iterable
- _replace(**kwds)#
Return a new Entry object replacing specified fields with new values
- fx#
Alias for field number 3
- step#
Alias for field number 0
- walker#
Alias for field number 1
- xs#
Alias for field number 4
- odatse.util.separateT._clear_results(results: list[dict[str, list[Entry]]]) None[source]#
Reset all entry lists to empty so the structure can be reused each chunk.
- odatse.util.separateT._compute_temperature_statistics(samples: list[tuple[int, float, ndarray]], thermalization_steps: int, dbeta: float) tuple[float, float, float, float][source]#
Compute statistics for one temperature from a list of MC samples.
- Parameters:
samples (list of (int, float, numpy.ndarray)) – Raw
(step, fx, x)MC samples in the order they were recorded.thermalization_steps (int) – Steps with
step < thermalization_stepsare discarded as thermalisation.dbeta (float) –
1/T_lower - 1/T; pass0.0when there is no lower-temperature neighbour (the thermodynamic-integration contribution is then 0).
- Returns:
fx_mean (float) – Arithmetic mean of f(x) over production samples.
nanif N == 0.fx_error (float) – Standard error of the mean.
nanif N <= 1.dlogZ (float) –
log(Z_lower / Z_this)via log-sum-exp thermodynamic integration.0.0whendbeta == 0.0or N == 0.acceptance (float) – Fraction of steps where x changed.
nanif N == 0.
- odatse.util.separateT._distribute_entries(entries: list[Entry], T2rank: dict[str, int], results: list[dict[str, list[Entry]]]) None[source]#
Append each entry into the destination-rank bucket it belongs to.
- odatse.util.separateT._merge_results(results2: list[dict[str, list[Entry]]]) dict[str, list[Entry]][source]#
Merge per-source dicts received from alltoall into a single dict.
results2[0]is mutated in-place and returned; the caller owns the object (alltoall in mpi4py returns fresh objects, and in the serial path this is the same dict that will be cleared at the start of the next chunk).
- odatse.util.separateT._parse_result_line(line: str, mpirank: int, nwalkers: int) Entry | None[source]#
Parse one line from
result.txtinto anEntry.Returns
Nonefor blank or comment-only lines. The walker field is remapped from a rank-local index to a global index. Tstr, fx, and xs are kept as raw strings to preserve exact values.
- odatse.util.separateT._read_result_T_entries(filepath: Path) list[tuple[int, float, ndarray]][source]#
Read
result_T<idx>.txtand return a list of(step, fx, x)tuples.Comment lines and blank lines are skipped.
- odatse.util.separateT._write_entries_to_file(entries: list[Entry], filepath: Path) None[source]#
Sort entries by step number and append them to filepath.
- odatse.util.separateT.calculate_statistics_from_separated_files(Ts: np.ndarray, output_dir: PathLike, thermalization_steps: int, comm: MPI.Comm | None) None[source]#
Calculate and save statistical quantities (means and errors of f(x) and partition function) from separated files generated by separateT.
This function reads the separated files,
result_T<Tindex>.txtinoutput_dir, generated by separateT. The output file isfx.txtinoutput_dir. The format is described as a header as follows:# $1: 1/T # $2: mean of f(x) # $3: standard error of f(x) # $4: number of replicas [Not used for exchange MC] # $5: log(Z/Z0) # $6: acceptance ratio
- Parameters:
Ts (np.ndarray) – Array of temperature values.
output_dir (PathLike) – Directory to store the output files.
thermalization_steps (int) – Number of steps to discard for thermalization.
comm (MPI.Comm, optional) – MPI communicator for parallel processing.
- odatse.util.separateT.separateT(Ts: np.ndarray, nwalkers: int, output_dir: PathLike, comm: MPI.Comm | None, use_beta: bool, buffer_size: int = 10000) None[source]#
Separates and processes temperature data for the data analysis framework.
Reads each rank’s
result.txt, redistributes entries to the rank that owns their temperature via MPI alltoall, and writes per-temperatureresult_T*.txtfiles. Large files are processed in chunks of buffer_size lines so that memory usage is bounded.- Parameters:
Ts (np.ndarray) – Array of temperature (or beta) values, shared across all ranks.
nwalkers (int) – Number of walkers per MPI rank. Must satisfy
len(Ts) == nwalkers * mpisize.output_dir (PathLike) – Root output directory. Rank r reads from
output_dir/<r>/result.txt.comm (MPI.Comm, optional) – MPI communicator. Pass
Nonefor serial execution.use_beta (bool) – Write
# beta = …headers instead of# T = …whenTrue.buffer_size (int, optional) – Maximum number of lines read per chunk (rounded up to a multiple of nwalkers). Default is 10000.