Second step with snek5000-phill: Snakemake rules#

Initialization of the simulation (recap)#

In the previous tutorial First step with snek5000-phill: setting up a simulation, we saw how to setup a simulation run. Let us do it here in one step.

from phill.solver import Simul

params = Simul.create_default_params()
params.output.sub_directory = "examples_snek/tuto"
params.oper.nx = 6
params.oper.ny = 5
params.oper.nz = 4
params.oper.elem.order = params.oper.elem.order_out = 10

params.oper.nproc_min = 2

params.nek.general.num_steps = 10
params.nek.general.time_stepper = "bdf2"
params.nek.general.write_interval = 10

params.nek.stat.av_step = 3
params.nek.stat.io_step = 10

sim = Simul(params)
path_run: /home/docs/Sim_data/examples_snek/tuto/phill_run_6x5x4_V1.x1.x1._2024-03-03_01-32-53
INFO: session_id: 0
INFO: Writing params files... /home/docs/Sim_data/examples_snek/tuto/phill_run_6x5x4_V1.x1.x1._2024-03-03_01-32-53/phill.par, params_simul.xml, info_solver.xml
INFO: sim:                        <class 'phill.solver.SimulPhill'>
sim.oper:                   <class 'snek5000.operators.Operators'>
sim.output.print_stdout:    <class 'snek5000.output.print_stdout.PrintStdOut'>
sim.output.phys_fields:     <class 'snek5000.output.phys_fields.PhysFields'>
sim.output.history_points:  <class 'snek5000.output.history_points.HistoryPoints'>
sim.output.remaining_clock_time: <class 'snek5000.output.remaining_clock_time.RemainingClockTime'>
sim.output:                 <class 'phill.output.OutputPhill'>
sim.make:                   <class 'snek5000.make.Make'>

INFO: Writing box file... /home/docs/Sim_data/examples_snek/tuto/phill_run_6x5x4_V1.x1.x1._2024-03-03_01-32-53/phill.box
INFO: Writing SIZE file... /home/docs/Sim_data/examples_snek/tuto/phill_run_6x5x4_V1.x1.x1._2024-03-03_01-32-53/SIZE

We recall that this instanciation of the class Simul creates the simulation directory on the disk with the following files:

!ls {sim.path_run}
SIZE		  etc		    map_user_params.json  phill.log  toolbox
Snakefile	  info_solver.xml   params_simul.xml	  phill.par
config_simul.yml  makefile_usr.inc  phill.box		  phill.usr

Execute the simulation with Snakemake rules#

Snakemake rules#

To run the simulation we need to execute certain commands. These are described using snakemake in the Snakefile. Let’s look at the rules defined in the Snakefile (which are nearly generic for any Nek5000 case).

sim.make.list();
all
archive
clean
clean3rd
cleanall
cleansimul
compile
generate_compile_sh
internal_generate_box
internal_generate_makefile
internal_generate_map
internal_generate_session
internal_move_box
mesh
mpiexec
run
run_fg
show_config
source_archive
Changing to shadow directory: /home/docs/Sim_data/examples_snek/tuto/phill_run_6x5x4_V1.x1.x1._2024-03-03_01-32-53
WARNING: Initializing Output class without sim or params might lead to errors.

The rules in the Snakefile are either shell commands or Python code which handle different parts of the build step, such as building a mesh (rule mesh), compiling (rule compile) and running the simulation (rule run or run_fg). The rules can be executed on by one by passing them as strings to the exec method of the sim.make object. The default parameter is to do everything to run a simulation.

From a user’s perspective the following rules are essential:

  • compile: Only compile the executable

  • run: Run the simulation in the background (non-blocking)

  • run_fg: Run the simulation in the foreground (blocking, till the simulation is over / terminated)

Hence, the most standard method to launch a simulation with Snek5000 is to call

sim.make.exec("run_fg", nproc=2)

In the next tutorial Demo periodic hill (snek5000-phill solver): running a simulation from a script, we will do it from a script and see what happens, but we can already guess that all the Snakemake rules necessary for the simulation are going to be executed.

Note

In real life, simulations are usually submitted with Snek5000 from a script and we are going to call Snakemake with the exec method.

However, there is also a command snek-make that can be run from the simulation directory to list and invoke the Snakemake rules. See snek-make -h and snek-make -l.

Debug mode#

During development, it can be useful to turn on the debug environment variable which can be done in Python with:

import os
os.environ["SNEK_DEBUG"] = "1"

The equivalent of this in the shell command line would be export SNEK_DEBUG=1. By doing so, snek5000 would: