Skip to main content

Zero-Shot Wing Deployment

This demo shows how to deploy multiple pre-trained control policies simultaneously on the NACA4412 small-wing NEK5000 case using a PettingZoo rollout. Different policies are mapped to spatially distinct subsets of the wing actuators by chordwise position and pressure/suction side, and executed together in a single simulation without any additional training.

Deployment only

This is an evaluation demo. No training is performed. The controllers and template values are illustrative and should not be used to draw physical conclusions about the wing case.

All scripts live in examples/nek/getting_started/6_zeroshot_wing_demo/.

What the demo does

zeroshot_demo_pettingzoo.py:

  1. Loads a base NekEnv via NekEnv.from_hf("NACA4412_3D_Re75000_AOA5", nproc=12) and wraps it with make_pettingzoo_env.
  2. Reads the POLICY_SPECS list from the policy template (default: meta_policy_small_wing_template.py).
  3. Assigns each policy entry to the actuator agents whose chordwise coordinate falls within x_range and whose side matches "SS" (suction side, y > 0) or "PS" (pressure side, y < 0).
  4. Queries each controller every drl_step environment steps; between refreshes the last action is held constant for the assigned actuator group.
  5. Clips all actions to action_bounds before passing them to the environment.
  6. Prints a reward summary table at the end to help compare controller configurations.

Actuator agents not assigned to any policy entry receive a zero action throughout the rollout.

PettingZoo rollout interface

from hydrogym.nek import NekEnv
from hydrogym.nek.pettingzoo_env import make_pettingzoo_env

base_env = NekEnv.from_hf("NACA4412_3D_Re75000_AOA5", nproc=12)
env = make_pettingzoo_env(base_env)

obs_dict, info = env.reset()
actions = {agent: controller(obs_dict[agent]) for agent in env.agents}
obs_dict, rewards_dict, terminations, truncations, infos = env.step(actions)

Example scripts

FilePurpose
zeroshot_demo_pettingzoo.pyMulti-policy rollout demo
meta_policy_small_wing_template.pyTemplate defining ENV_NAME, NPROC, and POLICY_SPECS
run_pettingzoo_docker.shDocker/MPI launcher

Running the demo

The runner script is the recommended entry point — it handles module loading and workspace preparation automatically:

# Default template
./run_pettingzoo_docker.sh

# Specify a root directory containing pre-trained model runs
./run_pettingzoo_docker.sh --policy-root /workspace/legacy_runs

To invoke the Python script directly:

# Default template
mpirun -np 1 python zeroshot_demo_pettingzoo.py : -np 12 nek5000

# Custom template and policy root
mpirun -np 1 python zeroshot_demo_pettingzoo.py \
--policy-template ./meta_policy_small_wing_template.py \
--policy-root /path/to/legacy_runs \
--steps 3000 \
: -np 12 nek5000

Available command-line overrides:

FlagDefaultDescription
--policy-template PATH./meta_policy_small_wing_template.pyPath to the policy template
--env ENV_NAMEFrom template ENV_NAMEOverride the environment name
--nproc NPROCFrom template NPROCNumber of solver processes
--steps NUM_STEPSFrom template NUM_STEPSTotal rollout steps
--policy-root PATHFrom template POLICY_ROOTRoot directory for RL model run folders
--local-dir PATHOptional local fallback for packaged environments
--log-every NReward table print frequency

Policy template format

meta_policy_small_wing_template.py defines the following top-level variables:

VariableTypeDescription
ENV_NAMEstrEnvironment name for NekEnv.from_hf()
NPROCintNumber of NEK5000 solver processes
NUM_STEPSintTotal rollout length
POLICY_ROOTstrDefault root directory for RL model checkpoints
POLICY_SPECSlist[dict]List of policy group definitions

Each entry in POLICY_SPECS supports:

KeyDescription
nameHuman-readable label for the policy group
x_range[x_min, x_max] — chordwise range of assigned actuators
side"SS" (suction side, y > 0) or "PS" (pressure side, y < 0)
algorithm"PPO", "TD3", "DDPG", "BL" (constant max action), or "ZERO"
drl_stepAction refresh interval; actions are held between refreshes
action_bounds[min, max] — clipping applied to controller output
u_tauOptional: friction velocity used to normalise observations before calling the controller
baseline_dudyOptional: baseline velocity gradient for normalisation
agent_run_nameRL only: identifier for the training run folder
policyRL only: checkpoint identifier within the run folder
model_pathRL only: explicit path to the model file (overrides the default convention)

Default RL model path convention

When model_path is not set, the model is resolved from:

<POLICY_ROOT>/<agent_run_name>/logs/<agent_run_name>-<policy>

For overlapping x_range regions, the last-listed policy in POLICY_SPECS takes precedence.