Skip to content

Commit 4f8fc11

Browse files
authored
Update to v4 (#39)
* Initial update to Horace 4 (parallel not working) * Fix parallel Horace. Update SpinW to v4. * Update build system * Using spinw.mltbx instead of git in order to get all mex * Downloading both Windows and Linux Horace to get both mex * Fix setup.py to generate universal wheels * Add new patch_ctf target which cleans CTF dir and patches Horace * Fix bug if MCR dir defined in env variable * Add stripping mex from ctf to wheel build * Remove test sqw files from Horace CTF. * Update C++ files to libpymcr-0.2 * Update req to libpymcr-0.2. Update ctf recombine initialisation * Fix numpy2 bug and failing catch causing GIL deadlock * Update to libpymcr 0.2.1 - refactor call_python; add rel notes * Workaround for twine bug #1216
1 parent b7573e3 commit 4f8fc11

30 files changed

+532
-1589
lines changed

.github/workflows/upload_pypi.yml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
run: |
2121
python -m pip install --upgrade pip
2222
python -m pip install twine pyyaml importlib-resources
23+
python -m pip install --upgrade packaging
2324
2425
- name: Publish wheels to PyPI
2526
env:

.gitignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pace_neutrons/\.DS_Store
88
__pycache__
99
pace_python/mccExcludedFiles.log
1010
pace_neutrons/mccExcludedFiles.log
11+
pace_neutrons/ctfs
1112

1213
*~
1314
*swp
@@ -36,10 +37,12 @@ CMakeCache.txt
3637
extern-pybind11
3738
src/CTF
3839

40+
bld
3941
build
4042
buildctf
4143
dist
4244
wheelhouse
45+
*.whl
4346

4447
installer/Pace_Python_Installer/
4548
installer/mccExcludedFiles.log
@@ -49,7 +52,9 @@ installer/pace_python_installer
4952
installer/pace_neutrons_installer
5053
installer/readme.txt
5154
installer/requiredMCRProducts.txt
52-
55+
installer/unresolvedSymbols.txt
56+
pace_neutrons_installer*install
57+
pace_neutrons_installer*exe
5358
requiredMCRProducts.txt
5459

5560
euphonic_sqw_models
@@ -60,6 +65,7 @@ cmake/print_git/CMakeCache.txt
6065
cmake/print_git/*.cmake
6166
cmake/print_git/*.vcxproj
6267
cmake/print_git/*.sln
68+
*.vcxproj.filters
6369

6470
success
6571

@@ -73,3 +79,5 @@ test/demo
7379

7480
tmp
7581
temp
82+
83+
.ipynb_checkpoints/

CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# [v0.4.0](https://github.com/pace-neutrons/pace-python/compare/v0.3.0a0...v0.4.0)
2+
3+
Updated to Horace 4.0.0
4+
5+
* New features
6+
- Updated to use libpymcr [v0.2.1](https://github.com/pace-neutrons/libpymcr/releases/tag/v0.2.1)
7+
- Features from that include: specifying function handle using the `@` operator,
8+
use of `Ctrl+C` to interrrupt Matlab execution, better formatting of Matlab output
9+
10+
* Bugfixes
11+
- Now have `ctf` for Matlab R2021b to R2024b included in distribution.
12+
- Support for Python 3.13 added, support for Python 3.7 dropped.
13+
14+
115
# [v0.3.0a1](https://github.com/pace-neutrons/pace-python/compare/v0.2.0...v0.3.0a0)
216

317
* New features

CITATION.cff

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ authors:
2929
- family-names: "Wilkins"
3030
given-names: "Jacob"
3131
title: "pace_neutrons"
32-
version: "0.3.0a1"
32+
version: "0.4.0"
3333
date-released: "2021-07-13"
3434
license: "GPL-3.0-only"
3535
repository: "https://github.com/pace-neutrons/pace-python"

CMakeLists.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required (VERSION 3.12)
1+
cmake_minimum_required (VERSION 3.15)
22

33
project("pace-python" VERSION "0.1.0")
44

@@ -21,7 +21,7 @@ option(WITH_SPINW "Include SpinW" ON)
2121
set(HORACE_PATH "" CACHE PATH "Sets the path of external Horace. If unset, downloads the version set with HORACE_VERSION")
2222
set(SPINW_PATH "" CACHE PATH "Sets the path of external Horace. If unset, downloads the version set with SPINW_VERSION")
2323

24-
set(SPINW_REPO "mducle/spinw" CACHE STRING "Sets the git repo used to download SpinW")
24+
set(SPINW_REPO "spinw/spinw" CACHE STRING "Sets the git repo used to download SpinW")
2525

2626
#Gets Horace version number
2727
if(WITH_HORACE AND HORACE_PATH)
@@ -32,7 +32,8 @@ if(WITH_HORACE AND HORACE_PATH)
3232
endif()
3333
set(HORACE_VERSION ${HORACE_SRC_VERSION} CACHE STRING "Horace version number")
3434
elseif(WITH_HORACE AND NOT HORACE_PATH AND NOT DEFINED HORACE_VERSION)
35-
set(HORACE_VERSION 3.6.3 CACHE STRING "Sets the Horace release version number to download")
35+
set(HORACE_VERSION 4.0.0 CACHE STRING "Sets the Horace release version number to download")
36+
set(GH_MATLAB_VERSION R2021a CACHE STRING "Sets the Matlab release version number to download")
3637
endif()
3738

3839
#Gets SpinW version number
@@ -45,7 +46,7 @@ if(WITH_SPINW AND SPINW_PATH)
4546
endif()
4647
set(SPINW_VERSION ${SPINW_SRC_VERSION} CACHE STRING "SpinW version number")
4748
elseif(WITH_SPINW AND NOT SPINW_PATH AND NOT DEFINED SPINW_VERSION)
48-
set(SPINW_VERSION e3e57aae432f6737aff81d31ccda6e7dce741cef CACHE STRING "Sets the SpinW version (git tag/branch/hash) to download")
49+
set(SPINW_VERSION 4.0.0 CACHE STRING "Sets the SpinW version (git tag/branch/hash) to download")
4950
endif()
5051

5152

build_ctf.m

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function build_ctf(cmake_bindir)
2+
out_dir = 'ctfs';
3+
VERSION = version('-release');
4+
package_name = ['pace_', VERSION];
5+
full_package = ['pace_', VERSION, '.ctf'];
6+
7+
if nargin < 1
8+
cmake_bindir = 'buildtmp';
9+
end
10+
if ~exist('ctfs', 'dir')
11+
mkdir('ctfs')
12+
end
13+
mcc('-U', '-W', ['CTF:' package_name], '-N', ....
14+
'-d', out_dir, ...
15+
'src/call.m', ...
16+
'src/pyclasswrapper.m', ...
17+
'src/pyhorace_init.m', ...
18+
'-a', fullfile(cmake_bindir, 'CTF'))
19+
end

cmake/PACE.cmake

+36-31
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
include(ExternalProject)
22

3-
message(STATUS "Obtaining desired PACE components")
3+
message(STATUS "Obtaining desired PACE components")
44

55
if(WITH_SPINW)
66
if(SPINW_PATH)
7-
# checks if provided SpinW path is correct and
7+
# checks if provided SpinW path is correct and
88
# includes it if it exists
99
find_file(SPINW_FOUND
1010
NAMES "install_spinw.m"
@@ -16,30 +16,30 @@ if(WITH_SPINW)
1616
endif()
1717
message(STATUS "SpinW found at: ${SPINW_PATH}")
1818

19-
ExternalProject_Add(spinw
19+
ExternalProject_Add(spinw
2020
SOURCE_DIR "${SPINW_PATH}"
2121
DOWNLOAD_COMMAND ""
2222
CONFIGURE_COMMAND ""
23-
BUILD_COMMAND ""
23+
BUILD_COMMAND ""
2424
INSTALL_COMMAND ""
2525
)
2626
else()
2727

28-
#downloads desired SpinW version and includes it in the project
29-
message(STATUS "Downloading SpinW from https://github.com/${SPINW_REPO}.git @ ${SPINW_VERSION}")
28+
# downloads desired SpinW version and includes it in the project
29+
message(STATUS "Downloading SpinW version ${SPINW_VERSION}")
3030
ExternalProject_Add(spinw
31-
GIT_REPOSITORY https://github.com/${SPINW_REPO}.git
32-
GIT_TAG ${SPINW_VERSION}
33-
GIT_SHALLOW 1
31+
URL https://github.com/spinw/spinw/releases/download/v${SPINW_VERSION}/spinw.mltbx
3432
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/CTF/SpinW"
33+
SOURCE_DIR
3534
CONFIGURE_COMMAND ""
36-
BUILD_COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/swfiles <BINARY_DIR>/swfiles
37-
COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/external <BINARY_DIR>/external
38-
COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/dat_files <BINARY_DIR>/dat_files
35+
BUILD_COMMAND
36+
COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/fsroot/swfiles <BINARY_DIR>/swfiles
37+
COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/fsroot/external <BINARY_DIR>/external
38+
COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/fsroot/dat_files <BINARY_DIR>/dat_files
3939
INSTALL_COMMAND ""
4040
TEST_COMMAND ""
4141
)
42-
42+
4343
endif()
4444

4545
else()
@@ -50,47 +50,52 @@ endif()
5050
if(WITH_HORACE)
5151
if(HORACE_PATH)
5252
#Searches for the horace_version.m file to check whether horace can be found in the provided dir
53-
#ISSUE: different horace versions may have different dir structure
54-
find_file(HORACE_FOUND
53+
#ISSUE: different horace versions may have different dir structure
54+
find_file(HORACE_FOUND
5555
NAMES "horace_version.m"
5656
PATHS "${HORACE_PATH}/horace_core/admin"
5757
NO_CACHE
5858
)
5959

6060
if(NOT HORACE_FOUND)
61-
message(FATAL_ERROR "Horace may not exist at ${HORACE_PATH}")
61+
message(FATAL_ERROR "Horace may not exist at ${HORACE_PATH}")
6262
endif()
6363
message(STATUS "Horace found: ${HORACE_PATH}")
6464

6565
#includes the located version of Horace in the current project
66-
ExternalProject_Add(horace
66+
ExternalProject_Add(horace
6767
SOURCE_DIR ${HORACE_PATH}
6868
DOWNLOAD_COMMAND "" #empty quotation marks effectively disables the download feature of ExternalProject_Add
6969
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/CTF"
7070
)
7171

7272
else()
7373

74-
#downloads desired Horace version suitable for the users OS
75-
if(WIN32)
76-
set(HORACE_TYPE "win64")
77-
set(FILE_EXTENSION "zip")
78-
else()
79-
set(HORACE_TYPE "linux")
80-
set(FILE_EXTENSION "tar.gz")
81-
endif()
82-
83-
message(STATUS "Downloading Horace from https://github.com/pace-neutrons/Horace/releases/download/v${HORACE_VERSION}/Horace-${HORACE_VERSION}-${HORACE_TYPE}-R2019b.zip")
84-
ExternalProject_Add(horace
85-
URL https://github.com/pace-neutrons/Horace/releases/download/v${HORACE_VERSION}/Horace-${HORACE_VERSION}-${HORACE_TYPE}-R2019b.${FILE_EXTENSION}
74+
# downloads desired Horace versions for both Linux and Windows (to get both sets of mex files)
75+
message(STATUS "Downloading Horace from https://github.com/pace-neutrons/Horace/releases/download/v${HORACE_VERSION}/Horace-${HORACE_VERSION}-linux-${GH_MATLAB_VERSION}.tar.gz")
76+
ExternalProject_Add(horace_linux
77+
URL https://github.com/pace-neutrons/Horace/releases/download/v${HORACE_VERSION}/Horace-${HORACE_VERSION}-linux-${GH_MATLAB_VERSION}.tar.gz
8678
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/CTF"
87-
SOURCE_DIR
79+
SOURCE_DIR
8880
CONFIGURE_COMMAND ""
8981
BUILD_COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/Horace <BINARY_DIR>/Horace
90-
COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/Herbert <BINARY_DIR>/Herbert
82+
COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/worker_v4.m.template <BINARY_DIR>/worker_v4.m
9183
INSTALL_COMMAND ""
9284
TEST_COMMAND ""
9385
)
86+
message(STATUS "Downloading Horace from https://github.com/pace-neutrons/Horace/releases/download/v${HORACE_VERSION}/Horace-${HORACE_VERSION}-win64-${GH_MATLAB_VERSION}.zip")
87+
ExternalProject_Add(horace_win
88+
URL https://github.com/pace-neutrons/Horace/releases/download/v${HORACE_VERSION}/Horace-${HORACE_VERSION}-win64-${GH_MATLAB_VERSION}.zip
89+
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/CTF"
90+
SOURCE_DIR
91+
CONFIGURE_COMMAND ""
92+
BUILD_COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/Horace/horace_core/DLL/_PCWIN64 <BINARY_DIR>/Horace/horace_core/DLL/_PCWIN64
93+
INSTALL_COMMAND ""
94+
TEST_COMMAND ""
95+
)
96+
add_custom_target(horace ALL)
97+
add_dependencies(horace horace_linux horace_win)
98+
9499
endif()
95100

96101
else()

cmake/copy_and_remove_0.ps1

-3
This file was deleted.

cmake/patch_horace.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys, os, re
2+
import warnings
23

34
FUZZ = 10
45

@@ -55,4 +56,8 @@ def patch_files(diff_file, base_dir):
5556
# Recursively applies all diffs in a given folder w.r.t. an input base dir
5657
for root, _, files in os.walk(sys.argv[1]):
5758
for fl in [f for f in files if f.endswith('.diff')]:
58-
patch_files(os.path.join(root, fl), sys.argv[2])
59+
try:
60+
patch_files(os.path.join(root, fl), sys.argv[2])
61+
except ValueError as e:
62+
if 'Unmatched hunk' in str(e): # Probably patched already
63+
warnings.warn(str(e))

cmake/remove_nonctf.ps1

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Get-ChildItem "$($args[0])" -recurse | where-object {$_.length -eq 0} | ?{Remove-Item $_.fullname}
2+
Get-ChildItem "$($args[0])" -recurse | where-object {$_.Name -match "_docify"} | ?{Remove-Item $_.fullname -recurse}
3+
Get-ChildItem "$($args[0])" -recurse | where-object {($_.Name -match "@*_old") -and ($_.GetType().Name -eq "DirectoryInfo")} | ?{Remove-Item $_.fullname -recurse}
4+
Get-ChildItem "$($args[0])" -recurse | where-object {($_.Name -match "@testsigvar") -and ($_.GetType().Name -eq "DirectoryInfo")} | ?{Remove-Item $_.fullname -recurse}
5+
Get-ChildItem "$($args[0])" -recurse | where-object {$_.Name -match "compute_bin_data_mex_.m"} | ?{Remove-Item $_.fullname -recurse}
6+
Get-ChildItem "$($args[0])" -recurse | where-object {$_.Name -match "w*data.sqw"} | ?{Remove-Item $_.fullname -recurse}

cmake/copy_and_remove_0.sh renamed to cmake/remove_nonctf.sh

+3
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ find "$1" -name _docify -exec rm -rf '{}' \;
33
find "$1" -name .git -exec rm -rf '{}' \;
44
find "$1" -size 0 -exec rm -f '{}' \;
55
find "$1" -name "@*_old" -exec rm -rf '{}' \;
6+
find "$1" -name "@testsigvar" -exec rm -rf '{}' \;
7+
find "$1" -name "compute_bin_data_mex_.m" -exec rm -rf '{}' \;
8+
find "$1" -name "w*data.sqw" -exec rm -rf '{}' \;
69

710
exit 0

mcc_all.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from libpymcr.utils import checkPath, stripmex
2+
import os
3+
import sys
4+
import subprocess
5+
6+
if __name__ == '__main__':
7+
firstrun = True
8+
for v in ['R2021b', 'R2022a', 'R2022b', 'R2023a', 'R2023b', 'R2024a', 'R2024b']:
9+
print(f'Compiling for {v}')
10+
mlPath = checkPath(v, error_if_not_found=False, suppress_output=True)
11+
if mlPath is not None:
12+
rv = subprocess.run([os.path.join(mlPath, 'bin', 'matlab'), '-batch', 'build_ctf'], capture_output=True)
13+
if rv.returncode != 0:
14+
print(rv.stdout.decode())
15+
print(rv.stderr.decode())
16+
else:
17+
stripmex(v, ctfdir='ctfs', writemex=firstrun)
18+
if firstrun:
19+
firstrun = False
20+
else:
21+
print(f'Matlab {v} not found')

0 commit comments

Comments
 (0)