From efe5f3a42244790215e6612cf82a25d79d5d6cf5 Mon Sep 17 00:00:00 2001 From: Thomas BAUDIER Date: Fri, 23 Aug 2024 10:12:50 +0200 Subject: [PATCH 1/2] Use qt6 for mac instead qt5 Change cache to compile G4 with qt6 Qt6 is not installed in the same directory than Qt5 on macOS Try to add libqcocoa into the wheel. cibuildwheel could not do it so I compile and delocate the wheel by myself --- .github/workflows/main.yml | 40 +++++++++---------- .github/workflows/redoQt5LibsMac.py | 30 ++++++++------ core/MANIFEST.in | 1 + ...mands.mac => default_visu_commands_qt.mac} | 2 +- opengate/managers.py | 2 +- opengate/tests/src/test004_simple_visu_qt.py | 13 +----- 6 files changed, 41 insertions(+), 47 deletions(-) create mode 100644 core/MANIFEST.in rename opengate/mac/{default_visu_commands.mac => default_visu_commands_qt.mac} (97%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index daa5eb652..61434d629 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -66,8 +66,8 @@ jobs: uses: actions/cache@v4 with: path: ~/software - key: ${{ runner.os }}-${{ steps.get-os-version.outputs.release }}_geant4_${{ env.GEANT4_VERSION }}_itk_${{ env.ITK_VERSION }}_build1 - restore-keys: ${{ runner.os }}-${{ steps.get-os-version.outputs.release }}_geant4_${{ env.GEANT4_VERSION }}_itk_${{ env.ITK_VERSION }}_build1 + key: ${{ runner.os }}-${{ steps.get-os-version.outputs.release }}_geant4_${{ env.GEANT4_VERSION }}_itk_${{ env.ITK_VERSION }}_build2 + restore-keys: ${{ runner.os }}-${{ steps.get-os-version.outputs.release }}_geant4_${{ env.GEANT4_VERSION }}_itk_${{ env.ITK_VERSION }}_build2 - name: Create opengate Wheel if: matrix.os == 'ubuntu-latest' run: | @@ -139,8 +139,8 @@ jobs: python --version export PATH="/usr/local/miniconda/envs/opengate_core/bin/:$PATH" pip install wget colored - pip install cibuildwheel==2.17.0 - conda install -c conda-forge qt==5.15.6 + pip install wheel delocate + conda install conda-forge::qt6-main conda-forge::qt6-3d mkdir -p $HOME/software if [ "${{ steps.cache_opengate_core_dependencies.outputs.cache-hit }}" != 'true' ]; then cd $HOME/software @@ -153,7 +153,8 @@ jobs: -DGEANT4_INSTALL_DATA=OFF \ -DGEANT4_INSTALL_DATADIR=$HOME/software/geant4/data \ -DGEANT4_USE_QT=ON \ - -DGEANT4_USE_OPENGL_X11=ON \ + -DGEANT4_USE_OPENGL_X11=OFF \ + -DGEANT4_USE_QT_QT6=ON \ -DGEANT4_USE_SYSTEM_EXPAT=OFF \ -DGEANT4_BUILD_MULTITHREADED=ON \ -DGEANT4_USE_GDML=ON \ @@ -174,26 +175,23 @@ jobs: make -j4 fi cd $GITHUB_WORKSPACE - ls /Users/runner/miniconda3/envs/opengate_core/plugins/platforms source $HOME/software/geant4/bin/geant4make.sh export CMAKE_PREFIX_PATH=$HOME/software/geant4/bin:$HOME/software/itk/bin/:${CMAKE_PREFIX_PATH} cd core mkdir opengate_core/plugins - mkdir opengate_core/plugins/miniconda + cp -r /Users/runner/miniconda3/envs/opengate_core/lib/qt6/plugins/platforms/* opengate_core/plugins/ + cp -r /Users/runner/miniconda3/envs/opengate_core/lib/qt6/plugins/imageformats opengate_core/plugins/ + python3 setup.py sdist bdist_wheel + ls dist + export DYLD_LIBRARY_PATH=$HOME/software/geant4/bin/BuildProducts/lib:/Users/runner/miniconda3/envs/opengate_core/lib/qt6/plugins/platforms:/opt/X11/lib/:$DYLD_LIBRARY_PATH:/Users/runner/miniconda3/envs/opengate_core/lib + delocate-listdeps --all dist/*.whl + delocate-wheel -w fixed_wheels -v dist/*.whl rm -rf dist - if [ ${{ matrix.python-version }} == "3.8" ]; then - export CIBW_BUILD="cp38-macosx_x86_64" - elif [ ${{ matrix.python-version }} == "3.9" ]; then - export CIBW_BUILD="cp39-macosx_x86_64" - elif [ ${{ matrix.python-version }} == "3.10" ]; then - export CIBW_BUILD="cp310-macosx_x86_64" - elif [ ${{ matrix.python-version }} == "3.11" ]; then - export CIBW_BUILD="cp311-macosx_x86_64" - fi - export CIBW_ENVIRONMENT='MACOSX_DEPLOYMENT_TARGET=10.14' - export CIBW_BEFORE_BUILD="python -m pip install colored" - python -m cibuildwheel --output-dir dist + ls fixed_wheels + delocate-listdeps --all fixed_wheels/*.whl + mv fixed_wheels dist cd dist + find . -name '*whl' -exec bash -c ' mv $0 ${0/macosx_12_0/macosx_10_9}' {} \; cd ../.. mv core/dist . - name: Create opengate_core Wheel Windows @@ -327,8 +325,8 @@ jobs: # uses: actions/cache@v4 # with: # path: ~/software -# key: ${{ runner.os }}-${{ steps.get-os-version.outputs.release }}_geant4_${{ env.GEANT4_VERSION }}_itk_${{ env.ITK_VERSION }}_build1 -# restore-keys: ${{ runner.os }}-${{ steps.get-os-version.outputs.release }}_geant4_${{ env.GEANT4_VERSION }}_itk_${{ env.ITK_VERSION }}_build1 +# key: ${{ runner.os }}-${{ steps.get-os-version.outputs.release }}_geant4_${{ env.GEANT4_VERSION }}_itk_${{ env.ITK_VERSION }}_build2 +# restore-keys: ${{ runner.os }}-${{ steps.get-os-version.outputs.release }}_geant4_${{ env.GEANT4_VERSION }}_itk_${{ env.ITK_VERSION }}_build2 # - uses: conda-incubator/setup-miniconda@v3 # with: # miniconda-version: "latest" diff --git a/.github/workflows/redoQt5LibsMac.py b/.github/workflows/redoQt5LibsMac.py index 73485cc57..8321eea00 100644 --- a/.github/workflows/redoQt5LibsMac.py +++ b/.github/workflows/redoQt5LibsMac.py @@ -8,20 +8,24 @@ dictLibs = { "@rpath/libz.1.dylib": "@loader_path/../../.dylibs/libz.1.2.11.dylib", "@rpath/libpng16.16.dylib": "@loader_path/../../.dylibs/libpng16.16.dylib", - "@rpath/libQt5Gui.5.dylib": "@loader_path/../../.dylibs/libQt5Gui.5.15.6.dylib", - "@rpath/libQt5Core.5.dylib": "@loader_path/../../.dylibs/libQt5Core.5.15.6.dylib", - "@rpath/libQt5PrintSupport.5.dylib": "@loader_path/../../.dylibs/libQt5PrintSupport.5.15.6.dylib", - "@rpath/libQt5Widgets.5.dylib": "@loader_path/../../.dylibs/libQt5Widgets.5.15.6.dylib", - "@rpath/libQt5Svg.5.dylib": "@loader_path/../miniconda/libQt5Svg.5.15.6.dylib", - "@rpath/libQt5DBus.5.dylib": "@loader_path/../miniconda/libQt5DBus.5.15.6.dylib", - "@rpath/libQt5Quick.5.dylib": "@loader_path/../miniconda/libQt5Quick.5.15.6.dylib", - "@rpath/libQt5WebSockets.5.dylib": "@loader_path/../miniconda/libQt5WebSockets.5.15.6.dylib", - "@rpath/libQt5QmlModels.5.dylib": "@loader_path/../miniconda/libQt5QmlModels.5.15.6.dylib", - "@rpath/libQt5Qml.5.dylib": "@loader_path/../miniconda/libQt5Qml.5.15.6.dylib", - "@rpath/libQt5Network.5.dylib": "@loader_path/../miniconda/libQt5Network.5.15.6.dylib", - "@rpath/libQt5Pdf.5.dylib": "@loader_path/../miniconda/libQt5Pdf.5.15.6.dylib", + "@rpath/libQt6Gui.6.dylib": "@loader_path/../../.dylibs/libQt6Gui.6.6.0.dylib", + "@rpath/libQt6Core.6.dylib": "@loader_path/../../.dylibs/libQt6Core.6.6.0.dylib", + "@rpath/libQt6PrintSupport.6.dylib": "@loader_path/../../.dylibs/libQt6PrintSupport.6.6.0.dylib", + "@rpath/libQt6Widgets.6.dylib": "@loader_path/../../.dylibs/libQt6Widgets.6.6.0.dylib", + "@rpath/libQt6Svg.6.dylib": "@loader_path/../miniconda/libQt6Svg.6.6.0.dylib", + "@rpath/libQt6DBus.6.dylib": "@loader_path/../miniconda/libQt6DBus.6.6.0.dylib", + "@rpath/libQt6Quick.6.dylib": "@loader_path/../miniconda/libQt6Quick.6.6.0.dylib", + "@rpath/libQt6WebSockets.6.dylib": "@loader_path/../miniconda/libQt6WebSockets.6.6.0.dylib", + "@rpath/libQt6QmlModels.6.dylib": "@loader_path/../miniconda/libQt6QmlModels.6.6.0.dylib", + "@rpath/libQt6Qml.6.dylib": "@loader_path/../miniconda/libQt6Qml.6.6.0.dylib", + "@rpath/libQt6Network.6.dylib": "@loader_path/../miniconda/libQt6Network.6.6.0.dylib", + "@rpath/libQt6Pdf.6.dylib": "@loader_path/../miniconda/libQt6Pdf.6.6.0.dylib", "@rpath/libc++.1.dylib": "@loader_path/../../.dylibs/libc++.1.dylib", - "@rpath/libjpeg.9.dylib": "@rpath/libjpeg.9.dylib", + "@rpath/libjpeg.8.dylib": "@rpath/libjpeg.8.dylib", + "@rpath/libwebp.7.dylib": "@rpath/libwebp.7.dylib", + "@rpath/libwebpdemux.2.dylib": "@rpath/libwebpdemux.2.dylib", + "@rpath/libwebpmux.3.dylib": "@rpath/libwebpmux.3.dylib", + "@rpath/libtiff.6.dylib": "@rpath/libtiff.6.dylib", } for root, dirs, files in os.walk("opengate_core/plugins"): diff --git a/core/MANIFEST.in b/core/MANIFEST.in new file mode 100644 index 000000000..785f4d859 --- /dev/null +++ b/core/MANIFEST.in @@ -0,0 +1 @@ +recursive-include opengate_core/plugins * diff --git a/opengate/mac/default_visu_commands.mac b/opengate/mac/default_visu_commands_qt.mac similarity index 97% rename from opengate/mac/default_visu_commands.mac rename to opengate/mac/default_visu_commands_qt.mac index 92f2a4579..74073d972 100644 --- a/opengate/mac/default_visu_commands.mac +++ b/opengate/mac/default_visu_commands_qt.mac @@ -2,7 +2,7 @@ # default visualization #/vis/open OGLSQt -/vis/open OGLIQt +/vis/open OGL /vis/scene/create /vis/drawVolume worlds /vis/viewer/flush diff --git a/opengate/managers.py b/opengate/managers.py index d2f8620b4..ba28962d5 100644 --- a/opengate/managers.py +++ b/opengate/managers.py @@ -1109,7 +1109,7 @@ class Simulation(GateObject): }, ), "visu_commands": ( - read_mac_file_to_commands("default_visu_commands.mac"), + read_mac_file_to_commands("default_visu_commands_qt.mac"), { "doc": "Geant4 commands needed to handle the visualization. ", }, diff --git a/opengate/tests/src/test004_simple_visu_qt.py b/opengate/tests/src/test004_simple_visu_qt.py index f4ecd6f42..2af60add4 100755 --- a/opengate/tests/src/test004_simple_visu_qt.py +++ b/opengate/tests/src/test004_simple_visu_qt.py @@ -17,6 +17,7 @@ sim.g4_verbose = False sim.g4_verbose_level = 1 sim.visu = True + sim.visu_type = "qt" sim.visu_verbose = False sim.number_of_threads = 1 sim.random_engine = "MersenneTwister" @@ -43,7 +44,7 @@ source.energy.mono = 80 * keV source.direction.type = "momentum" source.direction.momentum = [0, 0, 1] - source.activity = 200000 * Bq + source.activity = 200 * Bq # runs sec = g4_units.second @@ -55,13 +56,3 @@ # start simulation # sim.add_g4_command_after_init("/run/verbose 1") sim.run() - - stats = sim.output.get_actor("Stats") - stats.counts.run_count = 1 - - # gate_test4_simulation_stats_actor - # Gate mac/main.mac - stats_ref = utility.read_stat_file(paths.gate_output / "stat.txt") - is_ok = utility.assert_stats(stats, stats_ref, tolerance=0.03) - - utility.test_ok(is_ok) From 9a0b8131058ba75f368171e4c10ef27d08a84ea2 Mon Sep 17 00:00:00 2001 From: Thomas BAUDIER Date: Fri, 6 Sep 2024 11:01:23 +0200 Subject: [PATCH 2/2] Update cirrus with qt6 for mac M1 Install qt6 with brew instead of conda With conda, during ccmake of geant4, I have to set QT_HOST_PATH and QT_HOST_PATH_CMAKE_DIR. Even with that I still have problem due to a cross-compile of qt6 workaround for delocate https://github.c/neuronsimulator/nrn/pull/1897 Update doc --- .cirrus.yml | 57 ++++++++++++++++-------- docs/source/user_guide_2_0_simulation.md | 4 +- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 4d2bea58e..8f0cda8bf 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -14,6 +14,10 @@ build_wheel_task: - wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-py39_4.12.0-MacOSX-arm64.sh -O ~/miniconda.sh - bash ~/miniconda.sh -b -p $HOME/miniconda3 - export PATH="$HOME/miniconda3/bin/:$PATH" + - conda create -n py3.9 python=3.9 + - conda create -n py3.10 python=3.10 + - conda create -n py3.11 python=3.11 + - conda create -n py3.12 python=3.12 software_cache: folder: $HOME/software @@ -31,24 +35,21 @@ build_wheel_task: wget - export LDFLAGS="-L/usr/local/opt/llvm/lib" - export CPPFLAGS="-I/usr/local/opt/llvm/include -fopenmp" - - conda info - - conda list - - which python - - pip install wget colored - - pip install cibuildwheel==2.11.2 - - conda install -c conda-forge qt==5.15.6 + - brew install qt - mkdir -p $HOME/software - cd $HOME/software - mkdir -p geant4 - cd geant4 + - rm -rf src bin data - mkdir -p src bin data - - if [ ! -d "src/source" ] ; then git clone --branch v11.1.1 https://github.com/Geant4/geant4.git --depth 1 src ; fi + - if [ ! -d "src/source" ] ; then git clone --branch v11.2.1 https://github.com/Geant4/geant4.git --depth 1 src ; fi - cd bin - cmake -DCMAKE_CXX_FLAGS=-std=c++17 -DGEANT4_INSTALL_DATA=OFF -DGEANT4_INSTALL_DATADIR=$HOME/software/geant4/data -DGEANT4_USE_QT=ON -DGEANT4_USE_OPENGL_X11=ON + -DGEANT4_USE_QT_QT6=ON -DGEANT4_BUILD_MULTITHREADED=ON -DGEANT4_USE_SYSTEM_EXPAT=OFF -DGEANT4_USE_GDML=ON @@ -57,6 +58,7 @@ build_wheel_task: - cd $HOME/software - mkdir -p itk - cd itk + - rm -rf src bin - mkdir -p src bin - if [ ! -d "src/CMake" ] ; then git clone --branch v5.2.1 https://github.com/InsightSoftwareConsortium/ITK.git --depth 1 src ; fi - cd bin @@ -69,22 +71,41 @@ build_wheel_task: - make -j4 opengate_core_script: - - echo $PWD - - ls $HOME/miniconda3/plugins/platforms + - conda info + - conda list + - conda init bash + - source ~/.bash_profile + - ls /opt/homebrew/share/qt/plugins/platforms - source $HOME/software/geant4/bin/geant4make.sh - export CMAKE_PREFIX_PATH=$HOME/software/geant4/bin:$HOME/software/itk/bin/:${CMAKE_PREFIX_PATH} - ls - cd core - mkdir opengate_core/plugins - - mkdir opengate_core/plugins/miniconda - - ls $HOME/miniconda3/lib/ - - rm -rf dist - - export CIBW_BEFORE_BUILD="python -m pip install colored; - python -c \"import os,delocate; print(os.path.join(os.path.dirname(delocate.__file__), 'tools.py'));quit()\" | xargs -I{} sed -i.\"\" \"s/first, /input.pop('i386',None); first, /g\" {}" - - python -m cibuildwheel --output-dir dist - - cd dist - - cd ../.. - - mv core/dist . + - cp -r /opt/homebrew/share/qt/plugins/platforms/* opengate_core/plugins/ + - cp -r /opt/homebrew/share/qt/plugins/imageformats/* opengate_core/plugins/ + - ls /opt/homebrew/lib + - cd .. + - mkdir all_dist + - | + for PYVERSION in 3.9 3.10 3.11 3.12; do + cd core + rm -rf dist + conda activate py$PYVERSION; + pip install wget colored + pip install wheel delocate + python setup.py sdist bdist_wheel + export DYLD_LIBRARY_PATH=$HOME/software/geant4/bin/BuildProducts/lib:/opt/homebrew/share/qt/plugins/platforms/:/opt/X11/lib/:$DYLD_LIBRARY_PATH:/opt/homebrew/lib + python -c "import os,delocate; print(os.path.join(os.path.dirname(delocate.__file__), 'tools.py'));quit()" | xargs -I{} sed -i."" "s/first, /input.pop('i386',None); first, /g" {} + delocate-listdeps --all dist/*.whl + delocate-wheel -w fixed_wheels -v dist/*.whl + rm -rf dist + ls fixed_wheels + delocate-listdeps --all fixed_wheels/*.whl + mv fixed_wheels dist + cd .. + cp core/dist/* all_dist/ + done + - mv all_dist dist binaries_artifacts: path: dist/* diff --git a/docs/source/user_guide_2_0_simulation.md b/docs/source/user_guide_2_0_simulation.md index b1a804a05..0957e49dc 100644 --- a/docs/source/user_guide_2_0_simulation.md +++ b/docs/source/user_guide_2_0_simulation.md @@ -87,10 +87,10 @@ The **verbosity**, i.e. the messages printed on the screen, are controlled via v ##### QT -It will start a Qt interface with `ui.visu_type = "qt"`. By default, the Geant4 visualisation commands are the ones provided in the file `opengate\mac\default_visu_commands.mac`. It can be changed with `self.visu_commands = gate.read_mac_file_to_commands('my_visu_commands.mac')`. +It will start a Qt interface with `ui.visu_type = "qt"`. By default, the Geant4 visualisation commands are the ones provided in the file `opengate\mac\default_visu_commands_qt.mac`. It can be changed with `self.visu_commands = gate.read_mac_file_to_commands('my_visu_commands.mac')`. -The visualisation with qt is still work in progress. First, it does not work on some linux systems (we don't know why yet). When a CT image is inserted in the simulation, every voxel should be drawn which is highly inefficient and cannot really be used. +The visualisation with qt is still work in progress. First, it does not work on some linux systems (we don't know why yet). With MacOS Qt6 is working but sometimes you need to set the library path properly before running python with: ```export DYLD_LIBRARY_PATH=//lib/python3.9/site-packages/opengate_core/plugins:$DYLD_LIBRARY_PATH```. When a CT image is inserted in the simulation, every voxel should be drawn which is highly inefficient and cannot really be used. ##### VRML