Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debye efficiency (macOS) #2882

Merged
merged 25 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions build_tools/get_external_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import requests
import platform
from enum import Enum

class OS(Enum):
Expand All @@ -11,7 +12,6 @@ def get_os():
"""
Get the operating system of the current machine.
"""
import platform
if platform.system() == "Windows":
return OS.WIN
elif platform.system() == "Linux":
Expand All @@ -23,25 +23,20 @@ def get_os():
def get_ausaxs():
_os = get_os()
url = "https://github.com/SasView/AUSAXS/releases/latest/download/"
libs = None
lib = None
if _os == OS.WIN:
libs = ["libausaxs.dll"]
lib = "libausaxs.dll"
elif _os == OS.LINUX:
libs = ["libausaxs.so"]
lib = "libausaxs.so"
elif _os == OS.MAC:
libs = ["libausaxs.dylib"]
if libs is not None:
lib = "libausaxs.dylib"
if lib is not None:
# we have to use a relative path since the package is not installed yet
base_loc = "src/sas/sascalc/calculator/ausaxs/lib/"
for lib in libs:
response = requests.get(url+lib)
response = requests.get(url+lib)

# disable macos for now by renaming the local file
if _os is OS.MAC:
lib = "libausaxs.dylib"

with open(base_loc+lib, "wb") as f:
f.write(response.content)
with open(base_loc+lib, "wb") as f:
f.write(response.content)

def fetch_external_dependencies():
#surround with try/except to avoid breaking the build if the download fails
Expand Down
3 changes: 1 addition & 2 deletions installers/sasview.spec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ datas = [
('../src/sas/qtgui/images', "sas/qtgui/images"),
('../src/sas/sasview/media', 'media'),
('../src/sas/example_data', 'example_data'),
('../src/sas/sascalc/calculator/ausaxs/lib', 'sas/sascalc/calculator/ausaxs/lib'),
('../src/sas/qtgui/Utilities/Reports/report_style.css', 'sas/qtgui/Utilities/Reports'),
('../src/sas/qtgui/Perspectives/Fitting/plugin_models', 'plugin_models'),
('../src/sas/qtgui/Utilities/WhatsNew/messages', 'sas/qtgui/Utilities/WhatsNew/messages'),
Expand Down Expand Up @@ -81,7 +80,7 @@ if platform.system() == 'Windows':
a = Analysis(
['sasview.py'],
pathex=[],
binaries=[],
binaries=[('../src/sas/sascalc/calculator/ausaxs/lib', 'sas/sascalc/calculator/ausaxs/lib')],
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
Expand Down
8 changes: 4 additions & 4 deletions src/sas/sascalc/calculator/ausaxs/ausaxs_sans_debye.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _attach_hooks():
with resources.as_file(resources.files("sas.sascalc.calculator.ausaxs.lib")) as loc:
ext = get_shared_lib_extension()
if (ext == ""):
logging.log("AUSAXS: Unsupported OS. Using default Debye implementation.")
logging.info("AUSAXS: Unsupported OS. Using default Debye implementation.")
return None, lib_state.FAILED

path = loc.joinpath("libausaxs" + ext)
Expand All @@ -45,7 +45,7 @@ def _attach_hooks():
ausaxs_state = lib_state.READY
except Exception as e:
ausaxs_state = lib_state.FAILED
logging.warning("Failed to hook into AUSAXS library, using default Debye implementation")
logging.warning("AUSAXS: Failed to hook into external library; using default Debye implementation")
print(e)
return ausaxs, ausaxs_state

Expand Down Expand Up @@ -118,7 +118,7 @@ def evaluate_sans_debye(q, coords, w):
status = queue.get_nowait()
first_time = False
else:
logging.warning(f"AUSAXS calculator seems to have crashed (exit code \"{p.exitcode}\"). Using default Debye implementation instead.")
logging.warning(f"AUSAXS: External library seems to have crashed (exit code \"{p.exitcode}\"). Using default Debye implementation instead.")
ausaxs_state = lib_state.FAILED
return sasview_sans_debye(q, coords, w)

Expand All @@ -132,7 +132,7 @@ def evaluate_sans_debye(q, coords, w):
Iq, status = _invoke(q, coords, w)

if (status != 0):
logging.warning(f"AUSAXS calculator terminated unexpectedly (error code \"{status}\"). Using default Debye implementation instead.")
logging.warning(f"AUSAXS: External library evaluation terminated unexpectedly (error code \"{status}\"). Using default Debye implementation instead.")
return sasview_sans_debye(q, coords, w)

return Iq
9 changes: 2 additions & 7 deletions test/sascalculator/utest_sas_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,6 @@ def test_debye_impl(self):

rng = np.random.default_rng(1984)

from sas.sascalc.calculator.ausaxs.architecture import get_os, OS
if get_os() is OS.MAC:
self.assertTrue(True, "AUSAXS library is currently not available for MacOS. Skipping test.")
return

if not ausaxs_sans_debye.ausaxs_available():
self.assertTrue(False, "AUSAXS library not found, test cannot be run.")
return
Expand All @@ -257,7 +252,7 @@ def test_debye_impl(self):
errs = (external - analytical)/analytical
different_entries = 0
for val in np.abs(errs):
self.assertLessEqual(val, 0.01, "Ensure that the error is acceptable.")
self.assertLessEqual(val, 0.02, "Ensure that the error is acceptable.")
if val != 0:
different_entries += 1
self.assertTrue(different_entries > len(q)*0.5, "Check that two different algorithms were actually run.")
Expand All @@ -273,7 +268,7 @@ def test_debye_impl(self):

errs = (external - analytical)/analytical
for val in np.abs(errs):
self.assertLessEqual(val, 0.01)
self.assertLessEqual(val, 0.02)

def test_calculator_elements(self):
"""
Expand Down
Loading