From 0359205ba0790b8c6350aaecaad6611983d88ae7 Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 5 Apr 2023 15:17:47 +0100 Subject: [PATCH 01/36] Substitute cppflow submodule with conan package --- .gitmodules | 3 --- cmake_files/dependencies.cmake | 1 + conanfile.py | 3 +++ cpp/sopt/CMakeLists.txt | 2 +- cppflow | 1 - 5 files changed, 5 insertions(+), 5 deletions(-) delete mode 160000 cppflow diff --git a/.gitmodules b/.gitmodules index 4736c48a1..221b57d02 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "cppflow"] - path = cppflow - url = git@github.com:UCL/cppflow.git [submodule "lexci_models"] path = lexci_models url = git@github.com:astro-informatics/lexci_models.git diff --git a/cmake_files/dependencies.cmake b/cmake_files/dependencies.cmake index 91abadda2..3d7216fdf 100644 --- a/cmake_files/dependencies.cmake +++ b/cmake_files/dependencies.cmake @@ -51,5 +51,6 @@ endif() set(SOPT_MPI ${MPI_FOUND}) if(cppflow) + find_package(cppflow) find_library(TENSORFLOW_LIB tensorflow REQUIRED) endif() diff --git a/conanfile.py b/conanfile.py index 8d44861ee..641169cb9 100644 --- a/conanfile.py +++ b/conanfile.py @@ -39,6 +39,9 @@ def requirements(self): if self.options.logging == 'on': self.requires("spdlog/1.9.2") + if self.options.cppflow == 'on': + self.requires("cppflow/2.0.0") + def build_requirements(self): if self.options.docs == 'on': diff --git a/cpp/sopt/CMakeLists.txt b/cpp/sopt/CMakeLists.txt index b44bf2845..11dedc481 100644 --- a/cpp/sopt/CMakeLists.txt +++ b/cpp/sopt/CMakeLists.txt @@ -78,7 +78,7 @@ if (cppflow) # https://stackoverflow.com/questions/25676277/cmake-target-include-directories-prints-an-error-when-i-try-to-add-the-source # Add /usr/local/include for default location of TensorFlow headers target_include_directories(sopt PUBLIC - $ + $ $ $ ) diff --git a/cppflow b/cppflow deleted file mode 160000 index a6d00ccde..000000000 --- a/cppflow +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a6d00ccdee5a0ccad4b1ac628cdb316cbeef62ef From 330cd91e3a0d26983528df1d930f7bd3eee292d9 Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 10 May 2023 13:20:04 +0100 Subject: [PATCH 02/36] Update CI to create cppflow package --- .github/workflows/cmake.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index a19fed6d4..ed0730447 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -132,6 +132,13 @@ jobs: ${{ matrix.os }}-${{ matrix.cxx }} ${{ matrix.os }} + - name: Create cppflow package + uses: actions/checkout@v3 + with: + repository: UCL/cppflow.git + path: cppflow + run: conan create ./cppflow/ -pr:h=default -pr:b=default + - name: Conan install on gcc if: ${{ contains(matrix.cxx, 'g++-9') }} run: conan install ${{github.workspace}} -if ${{github.workspace}}/build -s compiler.libcxx=libstdc++11 --build missing -o mpi=${{matrix.mpi}} -o openmp=${{matrix.omp}} -o cppflow=on -pr:h=default -pr:b=default @@ -143,7 +150,7 @@ jobs: - name: Build # Build your program with the given configuration. # The Github Actions machines are dual-core so we can build faster using 2 parallel processes - run: conan build ${{github.workspace}} -bf ${{github.workspace}}/build + run: conan build ${{github.workspace}} -bf ${{github.workspace}}/build - name: Test working-directory: ${{github.workspace}}/build From 88c05ed7b120a30db2a28095e38c75ec667289bc Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 10 May 2023 13:24:41 +0100 Subject: [PATCH 03/36] Add cppflow package in documentation CI --- .github/workflows/documentation.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 9dfd0f8db..0a77ae4a7 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -12,7 +12,7 @@ on: description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' required: false default: false - + env: CONAN_PRINT_RUN_COMMANDS: 1 CONAN_REVISIONS_ENABLED: 1 @@ -32,13 +32,13 @@ jobs: - name: Setup tmate session uses: mxschmitt/action-tmate@v3 if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }} - + # Note that we are installing doxygen with apt here, and with conan in the Configure step. # This is because there is no easy way of extracting the path to the doxygen executable from conan. # the apt installed doxygen is used in the Make Docweb step to build the html files, # while the conan installed version is used in the build step. # The version we install from apt is older than the 1.9.4 we install from conan, but - # it is not causing any issues at the moment. + # it is not causing any issues at the moment. - name: Install dependencies run: | sudo apt update @@ -56,6 +56,13 @@ jobs: version: 2.11.0 os: linux + - name: Create cppflow package + uses: actions/checkout@v3 + with: + repository: UCL/cppflow.git + path: cppflow + run: conan create ./cppflow/ -pr:h=default -pr:b=default + - name: Configure run: | conan install doxygen/1.9.4@#2af713e135f12722e3536808017ba086 --update From 69c2234363a0689ade313a38a8629954602884b3 Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 10 May 2023 13:28:34 +0100 Subject: [PATCH 04/36] Split checkout and create into two steps --- .github/workflows/cmake.yml | 4 +++- .github/workflows/documentation.yml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index ed0730447..204898fad 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -132,11 +132,13 @@ jobs: ${{ matrix.os }}-${{ matrix.cxx }} ${{ matrix.os }} - - name: Create cppflow package + - name: Checkout cppflow repo uses: actions/checkout@v3 with: repository: UCL/cppflow.git path: cppflow + + - name: Create cppflow package run: conan create ./cppflow/ -pr:h=default -pr:b=default - name: Conan install on gcc diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 0a77ae4a7..2e5d95ffe 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -56,11 +56,13 @@ jobs: version: 2.11.0 os: linux - - name: Create cppflow package + - name: Checkout cppflow repo uses: actions/checkout@v3 with: repository: UCL/cppflow.git path: cppflow + + - name: Create cppflow package run: conan create ./cppflow/ -pr:h=default -pr:b=default - name: Configure From 56f541aede551112490acf24e1f8f6759e2bd9e9 Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 10 May 2023 13:33:12 +0100 Subject: [PATCH 05/36] Fix indentation, add ref to master --- .github/workflows/cmake.yml | 1 + .github/workflows/documentation.yml | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 204898fad..0314a1a42 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -137,6 +137,7 @@ jobs: with: repository: UCL/cppflow.git path: cppflow + ref: master - name: Create cppflow package run: conan create ./cppflow/ -pr:h=default -pr:b=default diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 2e5d95ffe..48a1ca30b 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -56,14 +56,15 @@ jobs: version: 2.11.0 os: linux - - name: Checkout cppflow repo - uses: actions/checkout@v3 - with: - repository: UCL/cppflow.git - path: cppflow + - name: Checkout cppflow repo + uses: actions/checkout@v3 + with: + repository: UCL/cppflow.git + path: cppflow + ref: master - - name: Create cppflow package - run: conan create ./cppflow/ -pr:h=default -pr:b=default + - name: Create cppflow package + run: conan create ./cppflow/ -pr:h=default -pr:b=default - name: Configure run: | From 3397e7bf85a7308b7b6cd1cb0d76b97f7de01c4d Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 10 May 2023 14:01:39 +0100 Subject: [PATCH 06/36] Add compiler flag for apple-gcc --- .github/workflows/cmake.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 0314a1a42..e046e1754 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -139,8 +139,15 @@ jobs: path: cppflow ref: master - - name: Create cppflow package - run: conan create ./cppflow/ -pr:h=default -pr:b=default + - name: Create cppflow package on gcc + if: ${{ contains(matrix.cxx, 'g++-9') }} + run: | + conan create ./cppflow/ -pr:h=default -pr:b=default -s compiler.libcxx=libstdc++11 + + - name: Create cppflow package on apple-clang + if: ${{ contains(matrix.cxx, 'clang++') }} + run: | + conan create ./cppflow/ -pr:h=default -pr:b=default - name: Conan install on gcc if: ${{ contains(matrix.cxx, 'g++-9') }} From c726429ac7412d1c717c9cfed5a8767983bd97b0 Mon Sep 17 00:00:00 2001 From: Sarah Jaffa Date: Wed, 10 May 2023 16:18:27 +0100 Subject: [PATCH 07/36] Try adding separate step to save tensorflow path --- .github/workflows/cmake.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index e046e1754..9232621d8 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -102,6 +102,10 @@ jobs: version: 2.11.0 os: darwin + - name: Add tensorflow path to environment on MacOS + if: ${{ contains(matrix.os, 'macos') }} + run: echo "LD_LIBRARY_PATH=/usr/local/lib" >> "${GITHUB_ENV}"` + - name: Select Python 3.10 # otherwise turtlebrowser/get-conan@v1.1 fails on macos-12 # ref: https://github.com/turtlebrowser/get-conan/issues/4 From a017215b3a79aac4ca729c56204c56faaf336fa5 Mon Sep 17 00:00:00 2001 From: Sarah Jaffa Date: Wed, 10 May 2023 16:30:16 +0100 Subject: [PATCH 08/36] Remove catastrophe apostrophe --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 9232621d8..b5fe87c1c 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -104,7 +104,7 @@ jobs: - name: Add tensorflow path to environment on MacOS if: ${{ contains(matrix.os, 'macos') }} - run: echo "LD_LIBRARY_PATH=/usr/local/lib" >> "${GITHUB_ENV}"` + run: echo "LD_LIBRARY_PATH=/usr/local/lib" >> "${GITHUB_ENV}" - name: Select Python 3.10 # otherwise turtlebrowser/get-conan@v1.1 fails on macos-12 From fdb03d7c235b0d898444a963add2996197a8666a Mon Sep 17 00:00:00 2001 From: Sarah Jaffa Date: Wed, 10 May 2023 16:45:38 +0100 Subject: [PATCH 09/36] Try without quotes --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b5fe87c1c..2eea7fda1 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -104,7 +104,7 @@ jobs: - name: Add tensorflow path to environment on MacOS if: ${{ contains(matrix.os, 'macos') }} - run: echo "LD_LIBRARY_PATH=/usr/local/lib" >> "${GITHUB_ENV}" + run: echo "LD_LIBRARY_PATH=/usr/local/lib" >> ${GITHUB_ENV} - name: Select Python 3.10 # otherwise turtlebrowser/get-conan@v1.1 fails on macos-12 From 88ad148b7933efc60448a87cf41a3821701bfa34 Mon Sep 17 00:00:00 2001 From: Sarah Jaffa Date: Wed, 10 May 2023 17:05:52 +0100 Subject: [PATCH 10/36] Try without brackets --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 2eea7fda1..440ac0ffa 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -104,7 +104,7 @@ jobs: - name: Add tensorflow path to environment on MacOS if: ${{ contains(matrix.os, 'macos') }} - run: echo "LD_LIBRARY_PATH=/usr/local/lib" >> ${GITHUB_ENV} + run: echo "LD_LIBRARY_PATH=/usr/local/lib" >> $GITHUB_ENV - name: Select Python 3.10 # otherwise turtlebrowser/get-conan@v1.1 fails on macos-12 From b80aa531acdffcbaaa9e67347af7602e26c8e1bb Mon Sep 17 00:00:00 2001 From: Sarah Jaffa Date: Wed, 10 May 2023 17:43:51 +0100 Subject: [PATCH 11/36] Move path export to the relevant step --- .github/workflows/cmake.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 440ac0ffa..5566a0a92 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -102,10 +102,6 @@ jobs: version: 2.11.0 os: darwin - - name: Add tensorflow path to environment on MacOS - if: ${{ contains(matrix.os, 'macos') }} - run: echo "LD_LIBRARY_PATH=/usr/local/lib" >> $GITHUB_ENV - - name: Select Python 3.10 # otherwise turtlebrowser/get-conan@v1.1 fails on macos-12 # ref: https://github.com/turtlebrowser/get-conan/issues/4 @@ -151,6 +147,7 @@ jobs: - name: Create cppflow package on apple-clang if: ${{ contains(matrix.cxx, 'clang++') }} run: | + echo "LD_LIBRARY_PATH=/usr/local/lib" >> $GITHUB_ENV conan create ./cppflow/ -pr:h=default -pr:b=default - name: Conan install on gcc From a6fb898d2d7870a476877360ee069dc17a720bec Mon Sep 17 00:00:00 2001 From: Sarah Jaffa Date: Wed, 10 May 2023 17:54:50 +0100 Subject: [PATCH 12/36] Try matching TF docs --- .github/workflows/cmake.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 5566a0a92..d98f0db21 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -147,7 +147,8 @@ jobs: - name: Create cppflow package on apple-clang if: ${{ contains(matrix.cxx, 'clang++') }} run: | - echo "LD_LIBRARY_PATH=/usr/local/lib" >> $GITHUB_ENV + echo "LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib" >> $GITHUB_ENV + echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/lib" >> $GITHUB_ENV conan create ./cppflow/ -pr:h=default -pr:b=default - name: Conan install on gcc From 0512c2a32aaf63ce5a841a2cce79aada31218145 Mon Sep 17 00:00:00 2001 From: Sarah Jaffa Date: Wed, 10 May 2023 18:06:58 +0100 Subject: [PATCH 13/36] Try DYLD path --- .github/workflows/cmake.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index d98f0db21..89c86042e 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -147,8 +147,7 @@ jobs: - name: Create cppflow package on apple-clang if: ${{ contains(matrix.cxx, 'clang++') }} run: | - echo "LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib" >> $GITHUB_ENV - echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/lib" >> $GITHUB_ENV + echo "DYLD_LIBRARY_PATH=/usr/local/lib" >> $GITHUB_ENV conan create ./cppflow/ -pr:h=default -pr:b=default - name: Conan install on gcc From 4ef10bc5c6821af78fc7d290bd99f7ea03f1415b Mon Sep 17 00:00:00 2001 From: Sarah Jaffa Date: Thu, 11 May 2023 10:46:18 +0100 Subject: [PATCH 14/36] cat github env to check --- .github/workflows/cmake.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 89c86042e..239b108a2 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -147,7 +147,9 @@ jobs: - name: Create cppflow package on apple-clang if: ${{ contains(matrix.cxx, 'clang++') }} run: | - echo "DYLD_LIBRARY_PATH=/usr/local/lib" >> $GITHUB_ENV + echo "LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib" >> "$GITHUB_ENV" + echo "DYLD_LIBRARY_PATH=/usr/local/lib" >> "$GITHUB_ENV" + cat $GITHUB_ENV conan create ./cppflow/ -pr:h=default -pr:b=default - name: Conan install on gcc From d43f75acd52ce45fd8ff5d85e7c9179fe66d58ae Mon Sep 17 00:00:00 2001 From: Sarah Jaffa Date: Thu, 11 May 2023 11:26:43 +0100 Subject: [PATCH 15/36] Add tmate fail condition and put paths in own step --- .github/workflows/cmake.yml | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 239b108a2..4bf987940 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -67,11 +67,6 @@ jobs: with: submodules: recursive - # Enable tmate debugging of manually-triggered workflows if the input option was provided - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }} - - name: Install Dependencies on Ubunutu if: ${{ contains(matrix.os, 'ubuntu') }} run: | @@ -139,6 +134,13 @@ jobs: path: cppflow ref: master + - name: Add Tensorflow paths to env + if: ${{ contains(matrix.cxx, 'clang++') }} + run: | + echo "LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib" >> "$GITHUB_ENV" + echo "DYLD_LIBRARY_PATH=/usr/local/lib" >> "$GITHUB_ENV" + cat $GITHUB_ENV + - name: Create cppflow package on gcc if: ${{ contains(matrix.cxx, 'g++-9') }} run: | @@ -147,9 +149,6 @@ jobs: - name: Create cppflow package on apple-clang if: ${{ contains(matrix.cxx, 'clang++') }} run: | - echo "LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib" >> "$GITHUB_ENV" - echo "DYLD_LIBRARY_PATH=/usr/local/lib" >> "$GITHUB_ENV" - cat $GITHUB_ENV conan create ./cppflow/ -pr:h=default -pr:b=default - name: Conan install on gcc @@ -170,3 +169,9 @@ jobs: # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure + + + # Enable tmate debugging of manually-triggered workflows if the input option was provided + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled && failure() }} From 882470f36d6abe8e697aaf7be63758ef43de214c Mon Sep 17 00:00:00 2001 From: Sarah Jaffa Date: Thu, 11 May 2023 11:36:06 +0100 Subject: [PATCH 16/36] Updated Mac debug for TF test --- .github/workflows/cmake.yml | 2 +- .github/workflows/macdebug.yml | 60 +++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 4bf987940..b2e081306 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -174,4 +174,4 @@ jobs: # Enable tmate debugging of manually-triggered workflows if the input option was provided - name: Setup tmate session uses: mxschmitt/action-tmate@v3 - if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled && failure() }} + if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled}} diff --git a/.github/workflows/macdebug.yml b/.github/workflows/macdebug.yml index 26f5087f2..41e6e37e6 100644 --- a/.github/workflows/macdebug.yml +++ b/.github/workflows/macdebug.yml @@ -28,21 +28,54 @@ jobs: CXX: clang++ steps: - - uses: actions/checkout@v2 - - # Enable tmate debugging of manually-triggered workflows if the input option was provided - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }} + - uses: actions/checkout@v3 + - name: Install Dependencies on MacOS - if: ${{ contains(matrix.os, 'macos') }} - run: brew install libtiff open-mpi libyaml ccache conan + run: | + brew update + brew install libtiff open-mpi libyaml ccache + echo "CMAKE_PREFIX_PATH=/usr/local/opt/libomp" >> $GITHUB_ENV - - name: Conan install on apple-clang - if: ${{ contains(matrix.cxx, 'clang++') }} - run: conan install ${{github.workspace}} -if ${{github.workspace}}/build --build missing -o mpi=on -o openmp=on + - name: Install Tensorflow API on MacOS + uses: UCL/install-tensorflow-action@main + with: + version: 2.11.0 + os: darwin + + - name: Select Python 3.10 + # otherwise turtlebrowser/get-conan@v1.1 fails on macos-12 + # ref: https://github.com/turtlebrowser/get-conan/issues/4 + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install Conan + id: conan + uses: turtlebrowser/get-conan@main + with: + version: 1.59.0 + + - name: Checkout cppflow repo + uses: actions/checkout@v3 + with: + repository: UCL/cppflow.git + path: cppflow + ref: master + - name: Add Tensorflow paths to env + run: | + echo "LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib" >> "$GITHUB_ENV" + echo "DYLD_LIBRARY_PATH=/usr/local/lib" >> "$GITHUB_ENV" + cat $GITHUB_ENV + + - name: Create cppflow package on apple-clang + run: | + conan create ./cppflow/ -pr:h=default -pr:b=default + + - name: Conan install on apple-clang + run: conan install ${{github.workspace}} -if ${{github.workspace}}/build --build missing -o mpi=${{matrix.mpi}} -o openmp=${{matrix.omp}} -o cppflow=on -pr:h=default -pr:b=default + - name: Build # Build your program with the given configuration. # The Github Actions machines are dual-core so we can build faster using 2 parallel processes @@ -53,3 +86,8 @@ jobs: # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure + + # Enable tmate debugging of manually-triggered workflows if the input option was provided + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }} From 56713bb2a1baad80c66476eb47f0e8d4d8746ee2 Mon Sep 17 00:00:00 2001 From: Sarah Jaffa Date: Thu, 11 May 2023 11:44:52 +0100 Subject: [PATCH 17/36] Fix tmate --- .github/workflows/macdebug.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/macdebug.yml b/.github/workflows/macdebug.yml index 41e6e37e6..3e3f18b1f 100644 --- a/.github/workflows/macdebug.yml +++ b/.github/workflows/macdebug.yml @@ -69,12 +69,18 @@ jobs: echo "DYLD_LIBRARY_PATH=/usr/local/lib" >> "$GITHUB_ENV" cat $GITHUB_ENV + # Enable tmate debugging of manually-triggered workflows if the input option was provided + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }} + + - name: Create cppflow package on apple-clang run: | conan create ./cppflow/ -pr:h=default -pr:b=default - name: Conan install on apple-clang - run: conan install ${{github.workspace}} -if ${{github.workspace}}/build --build missing -o mpi=${{matrix.mpi}} -o openmp=${{matrix.omp}} -o cppflow=on -pr:h=default -pr:b=default + run: conan install ${{github.workspace}} -if ${{github.workspace}}/build --build missing -o mpi=off -o openmp=off -o cppflow=on -pr:h=default -pr:b=default - name: Build # Build your program with the given configuration. @@ -87,7 +93,3 @@ jobs: # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure - # Enable tmate debugging of manually-triggered workflows if the input option was provided - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }} From 2a362fe0d33adc9e65031ec17fc27bad1cacb5f7 Mon Sep 17 00:00:00 2001 From: Sarah Jaffa Date: Thu, 11 May 2023 11:53:55 +0100 Subject: [PATCH 18/36] Tmate triggers on failure --- .github/workflows/cmake.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b2e081306..368a0f0ee 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -174,4 +174,5 @@ jobs: # Enable tmate debugging of manually-triggered workflows if the input option was provided - name: Setup tmate session uses: mxschmitt/action-tmate@v3 - if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled}} + if: ${{ failure() }} + timeout-minutes: 15 From 65f728133de8df90fac3583032544edf4b9fde35 Mon Sep 17 00:00:00 2001 From: Michael McLeod Date: Mon, 22 May 2023 18:03:08 +0100 Subject: [PATCH 19/36] Add g_proximal functions, which return pointers, for padmm and primal dual. --- cpp/sopt/imaging_padmm.h | 5 +++++ cpp/sopt/imaging_primal_dual.h | 1 + 2 files changed, 6 insertions(+) diff --git a/cpp/sopt/imaging_padmm.h b/cpp/sopt/imaging_padmm.h index 1e5dabb92..897581d0c 100644 --- a/cpp/sopt/imaging_padmm.h +++ b/cpp/sopt/imaging_padmm.h @@ -83,6 +83,11 @@ class ImagingProximalADMM { \ public: + proximal::L1 * g_proximal() + { + return &l1_proximal_; + } + //! Maximum number of iterations SOPT_MACRO(l1_proximal, proximal::L1); //! The weighted L2 proximal functioning as g diff --git a/cpp/sopt/imaging_primal_dual.h b/cpp/sopt/imaging_primal_dual.h index 963dcc285..1274fce7b 100644 --- a/cpp/sopt/imaging_primal_dual.h +++ b/cpp/sopt/imaging_primal_dual.h @@ -94,6 +94,7 @@ class ImagingPrimalDual { TYPE NAME##_; \ \ public: + ImagingPrimalDual * g_proximal(){ return this;} //! The l1 prox functioning as f SOPT_MACRO(l1_proximal, t_Proximal); //! The l1 prox with weights functioning as f From 1253cbb1b7efd5c8f1f409117782964c30994745 Mon Sep 17 00:00:00 2001 From: Michael McLeod Date: Wed, 31 May 2023 13:06:21 +0100 Subject: [PATCH 20/36] Add complex conversion to tensor method --- cpp/sopt/cppflow_utils.cc | 52 ++++++++++++++++++++++++++++++++++++--- cpp/sopt/cppflow_utils.h | 4 +++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/cpp/sopt/cppflow_utils.cc b/cpp/sopt/cppflow_utils.cc index 2aeee3937..63771489b 100644 --- a/cpp/sopt/cppflow_utils.cc +++ b/cpp/sopt/cppflow_utils.cc @@ -4,9 +4,13 @@ #include #include "cppflow/ops.h" #include "cppflow/model.h" +#include namespace sopt { namespace cppflowutils { + + const double imaginary_threshold = 1e-5; + cppflow::tensor convert_image_to_tensor(Image const &image, int image_rows, int image_cols){ // Convert the Sopt::Image of doubles(wrapper for Eigen::Array) to a cppflow::tensor of floats // TODO: Make types template parameters @@ -16,7 +20,7 @@ namespace cppflowutils { std::vector input_values(image_rows*image_cols, 1); for (int i = 0; i < image.rows(); ++i) { for (int j = 0; j < image.cols(); ++j) { - input_values[j*image_cols+i] = image(i,j); + input_values[j*image_cols+i] = image(i,j); } } @@ -26,16 +30,58 @@ namespace cppflowutils { return input_tensor; } + cppflow::tensor convert_image_to_tensor(Image> const &image, int image_rows, int image_cols) { + // Convert the Sopt::Image of complex (wrapper for Eigen::Array) to a cppflow::tensor of floats + // Only takes the real part for processing, on the assumption that the imaginary part is negligible. + // If ratio of imaginary part to real part is greater than the threshold then this will throw an exception. + // TODO: Make types template parameters + // create a vector of the right shape (model expects extra dimensions on start and end) + std::vector input_shape = {1, image_rows, image_cols, 1}; + + std::vector input_values(image_rows*image_cols, 1); + + for (int i = 0; i < image.rows(); ++i) { + for (int j = 0; j < image.cols(); ++j) { + if(std::abs(image(i,j).imag())/std::abs(image(i,j).real()) > cppflowutils::imaginary_threshold) + { + throw std::runtime_error("Cannot convert to tensorflow format: imaginary component of image is non-negligible."); + } + input_values[j*image_cols+i] = image(i,j).real(); + } + } + + // create a tensor from vector + cppflow::tensor input_tensor(input_values, input_shape); + return input_tensor; + } + // Convert an image stored in a sopt::Vector to a cppflow::tensor of floats cppflow::tensor convert_image_to_tensor(sopt::Vector const &image, int image_rows, int image_cols) { - std::vector values(&image[0], image.data()+image.size()); - cppflow::tensor input_tensor(values, {1, image_rows, image_cols, 1}); + std::vector input_values(&image[0], image.data()+image.size()); + cppflow::tensor input_tensor(input_values, {1, image_rows, image_cols, 1}); return input_tensor; } + // Convert an image stored in a sopt::Vector to a cppflow::tensor of floats + cppflow::tensor convert_image_to_tensor(sopt::Vector> const &image, int image_rows, int image_cols) { + + std::vector input_values(image_rows); + for(int i = 0; i < image_rows; i++) + { + if(std::abs(image(i).imag())/std::abs(image(i).real()) > cppflowutils::imaginary_threshold) + { + throw std::runtime_error("Cannot conver to tensorflow format: imaginary component of image vector is non negligible."); + } + input_values[i] = image(i).real(); + } + cppflow::tensor input_tensor(input_values, {1, image_rows, image_cols, 1}); + + return input_tensor; + } + // Convert model output in a std::vector into a sopt::Image (2D Eigen::Array) Eigen::Map> convert_tensor_to_image(std::vector model_output, int image_rows, int image_cols){ // convert tensor of floats to Eigen::Array of doubles diff --git a/cpp/sopt/cppflow_utils.h b/cpp/sopt/cppflow_utils.h index 332d6efc6..4987657f4 100644 --- a/cpp/sopt/cppflow_utils.h +++ b/cpp/sopt/cppflow_utils.h @@ -5,13 +5,17 @@ #include "sopt/types.h" #include #include "cppflow/ops.h" +#include namespace sopt { namespace cppflowutils { + //! Converts a sopt::Image to a cppflow::tensor cppflow::tensor convert_image_to_tensor(sopt::Image const &image, int image_rows, int image_cols); +cppflow::tensor convert_image_to_tensor(sopt::Image> const &image, int image_rows, int image_cols); //! Converts a sopt::Vector to a cppflow::tensor cppflow::tensor convert_image_to_tensor(sopt::Vector const &image, int image_rows, int image_cols); +cppflow::tensor convert_image_to_tensor(sopt::Vector> const &image, int image_rows, int image_cols); //! Convert a cppflow:tensor to an Eigen::Array Eigen::Map> convert_tensor_to_image(std::vector model_output, int image_rows, int image_cols); From 62476f9e2ebcc325b176bce21fedc06e70c72ee4 Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 31 May 2023 13:42:36 +0100 Subject: [PATCH 21/36] Try adding CMAKE_PREFIX_PATH to env --- .github/workflows/cmake.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 368a0f0ee..01836309a 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -139,6 +139,7 @@ jobs: run: | echo "LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib" >> "$GITHUB_ENV" echo "DYLD_LIBRARY_PATH=/usr/local/lib" >> "$GITHUB_ENV" + echo "CMAKE_PREFIX_PATH=/usr/local/lib" >> $GITHUB_ENV cat $GITHUB_ENV - name: Create cppflow package on gcc From 2c8e216146401a395bc7b843d923ee405ce2291e Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 31 May 2023 13:59:40 +0100 Subject: [PATCH 22/36] Patch g++ to the right version --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index fbe443f56..cf6793f3c 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -143,7 +143,7 @@ jobs: cat $GITHUB_ENV - name: Create cppflow package on gcc - if: ${{ contains(matrix.cxx, 'g++-9') }} + if: ${{ contains(matrix.cxx, 'g++-10') }} run: | conan create ./cppflow/ -pr:h=default -pr:b=default -s compiler.libcxx=libstdc++11 From c823c1d39a9521ca99886263055961672ae36a3b Mon Sep 17 00:00:00 2001 From: Michael McLeod Date: Wed, 31 May 2023 15:06:49 +0100 Subject: [PATCH 23/36] Fix assertion in example --- cpp/sopt/gradient_operator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/sopt/gradient_operator.h b/cpp/sopt/gradient_operator.h index 5094ef773..906aea5dc 100644 --- a/cpp/sopt/gradient_operator.h +++ b/cpp/sopt/gradient_operator.h @@ -49,7 +49,7 @@ template LinearTransform> gradient_operator(const t_int rows, const t_int cols) { return LinearTransform>( [rows, cols](Vector &out, Vector const &x) { - assert(x.size() = rows * cols * 2); + assert(x.size() == rows * cols * 2); out = diff2d_adjoint(x, rows, cols) / 2.; assert(out.size() == rows * cols); }, From f700c8e0ef58c7c80b6b142988584f8a61237521 Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 31 May 2023 15:26:53 +0100 Subject: [PATCH 24/36] Skip brew update. Test cppflow build fix --- .github/workflows/cmake.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index cf6793f3c..254102eb4 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -78,7 +78,7 @@ jobs: run: | # Skip brew update until https://github.com/actions/setup-python/issues/577 is fixed # Seems to be working, alghough the issue is still open - brew update + #brew update brew install libtiff open-mpi libyaml ccache echo "CMAKE_PREFIX_PATH=/usr/local/opt/libomp" >> $GITHUB_ENV @@ -132,7 +132,7 @@ jobs: with: repository: UCL/cppflow.git path: cppflow - ref: master + ref: tk/macos-build-fix - name: Add Tensorflow paths to env if: ${{ contains(matrix.cxx, 'clang++') }} From d6496e3d3ca40bddbfd7a8641afcd7c7cb944ffc Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 31 May 2023 16:22:56 +0100 Subject: [PATCH 25/36] Remove extra paths from env --- .github/workflows/cmake.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 254102eb4..d69d35f12 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -134,13 +134,13 @@ jobs: path: cppflow ref: tk/macos-build-fix - - name: Add Tensorflow paths to env - if: ${{ contains(matrix.cxx, 'clang++') }} - run: | - echo "LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib" >> "$GITHUB_ENV" - echo "DYLD_LIBRARY_PATH=/usr/local/lib" >> "$GITHUB_ENV" - echo "CMAKE_PREFIX_PATH=/usr/local/lib" >> $GITHUB_ENV - cat $GITHUB_ENV + # - name: Add Tensorflow paths to env + # if: ${{ contains(matrix.cxx, 'clang++') }} + # run: | + # echo "LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib" >> "$GITHUB_ENV" + # echo "DYLD_LIBRARY_PATH=/usr/local/lib" >> "$GITHUB_ENV" + # echo "CMAKE_PREFIX_PATH=/usr/local/lib" >> $GITHUB_ENV + # cat $GITHUB_ENV - name: Create cppflow package on gcc if: ${{ contains(matrix.cxx, 'g++-10') }} From 379967f17fe53bafb1632d36d5b3ee0a898e1597 Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 31 May 2023 16:31:29 +0100 Subject: [PATCH 26/36] Debug before conan create --- .github/workflows/cmake.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index d69d35f12..927ecd269 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -142,6 +142,14 @@ jobs: # echo "CMAKE_PREFIX_PATH=/usr/local/lib" >> $GITHUB_ENV # cat $GITHUB_ENV + + + # Enable tmate debugging of manually-triggered workflows if the input option was provided + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + if: ${{ failure() }} + timeout-minutes: 15 + - name: Create cppflow package on gcc if: ${{ contains(matrix.cxx, 'g++-10') }} run: | @@ -170,10 +178,3 @@ jobs: # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure - - - # Enable tmate debugging of manually-triggered workflows if the input option was provided - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - if: ${{ failure() }} - timeout-minutes: 15 From 02e3cd332c0579fa9de32ebaea9c9030ecdb2906 Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 31 May 2023 17:03:06 +0100 Subject: [PATCH 27/36] Clean up debugging --- .github/workflows/cmake.yml | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 927ecd269..50ece194a 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -76,12 +76,14 @@ jobs: - name: Install Dependencies on MacOS if: ${{ contains(matrix.os, 'macos') }} run: | - # Skip brew update until https://github.com/actions/setup-python/issues/577 is fixed - # Seems to be working, alghough the issue is still open - #brew update brew install libtiff open-mpi libyaml ccache echo "CMAKE_PREFIX_PATH=/usr/local/opt/libomp" >> $GITHUB_ENV + # Enable tmate debugging of manually-triggered workflows if the input option was provided + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }} + - name: Install Tensorflow API on Ubuntu # TODO could this be combined with mac version somehow? if/else? if: ${{ contains(matrix.os, 'ubuntu') }} @@ -134,22 +136,6 @@ jobs: path: cppflow ref: tk/macos-build-fix - # - name: Add Tensorflow paths to env - # if: ${{ contains(matrix.cxx, 'clang++') }} - # run: | - # echo "LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib" >> "$GITHUB_ENV" - # echo "DYLD_LIBRARY_PATH=/usr/local/lib" >> "$GITHUB_ENV" - # echo "CMAKE_PREFIX_PATH=/usr/local/lib" >> $GITHUB_ENV - # cat $GITHUB_ENV - - - - # Enable tmate debugging of manually-triggered workflows if the input option was provided - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - if: ${{ failure() }} - timeout-minutes: 15 - - name: Create cppflow package on gcc if: ${{ contains(matrix.cxx, 'g++-10') }} run: | From c881f7eac046310a5f7a8926376583749e1c6fb2 Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 31 May 2023 17:07:23 +0100 Subject: [PATCH 28/36] Checkout cppflow master --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 50ece194a..6b50ef6c6 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -134,7 +134,7 @@ jobs: with: repository: UCL/cppflow.git path: cppflow - ref: tk/macos-build-fix + ref: master - name: Create cppflow package on gcc if: ${{ contains(matrix.cxx, 'g++-10') }} From 54a12ccfc8c015358deb9bdd50ad1ec93c3d29d2 Mon Sep 17 00:00:00 2001 From: Michael McLeod Date: Thu, 1 Jun 2023 15:30:40 +0100 Subject: [PATCH 29/36] Fix type problem causing seg fault in proximal weights --- cpp/sopt/l1_g_proximal.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/sopt/l1_g_proximal.h b/cpp/sopt/l1_g_proximal.h index 7be3febf6..0bb32dcab 100644 --- a/cpp/sopt/l1_g_proximal.h +++ b/cpp/sopt/l1_g_proximal.h @@ -49,7 +49,9 @@ class L1GProximal : public GProximal { // Return the norm associated with this implementation Real proximal_norm(t_Vector const &x) const override { - return sopt::l1_norm(static_cast(Psi().adjoint() * x), l1_proximal_weights()); + auto &weights = l1_proximal_weights(); + auto input = static_cast(Psi().adjoint() * x); + return sopt::l1_norm(input, weights); } // Return g_proximal as a lambda function. Used in operator() in base class. @@ -97,7 +99,7 @@ class L1GProximal : public GProximal { SOPT_MACRO(positivity_constraint, bool); SOPT_MACRO(real_constraint, bool); SOPT_MACRO(nu, Real); - SOPT_MACRO(weights, t_Vector); + SOPT_MACRO(weights, Vector); #undef SOPT_MACRO //! Analysis operator Ψ From 42915449b815f9a52147a42455b5353dc70c97df Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Tue, 13 Jun 2023 16:44:27 +0100 Subject: [PATCH 30/36] We can debug in the cmake workflow --- .github/workflows/macdebug.yml | 95 ---------------------------------- 1 file changed, 95 deletions(-) delete mode 100644 .github/workflows/macdebug.yml diff --git a/.github/workflows/macdebug.yml b/.github/workflows/macdebug.yml deleted file mode 100644 index 3e3f18b1f..000000000 --- a/.github/workflows/macdebug.yml +++ /dev/null @@ -1,95 +0,0 @@ -name: MacOSDebug - -on: - workflow_dispatch: - inputs: - debug_enabled: - description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' - required: false - default: false - -env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) - BUILD_TYPE: Release - OMP_NUM_THREADS: 2 - CONAN_PRINT_RUN_COMMANDS: 1 - CONAN_CPU_COUNT: 2 - -jobs: - build: - name: macos-clang-debug - # The CMake configure and build commands are platform agnostic and should work equally - # well on Windows or Mac. You can convert this to a matrix build if you need - # cross-platform coverage. - # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - runs-on: macos-11 - env: - CC: clang - CXX: clang++ - - steps: - - uses: actions/checkout@v3 - - - - name: Install Dependencies on MacOS - run: | - brew update - brew install libtiff open-mpi libyaml ccache - echo "CMAKE_PREFIX_PATH=/usr/local/opt/libomp" >> $GITHUB_ENV - - - name: Install Tensorflow API on MacOS - uses: UCL/install-tensorflow-action@main - with: - version: 2.11.0 - os: darwin - - - name: Select Python 3.10 - # otherwise turtlebrowser/get-conan@v1.1 fails on macos-12 - # ref: https://github.com/turtlebrowser/get-conan/issues/4 - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - - name: Install Conan - id: conan - uses: turtlebrowser/get-conan@main - with: - version: 1.59.0 - - - name: Checkout cppflow repo - uses: actions/checkout@v3 - with: - repository: UCL/cppflow.git - path: cppflow - ref: master - - - name: Add Tensorflow paths to env - run: | - echo "LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib" >> "$GITHUB_ENV" - echo "DYLD_LIBRARY_PATH=/usr/local/lib" >> "$GITHUB_ENV" - cat $GITHUB_ENV - - # Enable tmate debugging of manually-triggered workflows if the input option was provided - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }} - - - - name: Create cppflow package on apple-clang - run: | - conan create ./cppflow/ -pr:h=default -pr:b=default - - - name: Conan install on apple-clang - run: conan install ${{github.workspace}} -if ${{github.workspace}}/build --build missing -o mpi=off -o openmp=off -o cppflow=on -pr:h=default -pr:b=default - - - name: Build - # Build your program with the given configuration. - # The Github Actions machines are dual-core so we can build faster using 2 parallel processes - run: conan build ${{github.workspace}} -bf ${{github.workspace}}/build - - - name: Test - working-directory: ${{github.workspace}}/build - # Execute tests defined by the CMake configuration. - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure - From 32ecc275df2db6fc7553abfc79df1c779e917567 Mon Sep 17 00:00:00 2001 From: Michael McLeod Date: Wed, 14 Jun 2023 10:52:59 +0100 Subject: [PATCH 31/36] Restore MPI communicators for FB algorithm --- cpp/sopt/imaging_forward_backward.h | 5 +++-- cpp/sopt/l1_g_proximal.h | 8 ++++++++ cpp/sopt/l2_forward_backward.h | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cpp/sopt/imaging_forward_backward.h b/cpp/sopt/imaging_forward_backward.h index 6bfb60267..2d813dafa 100644 --- a/cpp/sopt/imaging_forward_backward.h +++ b/cpp/sopt/imaging_forward_backward.h @@ -125,6 +125,7 @@ class ImagingForwardBackward { #ifdef SOPT_MPI //! Communicator for summing objective_function SOPT_MACRO(obj_comm, mpi::Communicator); + SOPT_MACRO(adjoint_space_comm, mpi::Communicator); #endif #undef SOPT_MACRO @@ -205,7 +206,7 @@ class ImagingForwardBackward { //! \brief Proximal of the L2 ball //! \details Non-const version to setup the object. - t_Gradient &l2_graident() { return l2_gradient_; } + t_Gradient &l2_gradient() { return l2_gradient_; } //! Helper function to set-up default residual convergence function ImagingForwardBackward &residual_convergence(Real const &tolerance) { @@ -316,7 +317,7 @@ bool ImagingForwardBackward::objective_convergence(mpi::Communicator con if (scalvar.relative_tolerance() <= 0e0) return true; auto const current = obj_comm.all_sum_all( ((gamma() > 0) ? g_proximal_->proximal_norm(x) - * gamma() : 0) + std::pow(sopt::l2_norm(residual), 2) / (2 * sigma() * sigma())); + * gamma() : 0) + std::pow(sopt::l2_norm(residual), 2) / (2 * sigma_ * sigma_)); return scalvar(current); }; #endif diff --git a/cpp/sopt/l1_g_proximal.h b/cpp/sopt/l1_g_proximal.h index 0bb32dcab..e19d7fb83 100644 --- a/cpp/sopt/l1_g_proximal.h +++ b/cpp/sopt/l1_g_proximal.h @@ -15,6 +15,10 @@ #include "sopt/g_proximal.h" #include "sopt/l1_proximal.h" +#ifdef SOPT_MPI + #include "sopt/mpi/communicator.h" +#endif + namespace sopt { namespace algorithm { @@ -100,6 +104,10 @@ class L1GProximal : public GProximal { SOPT_MACRO(real_constraint, bool); SOPT_MACRO(nu, Real); SOPT_MACRO(weights, Vector); +#ifdef SOPT_MPI + SOPT_MACRO(adjoint_space_comm, mpi::Communicator); + SOPT_MACRO(direct_space_comm, mpi::Communicator); +#endif #undef SOPT_MACRO //! Analysis operator Ψ diff --git a/cpp/sopt/l2_forward_backward.h b/cpp/sopt/l2_forward_backward.h index 2d60e092b..7d6eefd7f 100644 --- a/cpp/sopt/l2_forward_backward.h +++ b/cpp/sopt/l2_forward_backward.h @@ -206,7 +206,7 @@ class L2ForwardBackward { t_Proximal> &l2_proximal_weighted() { return l2_proximal_weighted_; } //! \brief Proximal of the L2 ball //! \details Non-const version to setup the object. - t_Gradient &l2_graident() { return l2_gradient_; } + t_Gradient &l2_gradient() { return l2_gradient_; } //! Helper function to set-up default residual convergence function L2ForwardBackward &residual_convergence(Real const &tolerance) { From 39f957ae94f864bf391f5fd6f721adf97ec84671 Mon Sep 17 00:00:00 2001 From: Sarah Jaffa Date: Wed, 14 Jun 2023 11:53:39 +0100 Subject: [PATCH 32/36] Updated install instructions for cppflow conan package --- README.md | 74 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index a4ebc8024..138c3da71 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Dependencies installation - [GCC](https://gcc.gnu.org) v7.3.0 GNU compiler for `C++`. - [UCL/GreatCMakeCookOff](https://github.com/UCL/GreatCMakeCookOff) Collection of `CMake` recipes. Downloaded automatically if absent. - [OpenMP](http://openmp.org/wp/) v4.8.4 (Trusty) - Optional - Speeds up some of the operations. +- [Cppflow](https://github.com/UCL/cppflow) - Optional - A warpper for the Tensorflow C API allowing us to read Tensorflow models into SOPT. Needed if you are using a learned prior. - [Conan](https://docs.conan.io/en/latest/installation.html) - C++ package manager which installs the following: - [Eigen3](http://eigen.tuxfamily.org/index.php?title=Main_Page) v3.2.0 (Trusty) Modern `C++` linear algebra. Downloaded automatically if absent. - [spdlog](https://github.com/gabime/spdlog) v* - Optional - Logging library. Downloaded automatically if @@ -42,45 +43,58 @@ Dependencies installation Installing and building SOPT ---------------------------- -You can build **SOPT** entirely from the source code. Once the mandatory dependencies are present, `git clone` from the [GitHub repository](https://github.com/astro-informatics/sopt): +You can build **SOPT** entirely from the source code. -``` bash -git clone https://github.com/astro-informatics/sopt.git -``` -Then, the program can be built with standard `CMake` command: -``` bash -cd /path/to/code -mkdir build -cd build -conan install .. --build missing -conan build .. -``` +1. If you are using a learned prior you must install teh Tensorflow C API and `cppflow package: + - Install [TensorFlow C API](https://www.tensorflow.org/install/lang_c) + - Clone the UCL fork of cppflow and create a conan package using -To install in directory `INSTALL_FOLDER`, add the following options to the conan build command: + ``` bash + git clone git@github.com:UCL/cppflow.git + conan create ./cppflow/ -pr:h=default -pr:b=default + ``` -``` bash -conan build .. -bf INSTALL_FOLDER -if . -``` +1. Once the mandatory dependencies are present, `git clone` from the [GitHub repository](https://github.com/astro-informatics/sopt): -CMake build options should be passed as options to `conan install` using the `-o` flag with a value `on` or `off`. Possible options are + ``` bash + git clone https://github.com/astro-informatics/sopt.git + ``` -- tests (default on) -- benchmarks (default off) -- examples (default on) -- logging (default on) -- openmp (default on) -- mpi (default on) -- docs (default off) -- coverage (default off) +1. Then, the program can be built using conan: -For example, to build with both MPI and OpenMP off you would use + ``` bash + cd /path/to/code + mkdir build + cd build + conan install .. --build missing + conan build .. + ``` -``` bash -conan install .. --build missing -o openmp=off -o mpi=off -conan build .. -``` + - To install in directory `INSTALL_FOLDER`, add the following options to the conan build command: + + ``` bash + conan build .. -bf INSTALL_FOLDER -if . + ``` + + - CMake build options should be passed as options to `conan install` using the `-o` flag with a value `on` or `off`. Possible options are + + - tests (default on) + - benchmarks (default off) + - examples (default on) + - logging (default on) + - openmp (default on) + - mpi (default on) + - docs (default off) + - coverage (default off) + + For example, to build with both MPI and OpenMP off you would use + + ``` bash + conan install .. --build missing -o openmp=off -o mpi=off + conan build .. + ``` Common errors ------- From 983f80de6f3992febc12a31b7a5fa197980161ed Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 14 Jun 2023 16:19:01 +0100 Subject: [PATCH 33/36] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 138c3da71..b828ec41d 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ You can build **SOPT** entirely from the source code. -1. If you are using a learned prior you must install teh Tensorflow C API and `cppflow package: +1. If you are using a learned prior you must install the Tensorflow C API and `cppflow` package: - Install [TensorFlow C API](https://www.tensorflow.org/install/lang_c) - Clone the UCL fork of cppflow and create a conan package using From fc664f2efab3ea6dded114e9e3451b51dc370dde Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 14 Jun 2023 16:20:01 +0100 Subject: [PATCH 34/36] Add cppflow option --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b828ec41d..61ec5c438 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ You can build **SOPT** entirely from the source code. - mpi (default on) - docs (default off) - coverage (default off) + - cppflow (default off) For example, to build with both MPI and OpenMP off you would use From bbbc5adbe63ecec1e75e8f212353474ad078b4cb Mon Sep 17 00:00:00 2001 From: Michael McLeod Date: Wed, 14 Jun 2023 17:21:09 +0100 Subject: [PATCH 35/36] Change from relative to absolute threshold for imaginary component of image --- cpp/sopt/cppflow_utils.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cpp/sopt/cppflow_utils.cc b/cpp/sopt/cppflow_utils.cc index 63771489b..90c8dd10f 100644 --- a/cpp/sopt/cppflow_utils.cc +++ b/cpp/sopt/cppflow_utils.cc @@ -9,7 +9,8 @@ namespace sopt { namespace cppflowutils { - const double imaginary_threshold = 1e-5; + // arbitrary constant for imaginary part of image vectors. + const double imaginary_threshold = 1e-10; cppflow::tensor convert_image_to_tensor(Image const &image, int image_rows, int image_cols){ // Convert the Sopt::Image of doubles(wrapper for Eigen::Array) to a cppflow::tensor of floats @@ -42,7 +43,7 @@ namespace cppflowutils { for (int i = 0; i < image.rows(); ++i) { for (int j = 0; j < image.cols(); ++j) { - if(std::abs(image(i,j).imag())/std::abs(image(i,j).real()) > cppflowutils::imaginary_threshold) + if(std::abs(image(i,j).real()) > cppflowutils::imaginary_threshold) { throw std::runtime_error("Cannot convert to tensorflow format: imaginary component of image is non-negligible."); } @@ -71,7 +72,7 @@ namespace cppflowutils { std::vector input_values(image_rows); for(int i = 0; i < image_rows; i++) { - if(std::abs(image(i).imag())/std::abs(image(i).real()) > cppflowutils::imaginary_threshold) + if(std::abs(image(i).real()) > cppflowutils::imaginary_threshold) { throw std::runtime_error("Cannot conver to tensorflow format: imaginary component of image vector is non negligible."); } From 976872f2b55fdefd38d88af24726381b62a05b63 Mon Sep 17 00:00:00 2001 From: Tuomas Koskela Date: Wed, 21 Jun 2023 13:53:57 +0100 Subject: [PATCH 36/36] Update README.md Add conan profiles to install instructions --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 61ec5c438..360066c67 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ You can build **SOPT** entirely from the source code. git clone git@github.com:UCL/cppflow.git conan create ./cppflow/ -pr:h=default -pr:b=default ``` + Note that conan requires you to specify the host (h) and the build (b) profiles on the command + line (`-pr:h=default -pr:b=default`), if you haven't defined them in your conan profile. 1. Once the mandatory dependencies are present, `git clone` from the [GitHub repository](https://github.com/astro-informatics/sopt): @@ -68,7 +70,7 @@ You can build **SOPT** entirely from the source code. cd /path/to/code mkdir build cd build - conan install .. --build missing + conan install .. --build missing -pr:h=default -pr:b=default conan build .. ``` @@ -93,7 +95,7 @@ You can build **SOPT** entirely from the source code. For example, to build with both MPI and OpenMP off you would use ``` bash - conan install .. --build missing -o openmp=off -o mpi=off + conan install .. --build missing -o openmp=off -o mpi=off -pr:h=default -pr:b=default conan build .. ```