Execution Environments

A recipe describes what to run; an execution environment decides where. NVIDIA FLARE ships three environments in nvflare.recipe: SimEnv (local simulation), PocEnv (a temporary local deployment), and ProdEnv (a running, provisioned federation). Because they share one interface, moving a job from research to production means changing one line. This page documents each environment's parameters, lifecycle, workspace handling, and caveats.

Choosing an Environment

SimEnv PocEnv ProdEnv
Processes Simulator runs server and clients locally Real server and client processes on this machine Your existing deployment
Provisioning None Automatic, fresh per run Done beforehand (nvflare provision or distributed provisioning)
Certificates / authorization No Yes (generated) Yes
Scripts must exist locally Yes Yes No (missing scripts only produce a warning; they are assumed pre-installed)
abort supported No Yes Yes
Typical use Develop and debug Validate deployment behavior Real collaborations

A common job.py pattern selects the environment from an argument:

from nvflare.recipe import PocEnv, ProdEnv, SimEnv

def make_env(args):
    if args.env == "sim":
        return SimEnv(num_clients=args.n_clients)
    if args.env == "poc":
        return PocEnv(num_clients=args.n_clients)
    return ProdEnv(startup_kit_location=args.startup_kit, username=args.username)

run = recipe.execute(make_env(args))
result = run.get_result(clean_up=args.env != "poc")

This is the approach taken by the repository's hello-pt-environments example.

SimEnv

SimEnv(
    *,
    num_clients=0,
    clients=None,
    num_threads=None,
    gpu_config=None,
    log_config=None,
    workspace_root="/tmp/nvflare/simulation",
    extra=None,
    reprod=False,
    plan=None,
)
Parameter Default Description
num_clients 0 Number of simulated clients, named site-1 ... site-N.
clients None Explicit client names. If both are given, the counts must match.
num_threads number of clients How many clients run in parallel.
gpu_config None GPU assignment string for simulated clients (comma-separated device IDs).
log_config None Log mode (concise, progress, msg_only, full, verbose), level name or number, JSON dictConfig string, or path to a JSON file.
workspace_root /tmp/nvflare/simulation Parent folder; each run uses <workspace_root>/<job name>.
reprod / plan False / None Controlled, reproducible simulation driven by a JSON plan (dict or file path). Each requires the other.

Validation errors:

  • Neither num_clients > 0 nor a non-empty clients list: Either 'num_clients' must be > 0 or 'clients' list must be provided. Cannot run simulation with no clients.
  • Mismatch: Inconsistent number of clients: num_clients=3 but clients list has 2 entries.
  • reprod=True without a plan (or vice versa): reprod=True requires plan, and plan requires reprod=True.
  • A referenced script missing locally: The following scripts do not exist locally: [...]. For SimEnv, all scripts must be present on the local machine.

Workspace and environment variable

The environment variable NVFLARE_SIMULATOR_WORKSPACE_ROOT, when set, overrides workspace_root and emits a RuntimeWarning naming both values. Unset it to use the constructor value.

Log configuration precedence

The effective log setting is, from highest priority: --log_config on the job.py command line, then the log_config argument, then the FL_LOG_LEVEL environment variable. An invalid value given on the command line or through FL_LOG_LEVEL produces a usage error; an invalid constructor argument raises ValueError.

Failure behavior

SimEnv runs synchronously. If the simulation fails, execute() raises RuntimeError: Simulation failed with return code ... with a summary and the path to per-site logs (for example server/log.txt and server/error_log.txt). abort_job() only prints abort is not supported in a simulation environment, it will always run to completion. The simulator also installs a default component class allow-list into the workspace's local/resources.json.default unless one is already defined.

PocEnv

PocEnv(
    *,
    num_clients=2,
    clients=None,
    gpu_ids=None,
    use_he=False,
    docker_image=None,
    project_conf_path="",
    username="[email protected]",
    study="default",
    extra=None,
)
Parameter Default Description
num_clients 2 Number of clients (site-1 ...). Must be > 0 when clients is not given.
clients None Explicit names; must be non-empty, and must match num_clients if both are set.
gpu_ids None GPU IDs for clients; CPU only when empty.
use_he False Provision with homomorphic-encryption support.
docker_image None Run the POC services in Docker with this image.
project_conf_path "" A custom project.yml; when set, client count, names, and Docker options are ignored.
username [email protected] Admin identity used to submit the job.
study "default" Study to submit into.
extra None Extra properties; login_timeout (default 10) controls the admin login timeout.

Lifecycle

  1. On construction, PocEnv computes a new, unique workspace beside the configured CLI POC workspace: <poc workspace>.recipe-<32 hex characters>, for example /tmp/nvflare/poc.recipe-3f2a.... It never reuses or overwrites the workspace used by nvflare poc.
  2. deploy() refuses to start if the CLI POC system is running (Stop it with 'nvflare poc stop' before starting a Recipe PocEnv deployment.), checks ports, provisions, starts the server and clients, waits for readiness, and submits the job.
  3. Run.get_result() waits for the job, downloads the result, and stops the services. With clean_up=True (the default) it then deletes the per-run workspace.

Each PocEnv instance can be deployed once. A second deployment raises This PocEnv has already been used; create a new PocEnv for another deployment. If deployment fails, the per-run workspace is cleaned up automatically.

Warning: The result directory returned by get_result() lives inside the per-run workspace. With the default clean_up=True it is deleted before you can read it. Use run.get_result(clean_up=False) when you need the files, and remove the workspace afterwards.

The POC workspace root itself comes from NVFLARE_POC_WORKSPACE, then the poc.workspace entry in ~/.nvflare/config.json, then /tmp/nvflare/poc.

ProdEnv

ProdEnv(
    startup_kit_location,
    login_timeout=5.0,
    username="[email protected]",
    study="default",
    extra=None,
)
Parameter Default Description
startup_kit_location required Path to the admin user's startup kit. Must exist (startup_kit_location path does not exist: ...).
login_timeout 5.0 Seconds to log in; must be positive.
username [email protected] Admin identity; must match the kit.
study "default" Target study.

ProdEnv submits the job through the FLARE API to an already running system. It does not start or stop anything. Scripts that are not found locally only produce Script '...' not found locally. Assuming it is pre-installed on the production system. A submission failure is raised as RuntimeError: Failed to submit job via Flare API: ....

The study name must pass NVFLARE's name check; otherwise study name '...' contains unsupported characters. is raised.

Writing Your Own Environment

All environments subclass nvflare.recipe.spec.ExecEnv and implement deploy(job) -> job_id, get_job_status(job_id), abort_job(job_id), and get_job_result(job_id, timeout=0.0, outputs_only=False); stop(clean_up=False) is optional. Run passes outputs_only only when it is True and the method accepts it, so environments written before that argument existed keep working.

See Also