Setup services and validation

RS-utils keeps the numerical Fortran setup kernel behind a small, path-explicit Python service. rsutil.setup_service.SetupService stages inputs, invokes rsutil.setup_runner.FortranSetupRunner in an isolated worker, validates generated namelists and outputs, and commits results atomically. The caller’s working directory is not changed.

The compatibility function rsutil.process_lattice() remains available for historical in-process use. It is unsafe for HT orchestration because the legacy Fortran call graph can terminate the Python interpreter; use SetupService/run_setup for batch and campaign work.

Setup features

SetupSpec and the CLI support:

  • periodic or free clusters and optional empty spheres;

  • supercell generation and seeded all-site SQS assignment;

  • reproducible lattice/basis Gaussian distortions and alat scaling;

  • 2D slab geometry with fixed or density-aware z margins;

  • block, chebyshev, and lanczos recursion controls;

  • lmx values from 0 through 3 in the current backend;

  • validation reports, output summaries, backups, and explicit in-place commit.

Typical service use

from rsutil.core import SetupSpec
from rsutil.setup import run_setup

result = run_setup(
    "source-run",
    "prepared-run",
    SetupSpec(supercell=(2, 2, 2), seed=1234),
)
if not result.success:
    for diagnostic in result.diagnostics:
        print(diagnostic.code, diagnostic.message)

The setup manifest records input/output hashes, normalized parameters, structure identity, software/environment metadata, timestamps, and stochastic provenance. It is an evidence record and should be retained with a run.

Validation API

The validation functions separate source namelist validation from generated output validation. Reports can be written and read as JSON-compatible objects, making them suitable for campaign status and collection.

Process-isolated adapter for the legacy Fortran setup kernel.

class rsutil.setup_runner.FortranSetupRunner(*, python_executable: str | PathLike[str] | None = None, timeout: float | None = None, workspace_parent: str | PathLike[str] | None = None, keep_workspace: bool = False, environment: Mapping[str, str] | None = None)

Bases: object

Run the existing setup call in a child process and isolated CWD.

lattice_path and input_path are copied into the workspace under the fixed names expected by Fortran. By default the workspace is removed after the call; pass workspace=... when a caller needs to inspect or commit candidate files itself. A caller-provided workspace is never removed by this class.

run(lattice_path: str | PathLike[str] = 'lattice.nml', input_path: str | PathLike[str] = 'input.nml', spec: SetupSpec | Mapping[str, Any] | None = None, *, workspace: str | PathLike[str] | None = None, resources: Iterable[str | PathLike[str]] = (), timeout: float | None = None) → SetupResult

Execute setup and return structured worker/output diagnostics.

resources is an explicit extension point for future legacy resources. The inspected setup call graph currently needs only the two namelists; resource files are staged by basename and never found implicitly by scanning the source directory.

Semantic setup validation and versioned provenance reports.

The validator deliberately works on the namelists rather than on console output. It is conservative about legacy inputs: fields that the Fortran kernel supplies by default remain optional, while contradictions in fields that are present are reported as coded diagnostics.

rsutil.setup_validation.build_run_manifest(lattice_path: str | Path, input_path: str | Path, spec: SetupSpec | Mapping[str, Any] | None, *, status: OperationStatus | str, validation: ValidationResult | None = None, output_paths: Mapping[str, str | Path] | None = None, started_at: str | None = None, finished_at: str | None = None, base_provenance: Mapping[str, Any] | None = None) → RunManifest

Build a deterministic-identity manifest for setup inputs and outputs.

rsutil.setup_validation.read_setup_report(path: str | Path) → SetupReport

Read a versioned report into the typed report model.

rsutil.setup_validation.setup_report(result: SetupResult, manifest: RunManifest | None = None) → SetupReport

Wrap a setup result in the versioned report envelope.

rsutil.setup_validation.validate_setup(lattice_path: str | Path, input_path: str | Path, *, spec: SetupSpec | Mapping[str, Any] | None = None, generated: bool = False) → ValidationResult

Validate setup namelists and return coded semantic diagnostics.

rsutil.setup_validation.validate_setup_namelists(lattice_path: str | Path, input_path: str | Path, *, spec: SetupSpec | Mapping[str, Any] | None = None, generated: bool = False) → ValidationResult

Validate setup namelists and return coded semantic diagnostics.

rsutil.setup_validation.validate_setup_outputs(output_dir: str | Path, *, lattice_path: str | Path | None = None, input_path: str | Path | None = None, spec: SetupSpec | Mapping[str, Any] | None = None, check_supercell_expansion: bool = False) → ValidationResult

Validate generated setup files, including sphere/radius evidence.

rsutil.setup_validation.write_setup_report(report: SetupReport | SetupResult, path: str | Path) → Path

Serialize a report deterministically enough for machine consumption.