2020-10-09 15:55:37 +02:00
|
|
|
{
|
|
|
|
stdenv
|
|
|
|
, config
|
|
|
|
, stages
|
|
|
|
, targetMachine
|
|
|
|
, garlicTools
|
2020-11-17 10:49:45 +01:00
|
|
|
, bsc
|
2020-12-10 15:41:49 +01:00
|
|
|
, writeTextFile
|
|
|
|
, runCommandLocal
|
|
|
|
, python
|
2021-02-03 12:37:54 +01:00
|
|
|
, pp
|
2020-10-09 15:55:37 +02:00
|
|
|
}:
|
|
|
|
|
|
|
|
with stdenv.lib;
|
|
|
|
with garlicTools;
|
|
|
|
|
|
|
|
let
|
|
|
|
machineConf = targetMachine.config;
|
|
|
|
in
|
|
|
|
rec {
|
|
|
|
/* Takes a list of units and builds an experiment, after executing the
|
2020-10-13 13:00:59 +02:00
|
|
|
trebuchet, runexp and isolate stages. Returns the trebuchet stage. */
|
2021-02-03 12:37:54 +01:00
|
|
|
buildTrebuchet = units:
|
|
|
|
let
|
|
|
|
trebuchet = stages.trebuchet {
|
|
|
|
inherit (machineConf) nixPrefix sshHost;
|
|
|
|
nextStage = stages.runexp {
|
2020-10-13 13:00:59 +02:00
|
|
|
inherit (machineConf) nixPrefix;
|
2021-02-03 12:37:54 +01:00
|
|
|
nextStage = stages.isolate {
|
|
|
|
inherit (machineConf) nixPrefix;
|
|
|
|
nextStage = stages.experiment {
|
|
|
|
inherit units;
|
|
|
|
};
|
2020-10-13 13:00:59 +02:00
|
|
|
};
|
2020-10-09 15:55:37 +02:00
|
|
|
};
|
|
|
|
};
|
2021-02-03 12:37:54 +01:00
|
|
|
in trebuchet // rec {
|
2021-02-24 19:45:47 +01:00
|
|
|
result = pp.store {
|
|
|
|
trebuchet=trebuchet;
|
|
|
|
experiment=trebuchet.experiment;
|
|
|
|
};
|
2021-02-03 12:37:54 +01:00
|
|
|
timetable = pp.timetable result;
|
2020-10-09 15:55:37 +02:00
|
|
|
};
|
|
|
|
|
2020-10-09 19:33:06 +02:00
|
|
|
/* Given an attrset of lists `varConf` and a function `genConf` that accepts a
|
|
|
|
attrset, computes the cartesian product of all combinations of `varConf` calls
|
|
|
|
genConf to produce the final list of configurations. */
|
|
|
|
buildConfigs = {varConf, genConf}:
|
|
|
|
map (c: genConf c) (genConfigs varConf);
|
2020-10-09 15:55:37 +02:00
|
|
|
|
2020-10-09 19:33:06 +02:00
|
|
|
stdStages = {
|
|
|
|
sbatch = {nextStage, conf, ...}: with conf; stages.sbatch (
|
|
|
|
# Allow a user to define a custom reservation for the job in MareNostrum4,
|
|
|
|
# by setting the garlic.sbatch.reservation attribute in the
|
|
|
|
# ~/.config/nixpkgs/config.nix file. If the attribute is not set, no
|
|
|
|
# reservation is used. The user reservation may be overwritten by the
|
|
|
|
# experiment, if the reservation is set like with nodes or ntasksPerNode.
|
|
|
|
optionalAttrs (config ? garlic.sbatch.reservation) {
|
|
|
|
inherit (config.garlic.sbatch) reservation;
|
2020-11-13 10:17:54 +01:00
|
|
|
} //
|
|
|
|
# However, if the experiment contains a reservation, that takes priority
|
2020-11-13 19:08:10 +01:00
|
|
|
# over the one set in the ~/.config/nixpkgs/config.nix file. Add other
|
|
|
|
# options if they are defined as well.
|
|
|
|
optionalInherit [ "reservation" "time" "qos" ] conf //
|
2020-11-13 10:17:54 +01:00
|
|
|
# Finally, add all the other required parameters
|
|
|
|
{
|
2020-11-13 19:08:10 +01:00
|
|
|
inherit nextStage nixPrefix;
|
|
|
|
# These sbatch options are mandatory
|
|
|
|
inherit cpusPerTask ntasksPerNode nodes jobName;
|
2020-10-09 19:33:06 +02:00
|
|
|
exclusive = true;
|
|
|
|
}
|
|
|
|
);
|
2020-10-09 15:55:37 +02:00
|
|
|
|
2020-10-09 19:33:06 +02:00
|
|
|
control = {nextStage, conf, ...}: stages.control {
|
|
|
|
inherit (conf) loops;
|
|
|
|
inherit nextStage;
|
|
|
|
};
|
2020-10-09 15:55:37 +02:00
|
|
|
|
2021-04-12 17:41:59 +02:00
|
|
|
srun = {nextStage, conf, preSrun ? "", postSrun ? "", ...}: (
|
2020-11-13 19:08:10 +01:00
|
|
|
assert (assertMsg (!(conf ? cpuBind))
|
|
|
|
"cpuBind is no longer available in the standard srun stage");
|
|
|
|
stages.srun {
|
|
|
|
inherit (conf) nixPrefix;
|
2021-04-12 17:41:59 +02:00
|
|
|
inherit nextStage preSrun postSrun;
|
2020-11-13 19:08:10 +01:00
|
|
|
|
|
|
|
# Binding is set to cores always
|
|
|
|
cpuBind = "cores,verbose";
|
|
|
|
}
|
|
|
|
);
|
2020-10-09 15:55:37 +02:00
|
|
|
|
2020-11-20 15:30:47 +01:00
|
|
|
isolate = {nextStage, conf, ...}: stages.isolate (
|
|
|
|
(
|
|
|
|
if (conf ? extraMounts) then { inherit (conf) extraMounts; }
|
|
|
|
else {}
|
|
|
|
) //
|
|
|
|
{
|
2021-01-14 12:25:32 +01:00
|
|
|
inherit (conf) nixPrefix clusterName;
|
2020-11-20 15:30:47 +01:00
|
|
|
inherit nextStage;
|
|
|
|
}
|
|
|
|
);
|
2021-04-06 15:23:26 +02:00
|
|
|
|
|
|
|
baywatch = {nextStage, ...}: stages.baywatch {
|
|
|
|
inherit nextStage;
|
|
|
|
};
|
2020-10-09 15:55:37 +02:00
|
|
|
};
|
|
|
|
|
2020-10-09 19:33:06 +02:00
|
|
|
stdPipelineOverride = {overrides ? {}}:
|
|
|
|
let
|
|
|
|
stages = stdStages // overrides;
|
|
|
|
in
|
2021-04-06 15:23:26 +02:00
|
|
|
with stages; [ sbatch isolate control srun isolate baywatch ];
|
2020-10-09 19:33:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
stdPipeline = stdPipelineOverride {};
|
2020-10-09 15:55:37 +02:00
|
|
|
|
2020-11-17 10:49:45 +01:00
|
|
|
replaceMpi = customMpi: bsc.extend (self: super: {
|
|
|
|
mpi = customMpi;
|
2020-10-09 17:19:00 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
# Generate the experimental units
|
|
|
|
genUnits = {configs, pipeline}: map (c: stages.unit {
|
|
|
|
conf = c;
|
|
|
|
stages = pipeline;
|
|
|
|
}) configs;
|
|
|
|
|
|
|
|
# Generate the complete experiment
|
|
|
|
genExperiment = {configs, pipeline}:
|
|
|
|
let
|
|
|
|
units = genUnits { inherit configs pipeline; };
|
|
|
|
in
|
|
|
|
buildTrebuchet units;
|
2020-12-10 15:41:49 +01:00
|
|
|
|
|
|
|
# Runs a python script and the standard output is directly imported as
|
|
|
|
# nix code
|
|
|
|
printPython = code:
|
|
|
|
let
|
|
|
|
p = writeTextFile {
|
|
|
|
name = "python-script";
|
|
|
|
text = ''
|
|
|
|
from math import *
|
|
|
|
${code}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
import (runCommandLocal "a" { buildInputs = [ python ]; } ''
|
|
|
|
python ${p} > $out'');
|
2020-10-09 15:55:37 +02:00
|
|
|
}
|