From 41849805377c91aad4816fab7ee5ba554f487f47 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Sun, 11 Aug 2024 14:02:05 -0500 Subject: [PATCH] AP_NavEKF3: derivation: pin generator library versions Document exactly which versions were used when generating the code. Sympy is the most important so it is explicitly checked. Also add an alternate generate script which uses `nix-shell` to make it convenient to automatically use these versions. --- libraries/AP_NavEKF3/derivation/generate_1.py | 6 ++++++ libraries/AP_NavEKF3/derivation/generate_nix | 13 +++++++++++++ 2 files changed, 19 insertions(+) create mode 100755 libraries/AP_NavEKF3/derivation/generate_nix diff --git a/libraries/AP_NavEKF3/derivation/generate_1.py b/libraries/AP_NavEKF3/derivation/generate_1.py index 4d54105604..882d1524fe 100755 --- a/libraries/AP_NavEKF3/derivation/generate_1.py +++ b/libraries/AP_NavEKF3/derivation/generate_1.py @@ -1,10 +1,16 @@ #!/usr/bin/env python3 # Copied from https://github.com/PX4/ecl/commit/264c8c4e8681704e4719d0a03b848df8617c0863 # and modified for ArduPilot +from sympy import __version__ as __sympy__version__ from sympy import * from code_gen import * import numpy as np +# version required to generate the exact code currently present in ArduPilot. +# sympy version upgrades must ensure generated code doesn't pose any problems +# and must not have any other changes to the generator. +assert __sympy__version__ == "1.9", "expected sympy version 1.9, not "+__sympy__version__ + # q: quaternion describing rotation from frame 1 to frame 2 # returns a rotation matrix derived form q which describes the same # rotation diff --git a/libraries/AP_NavEKF3/derivation/generate_nix b/libraries/AP_NavEKF3/derivation/generate_nix new file mode 100755 index 0000000000..cbb5e6ecb2 --- /dev/null +++ b/libraries/AP_NavEKF3/derivation/generate_nix @@ -0,0 +1,13 @@ +#!/usr/bin/env nix-shell +#! nix-shell --pure -i bash -p "python3.withPackages (p: [ p.numpy p.sympy ])" +#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/eabc38219184cc3e04a974fe31857d8e0eac098d.tar.gz + +# above pins Python 3.9.13, Numpy 1.21.2, and Sympy 1.9 (and deps) +# using the last nixos-21.11 branch commit + +cd "$(dirname "$0")" +rm -rf generated # ensure generated directory exists and is empty +mkdir -p generated + +# explicitly invoke python3 to use interpreter from nix-shell +python3 ./generate_1.py