How to export a standalone source code archive which excludes Snek5000#

Add the following Snakemake rule to your solver’s Snakefile (for example see snek5000-phill):

from phill import short_name, Output

# generate compile.sh
# ===================
rule generate_compile_sh:
    output:
        "compile.sh",
    run:
        from snek5000.resources import get_base_template

        template = get_base_template("compile.sh.j2")
        Output.write_compile_sh(template, config, path=output)


# create a archive with source files
# ==================================
rule source_archive:
    input:
        f"{short_name}.box",
        f"{short_name}.par",
        f"{short_name}.usr",
        "SIZE",
        "compile.sh",
        "makefile_usr.inc",
        *list(Output().makefile_usr_sources),
    output:
        f"{short_name}-source_archive.tar.gz",
    shell:
        """
        tar cvf {output} {input}
        """

Now execute in an IPython console to generate source code from your templates and prescribed parameters.

from phill.solver import Simul

params = Simul.create_default_params()
# modify params if necessary
sim = Simul(params)
Hide code cell output
path_run: /home/docs/Sim_data/phill_run_22x16x19_V1.x1.x1._2024-03-03_01-30-11
building 3rd-party dependencies ... done
~/Nek5000/tools ~/Nek5000
WARNING: Cannot find cmake, which is required by some tools!
WARNING: Cannot find X11, which is required by some tools!
building genmap ... done
~/Nek5000/tools ~/Nek5000
WARNING: Cannot find cmake, which is required by some tools!
WARNING: Cannot find X11, which is required by some tools!
building genbox ... done
INFO: session_id: 0
INFO: Writing params files... /home/docs/Sim_data/phill_run_22x16x19_V1.x1.x1._2024-03-03_01-30-11/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'>

Changing to shadow directory: /home/docs/Nek5000
Building DAG of jobs...
Using shell: /usr/bin/bash
Provided cores: 1 (use --cores to define parallelism)
Rules claiming more threads will be scaled down.
Job stats:
job                  count
-----------------  -------
_tool                    2
build_third_party        1
total                    3

Select jobs to execute...

[Sun Mar  3 01:30:12 2024]
rule build_third_party:
    input: nek5000_make_config.yml, bin/nekconfig
    output: 3rd_party/gslib/lib/libgs.a, 3rd_party/blasLapack/libblasLapack.a
    jobid: 2
    reason: Missing output files: 3rd_party/gslib/lib/libgs.a, 3rd_party/blasLapack/libblasLapack.a
    resources: tmpdir=/tmp

[Sun Mar  3 01:30:20 2024]
Finished job 2.
1 of 3 steps (33%) done
Select jobs to execute...

[Sun Mar  3 01:30:20 2024]
rule _tool:
    input: tools/genmap, nek5000_make_config.yml
    output: bin/genmap
    jobid: 0
    reason: Missing output files: bin/genmap
    wildcards: tool=genmap
    resources: tmpdir=/tmp

[Sun Mar  3 01:30:23 2024]
Finished job 0.
2 of 3 steps (67%) done
Select jobs to execute...

[Sun Mar  3 01:30:23 2024]
rule _tool:
    input: tools/genbox, nek5000_make_config.yml
    output: bin/genbox
    jobid: 1
    reason: Missing output files: bin/genbox
    wildcards: tool=genbox
    resources: tmpdir=/tmp

[Sun Mar  3 01:30:25 2024]
Finished job 1.
3 of 3 steps (100%) done
Complete log: .snakemake/log/2024-03-03T013012.001966.snakemake.log
INFO: Writing box file... /home/docs/Sim_data/phill_run_22x16x19_V1.x1.x1._2024-03-03_01-30-11/phill.box
INFO: Writing SIZE file... /home/docs/Sim_data/phill_run_22x16x19_V1.x1.x1._2024-03-03_01-30-11/SIZE

Finally make the source code archive:

sim.make.exec('source_archive')
Hide code cell output
phill.box
phill.par
phill.usr
SIZE
compile.sh
makefile_usr.inc
toolbox/
toolbox/map2D.f
toolbox/rprm_block.f
toolbox/mntrlog_block.f
toolbox/CHKPTMSTPD
toolbox/README.md
toolbox/mntrtmr_block.f
toolbox/io_tools.f
toolbox/chkpt_mstp.f
toolbox/STATD
toolbox/MAP2D
toolbox/io_tools_block.f
toolbox/mntrtmr.f
toolbox/CHKPOINTD
toolbox/frame.f
toolbox/stat_IO.f
toolbox/math_tools.f
toolbox/chkpoint.f
toolbox/RPRMD
toolbox/FRAMELP
toolbox/stat.f
toolbox/MNTRLOGD
toolbox/IOTOOLD
toolbox/MNTRTMRD
toolbox/rprm.f
toolbox/mntrlog.f
Changing to shadow directory: /home/docs/Sim_data/phill_run_22x16x19_V1.x1.x1._2024-03-03_01-30-11
WARNING: Initializing Output class without sim or params might lead to errors.
Building DAG of jobs...
Using shell: /usr/bin/bash
Provided cores: 1 (use --cores to define parallelism)
Rules claiming more threads will be scaled down.
Job stats:
job                    count
-------------------  -------
generate_compile_sh        1
source_archive             1
total                      2

Select jobs to execute...

[Sun Mar  3 01:30:25 2024]
rule generate_compile_sh:
    output: compile.sh
    jobid: 1
    reason: Missing output files: compile.sh
    resources: tmpdir=/tmp

WARNING: Initializing Output class without sim or params might lead to errors.
Building DAG of jobs...
Using shell: /usr/bin/bash
Provided cores: 1 (use --cores to define parallelism)
Rules claiming more threads will be scaled down.
Select jobs to execute...
[Sun Mar  3 01:30:26 2024]
Finished job 1.
1 of 2 steps (50%) done
Select jobs to execute...

[Sun Mar  3 01:30:26 2024]
rule source_archive:
    input: phill.box, phill.par, phill.usr, SIZE, compile.sh, makefile_usr.inc, toolbox
    output: phill_source-archive.tar.gz
    jobid: 0
    reason: Missing output files: phill_source-archive.tar.gz; Input files updated by another job: compile.sh
    resources: tmpdir=/tmp

[Sun Mar  3 01:30:26 2024]
Finished job 0.
2 of 2 steps (100%) done
Complete log: .snakemake/log/2024-03-03T013025.338647.snakemake.log
True
%mv {sim.path_run}/phill_source-archive.tar.gz .

This archive may now be shared to your colleagues or kept as a standalone archive which only depends on Nek5000 for compilation.