2020-10-09 15:55:37 +02:00
|
|
|
{
|
|
|
|
stdenv
|
|
|
|
, config
|
|
|
|
, stages
|
|
|
|
, targetMachine
|
|
|
|
, garlicTools
|
|
|
|
}:
|
|
|
|
|
|
|
|
with stdenv.lib;
|
|
|
|
with garlicTools;
|
|
|
|
|
|
|
|
let
|
|
|
|
machineConf = targetMachine.config;
|
|
|
|
in
|
|
|
|
rec {
|
|
|
|
/* Takes a list of units and builds an experiment, after executing the
|
|
|
|
trebuchet and the isolate stages. Returns the trebuchet stage. */
|
2020-10-09 17:19:00 +02:00
|
|
|
buildTrebuchet = units: stages.trebuchet {
|
2020-10-09 15:55:37 +02:00
|
|
|
inherit (machineConf) nixPrefix;
|
2020-10-09 16:13:16 +02:00
|
|
|
nextStage = stages.isolate {
|
2020-10-09 15:55:37 +02:00
|
|
|
inherit (machineConf) nixPrefix;
|
2020-10-09 16:13:16 +02:00
|
|
|
nextStage = stages.experiment {
|
2020-10-09 15:55:37 +02:00
|
|
|
inherit units;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
} // {
|
|
|
|
exclusive = true;
|
|
|
|
inherit nextStage nixPrefix nodes ntasksPerNode time qos jobName;
|
|
|
|
}
|
|
|
|
);
|
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
|
|
|
|
2020-10-09 19:33:06 +02:00
|
|
|
srun = {nextStage, conf, ...}: stages.srun {
|
|
|
|
inherit (conf) nixPrefix cpuBind;
|
|
|
|
inherit nextStage;
|
|
|
|
};
|
2020-10-09 15:55:37 +02:00
|
|
|
|
2020-10-09 19:33:06 +02:00
|
|
|
isolate = {nextStage, conf, ...}: stages.isolate {
|
|
|
|
clusterName = machineConf.name;
|
|
|
|
inherit (conf) nixPrefix;
|
|
|
|
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
|
|
|
|
with stages; [ sbatch isolate control srun isolate ];
|
|
|
|
|
|
|
|
|
|
|
|
stdPipeline = stdPipelineOverride {};
|
2020-10-09 15:55:37 +02:00
|
|
|
|
|
|
|
# FIXME: Remove this hack and allow custom nixpkgs
|
2020-10-09 16:13:16 +02:00
|
|
|
bscOverlay = import ../overlay.nix;
|
2020-10-09 15:55:37 +02:00
|
|
|
nixpkgs = import <nixpkgs>;
|
|
|
|
genPkgs = newOverlay: nixpkgs {
|
|
|
|
overlays = [
|
|
|
|
bscOverlay
|
|
|
|
newOverlay
|
|
|
|
];
|
|
|
|
};
|
2020-10-09 17:19:00 +02:00
|
|
|
|
|
|
|
replaceMpi = mpi: genPkgs (self: super: {
|
|
|
|
bsc = super.bsc // { inherit mpi; };
|
|
|
|
});
|
|
|
|
|
|
|
|
# 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-10-09 15:55:37 +02:00
|
|
|
}
|