Skip to content

Commit b557c59

Browse files
authored
Merge pull request #20 from EMSL-Computing/joss-edits
Joss edits complete
2 parents 652ab27 + 1b01f14 commit b557c59

File tree

4 files changed

+50
-32
lines changed

4 files changed

+50
-32
lines changed

examples/example_7_flow_2d_pinn_on_XCT.ipynb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@
236236
],
237237
"source": [
238238
"# Plot for the Boundary conditions and collocation for training \n",
239-
"x_b1, y_b1, bc_1, x_b2, y_b2, bc_2, x_b3, y_b3, bc_3, x_b4, y_b4, bc_4, x_c, y_c, conds, colloc = generate_BCs_and_colloc_xct(X, Y, norm_P1, norm_P2, dP_dy1, dP_dy2) \n",
239+
"x_b1, y_b1, bc_1, x_b2, y_b2, bc_2, x_b3, y_b3, bc_3, x_b4, y_b4, bc_4, x_c, y_c, conds, colloc = generate_BCs_and_colloc_xct(X, Y, norm_P1, \n",
240+
" norm_P2, dP_dy1, \n",
241+
" dP_dy2) \n",
240242
"plot_boundary_conditions(x_b1, y_b1, bc_1*max_P, x_b2, y_b2, bc_2*max_P, x_b3, y_b3, bc_3*max_P, x_b4, y_b4, bc_4*max_P, x_c, y_c, results_dir)"
241243
]
242244
},
@@ -310,7 +312,17 @@
310312
"print('-------------------------------------------------------')\n",
311313
"\n",
312314
"# PINN training\n",
313-
"best_params, best_loss, all_losses, all_epochs = train_PINN(params, epochs, optimizer, loss_fun, colloc, conds, norm_coeff, hidden_layers, hidden_nodes, lr, results_dir)"
315+
"best_params, best_loss, all_losses, all_epochs = train_PINN(params, \n",
316+
" epochs, \n",
317+
" optimizer, \n",
318+
" loss_fun, \n",
319+
" colloc, \n",
320+
" conds, \n",
321+
" norm_coeff, \n",
322+
" hidden_layers, \n",
323+
" hidden_nodes, \n",
324+
" lr, \n",
325+
" results_dir)"
314326
]
315327
},
316328
{

src/pore2chip/metrics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
from skimage.measure import label, regionprops
33
import feret
4-
from porespy import networks, networks, filters
4+
from porespy import networks, networks, filters, metrics
55
import openpnm as op
66
import copy
77
from skimage.segmentation import watershed
@@ -118,12 +118,12 @@ def extract_diameters2(img_list, voxel_size=1, sigma_val=0.4):
118118
sigma = sigma_val
119119
dt = spim.distance_transform_edt(input=img_list)
120120
dt1 = spim.gaussian_filter(input=dt, sigma=sigma)
121-
peaks = ps.filters.find_peaks(dt=dt)
121+
peaks = filters.find_peaks(dt=dt)
122122

123123
#print('Initial number of peaks: ', spim.label(peaks)[1])
124-
peaks = ps.filters.trim_saddle_points(peaks=peaks, dt=dt1)
124+
peaks = filters.trim_saddle_points(peaks=peaks, dt=dt1)
125125
#print('Peaks after trimming saddle points: ', spim.label(peaks)[1])
126-
peaks = ps.filters.trim_nearby_peaks(peaks=peaks, dt=dt)
126+
peaks = filters.trim_nearby_peaks(peaks=peaks, dt=dt)
127127
peaks, N = spim.label(peaks)
128128
#print('Peaks after trimming nearby peaks: ', N)
129129

tests/test_metrics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import time
44
import numpy as np
5+
import porespy as ps # ✅ Add this line to fix the NameError
56
from skimage.draw import ellipse
67
from pathlib import Path
78
from porespy.generators import cylinders

tests/test_train_pinn.py

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,36 @@ class TestTrainPINN(unittest.TestCase):
3636
- Different optimizers and loss functions: Ensures the function works correctly with various optimizers and loss functions.
3737
- Multiple layers and nodes: Tests the function with different feed-forward neural network architectures.
3838
"""
39-
39+
4040
def setUp(self):
4141
"""
4242
Sets up the test environment and initializes common test parameters.
43-
The `setUp` method is called before every test function in this class.
44-
It initializes the parameters, optimizer, and other inputs used by
45-
the `train_PINN` function.
43+
Ensures `weights` and `colloc` are not equal to test loss properly.
4644
"""
47-
# Initialize common test parameters
45+
# Initialize weights and collocation points to be different
4846
self.params = [{
4947
'weights': jnp.array([1.0, 2.0]), # Initial weights
50-
'biases': jnp.array([0.5]) # Initial biases
48+
'biases': jnp.array([0.5])
5149
}]
52-
self.epochs = 100 # Number of training epochs
53-
self.optimizer = optax.adam(
54-
0.001) # Adam optimizer with learning rate 0.001
50+
self.colloc = jnp.array([3.0, -1.0]) # Different from weights to ensure meaningful loss
51+
assert not jnp.array_equal(self.params[0]['weights'], self.colloc), \
52+
"Initial weights and collocation points should not be equal."
53+
54+
self.epochs = 100
55+
self.optimizer = optax.adam(0.1)
5556
self.loss_fun = lambda params, colloc, conds, norm_coeff: jnp.mean(
56-
(params[0]['weights'] - colloc)**2) # Simple loss function
57-
self.colloc = jnp.array([1.0, 2.0]) # Collocation points
58-
self.conds = [jnp.array([1.0, 2.0])] # Boundary conditions
59-
self.norm_coeff = jnp.array([1.0]) # Normalization coefficient
60-
self.hidden_layers = 2 # Number of hidden layers in the neural network
61-
self.hidden_nodes = 10 # Number of hidden nodes for each layer
62-
self.lr = 0.001 # Learning rate for the optimizer
63-
self.results_dir = './results/' # Results directory to save the .pkl file
64-
65-
# Create results directory if it doesn't exist
57+
(params[0]['weights'] - colloc) ** 2)
58+
self.conds = [jnp.array([1.0, 2.0])]
59+
self.norm_coeff = jnp.array([1.0])
60+
self.hidden_layers = 2
61+
self.hidden_nodes = 10
62+
self.lr = 0.001
63+
self.results_dir = './results/'
64+
6665
if not os.path.exists(self.results_dir):
6766
os.makedirs(self.results_dir)
6867

68+
6969
def test_train_PINN_output(self):
7070
"""
7171
Test the output of the `train_PINN` function.
@@ -296,14 +296,19 @@ def test_train_PINN_multiple_layers_nodes(self):
296296
best_params) # Ensure best_params is not None
297297
self.assertLessEqual(best_loss,
298298
float('inf')) # Ensure loss is finite
299+
300+
299301

300302

301-
def main():
302-
"""
303-
Run the unit tests when script is executed `python test_train_pinn.py`.
304-
"""
303+
if __name__ == '__main__':
304+
# Option 1: Run through standard unittest (preserves CLI usability)
305305
unittest.main()
306306

307-
308-
if __name__ == '__main__':
309-
main()
307+
# Option 2: Also make individual test methods REPL-executable
308+
print("\nManual REPL-friendly execution of each test case:")
309+
t = TestTrainPINN()
310+
t.setUp()
311+
for item in dir(t):
312+
if item.startswith('test_'):
313+
print(f'\nRunning test: {item}')
314+
getattr(t, item)()

0 commit comments

Comments
 (0)