From d1bbc2dd0f2cfb078874e2c86ca06f04a68263a5 Mon Sep 17 00:00:00 2001 From: Pierre Schnizer Date: Fri, 8 Sep 2023 17:26:24 +0200 Subject: [PATCH 1/5] Updated install instructions --- install.rst | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/install.rst b/install.rst index be35e13c..f753271d 100644 --- a/install.rst +++ b/install.rst @@ -10,6 +10,8 @@ python wrapper. Dependencies ------------ +- `gtpsa-cpp` provided by https://github.com/hz-b/gtpsa-cpp.git + - modern c++ compiler C++17 or better - std::shared_ptr @@ -26,6 +28,7 @@ Dependencies - flex and bison + - modern python3 Packages to be installed on Ubuntu 22 LTS @@ -52,7 +55,7 @@ First clone the repository using .. code:: shell - git clone https://github.com/jbengtsson/thor-scsi-lib.git + git clone https://github.com/hz-b/thor-scsi-lib.git change to the directory (persumably) `thor-scsi-lib`. @@ -61,18 +64,16 @@ Then initialise submodules using the following command .. code:: shell - git submodule update --init --recursive - -*NB*: this command currently will pull a subrepository (`cmake4epics`). -This repository currently does not support (llvm/clang). Thus build on -MAC currently fails. A fix is currently worked on. - + git submodule update --init Getting ready to build ---------------------- -create a directory "build" +Please install first gtpsa-cpp. Have a look to the installation +instructions provided there. + +Create a directory "build" .. code:: shell @@ -144,20 +145,6 @@ python install procedure. Before you can use this script, you need to build the c++ library and install it to some path (called `/path/to/install/to` above). -Directories with python modules -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Two python modules are provided - -* gtpsa: directory src/gtpsa/python -* thor_scsi: directory python/ - -Recommandation is to first build gtpsa and then thor scsi. -The description below refers to both of them. Both directories are -refered to as `python` directory below. - -Installation instruction for one of the packages -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The process of building the python package depends on the C++ headers and libraries. Thus it needs to know where these are installed. The process described below will From 1673d36d667dea55a0f8ec552a9ddcabe2ab6a90 Mon Sep 17 00:00:00 2001 From: Pierre Schnizer Date: Fri, 8 Sep 2023 17:26:24 +0200 Subject: [PATCH 2/5] Updated install instructions --- install.rst | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/install.rst b/install.rst index 65ee2ad8..f753271d 100644 --- a/install.rst +++ b/install.rst @@ -10,6 +10,8 @@ python wrapper. Dependencies ------------ +- `gtpsa-cpp` provided by https://github.com/hz-b/gtpsa-cpp.git + - modern c++ compiler C++17 or better - std::shared_ptr @@ -26,6 +28,7 @@ Dependencies - flex and bison + - modern python3 Packages to be installed on Ubuntu 22 LTS @@ -52,7 +55,7 @@ First clone the repository using .. code:: shell - git clone https://github.com/jbengtsson/thor-scsi-lib.git + git clone https://github.com/hz-b/thor-scsi-lib.git change to the directory (persumably) `thor-scsi-lib`. @@ -63,16 +66,14 @@ Then initialise submodules using the following command git submodule update --init -*NB*: this command currently will pull a subrepository (`cmake4epics`). -This repository currently does not support (llvm/clang). Thus build on -MAC currently fails. A fix is currently worked on. - - Getting ready to build ---------------------- -create a directory "build" +Please install first gtpsa-cpp. Have a look to the installation +instructions provided there. + +Create a directory "build" .. code:: shell @@ -144,20 +145,6 @@ python install procedure. Before you can use this script, you need to build the c++ library and install it to some path (called `/path/to/install/to` above). -Directories with python modules -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Two python modules are provided - -* gtpsa: directory src/gtpsa/python -* thor_scsi: directory python/ - -Recommandation is to first build gtpsa and then thor scsi. -The description below refers to both of them. Both directories are -refered to as `python` directory below. - -Installation instruction for one of the packages -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The process of building the python package depends on the C++ headers and libraries. Thus it needs to know where these are installed. The process described below will From ed76d4ecc5fe8418ee669f1c58c839e2539471dd Mon Sep 17 00:00:00 2001 From: Pierre Schnizer Date: Mon, 11 Sep 2023 17:38:39 +0200 Subject: [PATCH 3/5] [FIX] all tests should now pass --- .github/workflows/cmake-single-platform.yml | 10 +++++-- python/examples/mat_test.py | 32 --------------------- python/requirements.txt | 2 ++ python/setup.cfg | 6 ++-- python/tests/knobbable_test.py | 17 +++++------ 5 files changed, 22 insertions(+), 45 deletions(-) delete mode 100644 python/examples/mat_test.py diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-single-platform.yml index f091471f..d7f75ffd 100644 --- a/.github/workflows/cmake-single-platform.yml +++ b/.github/workflows/cmake-single-platform.yml @@ -43,8 +43,8 @@ jobs: sudo apt install g++ gfortran cmake make bison flex libarmadillo-dev # deliberatly only installing a subset of boost sudo apt install libboost-chrono-dev libboost-thread-dev libboost-filesystem-dev libboost-program-options-dev libboost-regex-dev libboost-test-dev - # for building the python interface ... hopefully python3-xarray is not needed this rather heavy - sudo apt install pybind11-dev python3-pytest python3-pip python3-pybind11 # python3-xarray + # for building the python interface ... hopefully python3-xarray is not needed this is rather heavy + sudo apt install pybind11-dev python3-pytest python3-pip python3-pybind11 - name: Configure cmake for gtpsa-cpp run: cmake gtpsa-cpp -B ${{github.workspace}}/gtpsa-cpp/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} @@ -82,5 +82,11 @@ jobs: - name : thor-scsi-lib build and install python package run: gtpsa_PREFIX=/usr/local thor_scsi_PREFIX=/usr/local pip3 install -v ./python/ + - name: install apt test dependencies + run: | + # xarray are heavy packages ... deliberatley only installed here + # as required for the tests + apt install python3-pandas python3-scipy python3-xarray + - name : thor-scsi-lib test python package run: pytest-3 python diff --git a/python/examples/mat_test.py b/python/examples/mat_test.py deleted file mode 100644 index 76215aec..00000000 --- a/python/examples/mat_test.py +++ /dev/null @@ -1,32 +0,0 @@ -from thor_scsi.lib import (ss_vect_tps, ss_vect_tps_to_mat, Matrix, - mat_to_ss_vect_tps) -import numpy as np - -ps = ss_vect_tps() -ps.set_identity() -print(ps) -tps = ps[1] -index = [0] * 6 -print("peek", tps.peek(index)) -tps.pook(index, 8) - -for tps in ps: - print(tps) - print ("TPS terms:", ", ".join(["{:.3f}".format(term) for term in tps])) - -rtmp = ss_vect_tps_to_mat(ps) -print(rtmp) -tmp = np.array(rtmp) -np.set_printoptions(precision=4) -print(tmp) -for r in tmp: - txt = '\t'.join(["{:10.6e}".format(x) for x in r]) - print(txt) - -x = np.fromfunction(lambda x, y: x * 100 + y, (7, 7)) -x = x.T -print(x) -m2 = Matrix(x) -print(m2) -ss2 = mat_to_ss_vect_tps(m2) -print(ss2) diff --git a/python/requirements.txt b/python/requirements.txt index 7687636d..9ef1a6b6 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -1,2 +1,4 @@ # Using PyBind11Extension pybind11>=2.6.0 +gtpsa +pandas diff --git a/python/setup.cfg b/python/setup.cfg index 7883d3db..a78c692b 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = thor_scsi -version = 0.0.0 +version = 0.0.2 url = https://github.com/jbengtson/thor-scsi-lib/ author = Johan Bengtsson, Pierre Schnizer author_email = johan.bengtsson@helmholtz-berlin.de @@ -23,6 +23,6 @@ requires = setup_tools [build_sphinx] project = 'thor_scsi' -version = 0.0.0 -release = 0.0.0 +version = 0.0.2 +release = 0.0.2 # source-dir = 'doc' diff --git a/python/tests/knobbable_test.py b/python/tests/knobbable_test.py index f134bf2c..ad88eecf 100644 --- a/python/tests/knobbable_test.py +++ b/python/tests/knobbable_test.py @@ -7,7 +7,7 @@ from dataclasses import dataclass import numpy as np -@pytest.mark.skip +#@pytest.mark.skip def test_knob_quadrupole(): length = 0.2 K = 1.2 @@ -28,7 +28,6 @@ def test_knob_quadrupole(): assert K_check == pytest.approx(K, rel=1e-12) -@pytest.mark.skip def test_knob_horizontal_steerer(): length = 0.0 K = 0.1 @@ -51,7 +50,7 @@ def test_knob_horizontal_steerer(): knobs.make_magnet_knobbable(nh_st, po=1, desc=desc, named_index=named_index) -@pytest.mark.skip +#@pytest.mark.skip def test_knob_vertical_steerer(): length = 0.0 K = 0.2 @@ -90,7 +89,6 @@ def analytic_x(*, K, length): return RMatrix(m11=m11, m12=m12, m21=m21, m22=m22) -# @pytest.mark.skip def test_quadrupole_dependence_on_offset(): """check that the parameter dependence on dx works as expected @@ -136,12 +134,16 @@ def test_quadrupole_dependence_on_offset(): {r_analytic.m21}, {r_analytic.m22} """ print("analytic\n", txt) + + for a_tpsa in [ps.x, ps.px]: + print(gtpsa.utils_df.tpsa2df(a_tpsa)) + # assert ps.x.get(dx=1) == pytest.approx(expected_dx_dependence, rel=1e-12) # fmt: on assert ps.x.get(x=1) == pytest.approx(r_analytic.m11, rel=1e-3) - assert ps.x.get(dx=1) == pytest.approx(r_analytic.m12, rel=1e-3) - assert ps.dx.get(x=1) == pytest.approx(r_analytic.m21, rel=1e-3) - assert ps.dx.get(dx=1) == pytest.approx(r_analytic.m21, rel=1e-3) + assert ps.x.get(px=1) == pytest.approx(r_analytic.m12, rel=1e-2) + assert ps.px.get(x=1) == pytest.approx(r_analytic.m21, rel=1e-2) + assert ps.px.get(px=1) == pytest.approx(r_analytic.m22, rel=1e-2) # fmt: off # Estimate effect based on propagation @@ -153,4 +155,3 @@ def test_quadrupole_dependence_on_offset(): ps.set_zero() quad.propagate(calc_config, ps) print(ps.x, ps.px) - assert False From fd3046419524af4710c0368572cff4f256b475aa Mon Sep 17 00:00:00 2001 From: Pierre Schnizer Date: Mon, 11 Sep 2023 18:36:04 +0200 Subject: [PATCH 4/5] [FIX] sudo for apt(-get) --- .github/workflows/cmake-single-platform.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-single-platform.yml index d7f75ffd..c787b5c9 100644 --- a/.github/workflows/cmake-single-platform.yml +++ b/.github/workflows/cmake-single-platform.yml @@ -38,13 +38,13 @@ jobs: - name: install apt dependencies run: | - sudo apt update + sudo apt-get update # gfortran ... currently for mad-ng gtpsa library - sudo apt install g++ gfortran cmake make bison flex libarmadillo-dev + sudo apt-get install g++ gfortran cmake make bison flex libarmadillo-dev # deliberatly only installing a subset of boost - sudo apt install libboost-chrono-dev libboost-thread-dev libboost-filesystem-dev libboost-program-options-dev libboost-regex-dev libboost-test-dev + sudo apt-get install libboost-chrono-dev libboost-thread-dev libboost-filesystem-dev libboost-program-options-dev libboost-regex-dev libboost-test-dev # for building the python interface ... hopefully python3-xarray is not needed this is rather heavy - sudo apt install pybind11-dev python3-pytest python3-pip python3-pybind11 + sudo apt-get install pybind11-dev python3-pytest python3-pip python3-pybind11 - name: Configure cmake for gtpsa-cpp run: cmake gtpsa-cpp -B ${{github.workspace}}/gtpsa-cpp/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} @@ -86,7 +86,7 @@ jobs: run: | # xarray are heavy packages ... deliberatley only installed here # as required for the tests - apt install python3-pandas python3-scipy python3-xarray + sudo apt-get install python3-pandas python3-scipy python3-xarray - name : thor-scsi-lib test python package run: pytest-3 python From 23a6df792eb11715fc0ced240ad033881413c75c Mon Sep 17 00:00:00 2001 From: Pierre Schnizer Date: Mon, 11 Sep 2023 18:49:53 +0200 Subject: [PATCH 5/5] [TASK] towards build with tests passing Only taking tests in dir tests/ into account --- .github/workflows/cmake-single-platform.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-single-platform.yml index c787b5c9..257e44e4 100644 --- a/.github/workflows/cmake-single-platform.yml +++ b/.github/workflows/cmake-single-platform.yml @@ -89,4 +89,7 @@ jobs: sudo apt-get install python3-pandas python3-scipy python3-xarray - name : thor-scsi-lib test python package - run: pytest-3 python + # consider removing tests .... + # so more tests will be run + # bba_test needs scikit-learn ... don't want to blow that image + run: pytest-3 python/tests/