Skip to content

Commit 929b714

Browse files
authored
Unify save methods, refactor plots, enable OpenMP windows(#180)
1 parent f978f4c commit 929b714

File tree

10 files changed

+143
-87
lines changed

10 files changed

+143
-87
lines changed

.github/workflows/build_wheel.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: true
1313
matrix:
14-
platform: [windows-latest, ubuntu-latest, macos-13, macos-14]
14+
platform: [windows-2022, ubuntu-latest, macos-13, macos-14]
1515
env:
1616
CIBW_SKIP: 'pp*'
1717
CIBW_ARCHS: 'auto64'
@@ -34,19 +34,19 @@ jobs:
3434
- name: Install OMP (MacOS Intel)
3535
if: matrix.platform == 'macos-13'
3636
run: |
37-
brew install llvm libomp
38-
echo "export CC=/usr/local/opt/llvm/bin/clang" >> ~/.bashrc
39-
echo "export CXX=/usr/local/opt/llvm/bin/clang++" >> ~/.bashrc
37+
brew install llvm@20 libomp
38+
echo "export CC=/usr/local/opt/llvm@20/bin/clang" >> ~/.bashrc
39+
echo "export CXX=/usr/local/opt/llvm@20/bin/clang++" >> ~/.bashrc
4040
echo "export CFLAGS=\"$CFLAGS -I/usr/local/opt/libomp/include\"" >> ~/.bashrc
4141
echo "export CXXFLAGS=\"$CXXFLAGS -I/usr/local/opt/libomp/include\"" >> ~/.bashrc
4242
echo "export LDFLAGS=\"$LDFLAGS -Wl,-rpath,/usr/local/opt/libomp/lib -L/usr/local/opt/libomp/lib -lomp\"" >> ~/.bashrc
4343
source ~/.bashrc
4444
- name: Install OMP (MacOS M1)
4545
if: matrix.platform == 'macos-14'
4646
run: |
47-
brew install llvm libomp
48-
echo "export CC=/opt/homebrew/opt/llvm/bin/clang" >> ~/.bashrc
49-
echo "export CXX=/opt/homebrew/opt/llvm/bin/clang++" >> ~/.bashrc
47+
brew install llvm@20 libomp
48+
echo "export CC=/opt/homebrew/opt/llvm@20/bin/clang" >> ~/.bashrc
49+
echo "export CXX=/opt/homebrew/opt/llvm@20/bin/clang++" >> ~/.bashrc
5050
echo "export CFLAGS=\"$CFLAGS -I/opt/homebrew/opt/libomp/include\"" >> ~/.bashrc
5151
echo "export CXXFLAGS=\"$CXXFLAGS -I/opt/homebrew/opt/libomp/include\"" >> ~/.bashrc
5252
echo "export LDFLAGS=\"$LDFLAGS -Wl,-rpath,/opt/homebrew/opt/libomp/lib -L/opt/homebrew/opt/libomp/lib -lomp\"" >> ~/.bashrc

.github/workflows/run_tests.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
platform: [windows-latest, ubuntu-latest, macos-13, macos-14]
22+
platform: [windows-2022, ubuntu-latest, macos-13, macos-14]
2323
version: ["3.10", "3.13"]
2424
defaults:
2525
run:
@@ -38,19 +38,19 @@ jobs:
3838
- name: Install OMP (MacOS Intel)
3939
if: matrix.platform == 'macos-13'
4040
run: |
41-
brew install llvm libomp
42-
echo "export CC=/usr/local/opt/llvm/bin/clang" >> ~/.bashrc
43-
echo "export CXX=/usr/local/opt/llvm/bin/clang++" >> ~/.bashrc
41+
brew install llvm@20 libomp
42+
echo "export CC=/usr/local/opt/llvm@20/bin/clang" >> ~/.bashrc
43+
echo "export CXX=/usr/local/opt/llvm@20/bin/clang++" >> ~/.bashrc
4444
echo "export CFLAGS=\"$CFLAGS -I/usr/local/opt/libomp/include\"" >> ~/.bashrc
4545
echo "export CXXFLAGS=\"$CXXFLAGS -I/usr/local/opt/libomp/include\"" >> ~/.bashrc
4646
echo "export LDFLAGS=\"$LDFLAGS -Wl,-rpath,/usr/local/opt/libomp/lib -L/usr/local/opt/libomp/lib -lomp\"" >> ~/.bashrc
4747
source ~/.bashrc
4848
- name: Install OMP (MacOS M1)
4949
if: matrix.platform == 'macos-14'
5050
run: |
51-
brew install llvm libomp
52-
echo "export CC=/opt/homebrew/opt/llvm/bin/clang" >> ~/.bashrc
53-
echo "export CXX=/opt/homebrew/opt/llvm/bin/clang++" >> ~/.bashrc
51+
brew install llvm@20 libomp
52+
echo "export CC=/opt/homebrew/opt/llvm@20/bin/clang" >> ~/.bashrc
53+
echo "export CXX=/opt/homebrew/opt/llvm@20/bin/clang++" >> ~/.bashrc
5454
echo "export CFLAGS=\"$CFLAGS -I/opt/homebrew/opt/libomp/include\"" >> ~/.bashrc
5555
echo "export CXXFLAGS=\"$CXXFLAGS -I/opt/homebrew/opt/libomp/include\"" >> ~/.bashrc
5656
echo "export LDFLAGS=\"$LDFLAGS -Wl,-rpath,/opt/homebrew/opt/libomp/lib -L/opt/homebrew/opt/libomp/lib -lomp\"" >> ~/.bashrc

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ mark-parentheses = false
3838
[tool.ruff.lint.pydocstyle]
3939
convention = "numpy"
4040

41-
41+
[tool.ruff.lint.isort]
42+
known-first-party = ["ratapi.rat_core"]

ratapi/controls.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,16 @@ def delete_IPC(self):
233233
os.remove(self._IPCFilePath)
234234
return None
235235

236-
def save(self, path: Union[str, Path], filename: str = "controls"):
236+
def save(self, filepath: Union[str, Path] = "./controls.json"):
237237
"""Save a controls object to a JSON file.
238238
239239
Parameters
240240
----------
241-
path : str or Path
242-
The directory in which the controls object will be written.
243-
filename : str
244-
The name for the JSON file containing the controls object.
245-
241+
filepath : str or Path
242+
The path to where the controls file will be written.
246243
"""
247-
file = Path(path, f"{filename.removesuffix('.json')}.json")
248-
file.write_text(self.model_dump_json())
244+
filepath = Path(filepath).with_suffix(".json")
245+
filepath.write_text(self.model_dump_json())
249246

250247
@classmethod
251248
def load(cls, path: Union[str, Path]) -> "Controls":

ratapi/examples/domains/domains_XY_model.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Custom model file for the domains custom XY example."""
22

3-
import math
3+
from math import sqrt
44

55
import numpy as np
6+
from scipy.special import erf
67

78

89
def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
@@ -19,13 +20,13 @@ def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
1920
z = np.arange(0, 141)
2021

2122
# Make the volume fraction distribution for our Silicon substrate
22-
[vfSilicon, siSurf] = makeLayer(z, -25, 50, 1, subRough, subRough)
23+
[vfSilicon, siSurf] = make_layer(z, -25, 50, 1, subRough, subRough)
2324

2425
# ... and the Oxide ...
25-
[vfOxide, oxSurface] = makeLayer(z, siSurf, oxideThick, 1, subRough, subRough)
26+
[vfOxide, oxSurface] = make_layer(z, siSurf, oxideThick, 1, subRough, subRough)
2627

2728
# ... and also our layer.
28-
[vfLayer, laySurface] = makeLayer(z, oxSurface, layerThick, 1, subRough, layerRough)
29+
[vfLayer, laySurface] = make_layer(z, oxSurface, layerThick, 1, subRough, layerRough)
2930

3031
# Everything that is not already occupied will be filled will water
3132
totalVF = vfSilicon + vfOxide + vfLayer
@@ -53,7 +54,7 @@ def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
5354
return SLD, subRough
5455

5556

56-
def makeLayer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
57+
def make_layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
5758
"""Produce a layer, with a defined thickness, height and roughness.
5859
5960
Each side of the layer has its own roughness value.
@@ -63,12 +64,9 @@ def makeLayer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
6364
right = prevLaySurf + thickness
6465

6566
# Make our heaviside
66-
a = (z - left) / ((2**0.5) * Sigma_L)
67-
b = (z - right) / ((2**0.5) * Sigma_R)
67+
erf_left = erf((z - left) / (sqrt(2) * Sigma_L))
68+
erf_right = erf((z - right) / (sqrt(2) * Sigma_R))
6869

69-
erf_a = np.array([math.erf(value) for value in a])
70-
erf_b = np.array([math.erf(value) for value in b])
71-
72-
VF = np.array((height / 2) * (erf_a - erf_b))
70+
VF = np.array((0.5 * height) * (erf_left - erf_right))
7371

7472
return VF, right

ratapi/examples/normal_reflectivity/custom_XY_DSPC.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""A custom XY model for a supported DSPC bilayer."""
22

3-
import math
3+
from math import sqrt
44

55
import numpy as np
6+
from scipy.special import erf
67

78

89
def custom_XY_DSPC(params, bulk_in, bulk_out, contrast):
@@ -51,10 +52,10 @@ def custom_XY_DSPC(params, bulk_in, bulk_out, contrast):
5152
z = np.arange(0, 141)
5253

5354
# Make our Silicon substrate
54-
vfSilicon, siSurf = layer(z, -25, 50, 1, subRough, subRough)
55+
vfSilicon, siSurf = make_layer(z, -25, 50, 1, subRough, subRough)
5556

5657
# Add the Oxide
57-
vfOxide, oxSurface = layer(z, siSurf, oxideThick, 1, subRough, subRough)
58+
vfOxide, oxSurface = make_layer(z, siSurf, oxideThick, 1, subRough, subRough)
5859

5960
# We fill in the water at the end, but there may be a hydration layer between the bilayer and the oxide,
6061
# so we start the bilayer stack an appropriate distance away
@@ -65,15 +66,15 @@ def custom_XY_DSPC(params, bulk_in, bulk_out, contrast):
6566
headThick = vHead / lipidAPM
6667

6768
# ... and make a box for the volume fraction (1 for now, we correct for coverage later)
68-
vfHeadL, headLSurface = layer(z, watSurface, headThick, 1, bilayerRough, bilayerRough)
69+
vfHeadL, headLSurface = make_layer(z, watSurface, headThick, 1, bilayerRough, bilayerRough)
6970

7071
# ... also do the same for the tails
7172
# We'll make both together, so the thickness will be twice the volume
7273
tailsThick = (2 * vTail) / lipidAPM
73-
vfTails, tailsSurf = layer(z, headLSurface, tailsThick, 1, bilayerRough, bilayerRough)
74+
vfTails, tailsSurf = make_layer(z, headLSurface, tailsThick, 1, bilayerRough, bilayerRough)
7475

7576
# Finally the upper head ...
76-
vfHeadR, headSurface = layer(z, tailsSurf, headThick, 1, bilayerRough, bilayerRough)
77+
vfHeadR, headSurface = make_layer(z, tailsSurf, headThick, 1, bilayerRough, bilayerRough)
7778

7879
# Making the model
7980
# We've created the volume fraction profiles corresponding to each of the groups.
@@ -114,12 +115,12 @@ def custom_XY_DSPC(params, bulk_in, bulk_out, contrast):
114115
totSLD = sldSilicon + sldOxide + sldHeadL + sldTails + sldHeadR + sldWat
115116

116117
# Make the SLD array for output
117-
SLD = [[a, b] for (a, b) in zip(z, totSLD)]
118+
SLD = np.column_stack((z, totSLD))
118119

119120
return SLD, subRough
120121

121122

122-
def layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
123+
def make_layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
123124
"""Produce a layer, with a defined thickness, height and roughness.
124125
125126
Each side of the layer has its own roughness value.
@@ -129,12 +130,9 @@ def layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
129130
right = prevLaySurf + thickness
130131

131132
# Make our heaviside
132-
a = (z - left) / ((2**0.5) * Sigma_L)
133-
b = (z - right) / ((2**0.5) * Sigma_R)
133+
erf_left = erf((z - left) / (sqrt(2) * Sigma_L))
134+
erf_right = erf((z - right) / (sqrt(2) * Sigma_R))
134135

135-
erf_a = np.array([math.erf(value) for value in a])
136-
erf_b = np.array([math.erf(value) for value in b])
137-
138-
VF = np.array((height / 2) * (erf_a - erf_b))
136+
VF = np.array((0.5 * height) * (erf_left - erf_right))
139137

140138
return VF, right

0 commit comments

Comments
 (0)