Skip to content

Commit

Permalink
Migrate testing of example notebooks to nix and run them in CI on the…
Browse files Browse the repository at this point in the history
… dedicated GPU box
  • Loading branch information
jake-arkinstall committed Oct 24, 2024
1 parent 61e2fcf commit c070d80
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-with-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ jobs:
- name: Test pytket-cutensornet
# impure is necessary due to nixgl usage (system-dependent cuda)
run: nix run .#tests --impure --accept-flake-config
- name: Test example notebooks
# impure is necessary due to nixgl usage (system-dependent cuda)
run: nix run .#example-tests --impure --accept-flake-config
9 changes: 7 additions & 2 deletions examples/check-examples
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ do
cmp ${name}.ipynb ${name}-gen.ipynb
rm ${name}-gen.ipynb

# Run script:
python python/${name}.py
# run tests are performed in nix, allowing
# us to manage the testing environment in a
# reproducible way.
#
# See /nix-support/pytket-cutensornet.nix,
# in the derivation called
# run-pytket-cutensornet-examples.
done
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
in {
packages = {
default = pkgs.pytket-cutensornet;
cupy = pkgs.cupy';
pytket-cutensornet = pkgs.pytket-cutensornet;
tests = pkgs.run-pytket-cutensornet-tests;
example-tests = pkgs.run-pytket-cutensornet-examples;
};
devShells = {
default = pkgs.mkShell { buildInputs = [ pkgs.pytket-cutensornet ]; };
Expand Down
28 changes: 28 additions & 0 deletions nix-support/pytket-cutensornet.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,32 @@ EOF
export LD_LIBRARY_PATH;
${test-env}/bin/pytest -s ${../tests};
'';
run-pytket-cutensornet-examples = let
example-env = super.python3.withPackages(ps: with ps; [
self.pytket-cutensornet
matplotlib
numpy
networkx
ipython
nbmake
pytest
]);
nixgl-bin = self.lib.getExe self.nixgl.auto.nixGLNvidia;
in super.writeShellScriptBin "run-pytket-cutensornet-examples" ''
HOME=$(mktemp -d);
export HOME;
NIXGL_PATH="$(${nixgl-bin} printenv LD_LIBRARY_PATH)";
WSL_PATH="/usr/lib/wsl/lib";
LD_LIBRARY_PATH="$NIXGL_PATH:$WSL_PATH:$LD_LIBRARY_PATH";
example_dir=${../examples};
set -e;
for name in `cat ''${example_dir}/ci-tested-notebooks.txt`;
do
${example-env}/bin/pytest \
--nbmake \
-p no:cacheprovider \
$example_dir/$name.ipynb;
done;
'';
}

0 comments on commit c070d80

Please sign in to comment.