← Về thư mục
📄 / / profiles / r-and-d / raw_evidence / scientific-agent-skills / skills / fluidsim / references / simulation_workflow.md

Bounded simulation, pilot, and restart workflow

1. Define the scientific contract

Before code, record:

Do not proceed from a prompt that only says “simulate turbulence” or supplies a Reynolds number without its definition and scaling.

2. Declare operational bounds

Every plan must explicitly bound:

The bundled JSON schema requires these fields. Start from:

python3 scripts/solver_config_validator.py --example

Save the reviewed JSON locally, then:

python3 scripts/solver_config_validator.py --config config.json
python3 scripts/grid_resource_estimator.py --config config.json
python3 scripts/simulation_dry_run.py --config config.json --output run.py

The generator does not import FluidSim or run anything. The generated script prints a JSON dry run by default. Execution requires both --execute and the exact reviewed config ID. An MPI plan is only a command preview; the tool never invokes a launcher or scheduler.

3. Verify the locked environment

In an isolated exact environment:

from importlib.metadata import version
from fluidfft import get_methods

assert version("fluidsim") == "0.9.0"
assert version("fluidfft") == "0.4.5"
print(sorted(get_methods()))

Record the actual FFT methods. A documented method that is absent from get_methods() is not installed. Importing a package is not enough: construct the selected solver's defaults.

4. Tiny no-output serial smoke

After approval, use a trivial, bounded state:

from fluidsim.solvers.ns2d.solver import Simul

params = Simul.create_default_params()
params.oper.nx = params.oper.ny = 8
params.oper.Lx = params.oper.Ly = 2.0
params.oper.coef_dealiasing = 2 / 3
params.time_stepping.USE_CFL = False
params.time_stepping.deltat0 = 0.001
params.time_stepping.deltat_max = 0.001
params.time_stepping.t_end = 0.001
params.time_stepping.max_elapsed = "00:01:00"
params.init_fields.type = "constant"
params.init_fields.constant.value = 0.0
params.output.HAS_TO_SAVE = False
params.output.ONLINE_PLOT_OK = False

sim = Simul(params)
sim.time_stepping.start()

This checks import, FFT construction, initialization, and one bounded step. It does not test the intended physics, forcing, conservation, convergence, performance, output, or restart.

5. Tiny output/restart smoke

Use a dedicated empty output root under a quota. Keep:

Inspect before analysis:

python3 scripts/output_inventory.py --path fluidsim-runs
python3 scripts/budget_summary.py --path fluidsim-runs

Confirm exact filenames and growth. FluidSim 0.9 defaults to state_phys_t*.nc for physical states; spectra remain HDF5.

6. Representative scientific pilot

Increase only enough to exercise the intended:

During and after the pilot, check:

A passing pilot permits planning a refinement study; it does not validate a production run.

7. Running a reviewed serial plan

The generated script is deliberately gated:

python3 run.py
python3 run.py --execute --acknowledge-config-id REVIEWED_CONFIG_ID

The first command is dry-run only. The second is a real simulation and must be issued by the user or approved operator after reviewing limits and output destination.

Never silently increase resolution, duration, save frequency, rank count, or wall time after approval.

8. Read-only loading

Use the lightweight loader:

from fluidsim import load_sim_for_plot

sim = load_sim_for_plot(
    "run-directory",
    merge_missing_params=False,
    hide_stdout=True,
)

Official 0.9 source shows that it:

merge_missing_params=True helps load old metadata but does not prove that an old result is scientifically or numerically equivalent under the new version.

9. State-bearing loading

from fluidsim import load_state_phys_file

sim = load_state_phys_file(
    "run-directory",
    t_approx="last",
    modif_save_params=True,
    merge_missing_params=False,
    init_with_initialized_state=True,
    hide_stdout=True,
)

This constructs a full-resolution operator and loads state; it can be expensive. With the default modif_save_params=True, saving and online plotting are disabled. Loading a state object is not the same as approving a restart.

10. Reviewed Python restart

First compare metadata:

python3 scripts/restart_compatibility.py \
  --source state_phys_t001.000.nc \
  --target-config restart-config.json

Then, after approval:

from fluidsim import load_for_restart

params, Simul = load_for_restart(
    "run-directory",
    t_approx="last",
    merge_missing_params=False,
)
params.time_stepping.t_end = 2.0
params.time_stepping.max_elapsed = "00:10:00"
params.NEW_DIR_RESULTS = True

sim = Simul(params)
sim.time_stepping.start()

load_for_restart reads parameters from /info_simul/params, sets init_fields.type = "from_file", points it to the selected state file, and by default sets NEW_DIR_RESULTS = False. Explicitly choose append versus new directory. Never append to an irreplaceable run without a backup and checksum.

Record:

FluidSim 0.9.0 stores “state parameters” in restarting files. FluidSim 0.8.6 fixed incorrect restart of time-correlated forcing; old checkpoints need extra review.

11. Upstream restart CLI

Safe first action:

fluidsim-restart --only-check run-directory --t_end 2.0

Current options include --only-check, --only-init, --new-dir-results, --t_approx, target/additive time or iteration bounds, --merge-missing-params, and --max-elapsed.

Avoid --modify-params with any untrusted or generated text. Official source passes that string to Python code execution. The bundled generator never emits this option.

The CLI does not supply scheduler resource limits. Running it under MPI or a scheduler remains a separate, explicit operational action.

12. Resolution changes

Do not change oper.nx/ny/nz and treat an old state file as directly compatible. FluidSim provides:

fluidsim-modif-resolution run-directory 5/4

This creates a new state at modified resolution. Before use:

Do not run this automatically or on a large state by default.

13. MPI/HPC handoff

After a serial pilot:

  1. Ask the site scheduler for the intended allocation; never submit from this skill.
  2. Verify the pinned MPI/FluidFFT environment inside that allocation.
  3. Run a manually launched tiny two-rank smoke.
  4. Benchmark candidate FFT methods on representative small shapes.
  5. Confirm decomposition compatibility and local array sizes.
  6. Set explicit process/thread affinity.
  7. Set memory/rank, wall time, scratch, output quota, and signal/checkpoint behavior.
  8. Use a short restartable pilot before scale-up.

The 2019 FluidSim/FluidFFT performance results are hardware- and shape-specific. Do not extrapolate their wall times or fastest backend to another cluster.

Failure and interruption handling

Sources (verified 2026-07-23)