Skip to content
Merged

Dev #48

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8c51b7c
cache key should be generated after probe_xs probe_ys are parsed
tpchuckles Jan 6, 2026
e851a39
Update calculators.py
tpchuckles Jan 6, 2026
df53abb
Update calculators.py
tpchuckles Jan 6, 2026
864124f
restore 03_manyprobes from commit bd16587dea647040620a447518037cc6796…
tpchuckles Jan 7, 2026
3a05e56
resparsify 03_manyprobes
tpchuckles Jan 7, 2026
067964e
06_loaders had incorrect kwargs for hBN_truncated which yielded wrong…
tpchuckles Jan 7, 2026
76e9178
several 06_loaders tests were colliding and pretending to pass, since…
tpchuckles Jan 7, 2026
e65fd9f
cleanup
tpchuckles Jan 7, 2026
2093e2b
restore 05_tacaw_cropped from before commit bd16587dea647040620a44751…
tpchuckles Jan 7, 2026
835bec3
LACBED_iterative had wrong indexing for diff
tpchuckles Jan 7, 2026
ec63f97
update runAllTests.sh
tpchuckles Jan 7, 2026
ca388fd
cleanup
tpchuckles Jan 7, 2026
8666ab7
Merge pull request #46 from h-walk/fixBrokenSparsification
tpchuckles Jan 7, 2026
bfaf34a
use np arctan2 not atan2
tpchuckles Jan 7, 2026
db5d0fc
add HPC testing infrastructure, and remove hbn_xyz from test, as it i…
Jan 7, 2026
7aef395
HPC test infrastructure complete. some numpy tests fail
Jan 7, 2026
975b5d7
restore tacawcrop from commit bd16587dea647040620a447518037cc6796b128c
Jan 7, 2026
54c5e02
resparsify tacawcrop test
Jan 7, 2026
d94c9cb
fix zeros device in wf_data
Jan 7, 2026
dc1f5d1
reupload tacawcrop output
Jan 7, 2026
424e71a
include runAllTests logs, pass numpy and torch cpu tests
Jan 7, 2026
98fc83d
Merge pull request #47 from h-walk/TWP20260107FRESH3
tpchuckles Jan 8, 2026
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Thumbs.db

# Log files
*.log
!runAllTests*.log
logs/
!tests/runAllTests.log

Expand Down
15 changes: 8 additions & 7 deletions src/pyslice/multislice/calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,6 @@ def setup(
self.cache_levels = cache_levels
self.max_kx = max_kx
self.max_ky = max_ky

# Generate cache key and setup output directory
cache_key = self._generate_cache_key(trajectory, aperture, voltage_eV,
slice_thickness, sampling, probe_positions)
#print(cache_key)
self.output_dir = Path("psi_data/" + ("torch" if TORCH_AVAILABLE else "numpy") + "_"+cache_key)
self.output_dir.mkdir(parents=True, exist_ok=True)

# Set up spatial grids
xs,ys,zs,lx,ly,lz=gridFromTrajectory(trajectory,sampling=sampling,slice_thickness=slice_thickness)
Expand Down Expand Up @@ -187,6 +180,14 @@ def setup(
self.probe_positions = [(lx/2, ly/2)] # Center probe
self.probe_xs = [lx/2] ; self.probe_ys = [ly/2]

# Generate cache key and setup output directory
cache_key = self._generate_cache_key(trajectory, aperture, voltage_eV,
slice_thickness, sampling, self.probe_positions)
#print(cache_key)
self.output_dir = Path("psi_data/" + ("torch" if TORCH_AVAILABLE else "numpy") + "_"+cache_key)
self.output_dir.mkdir(parents=True, exist_ok=True)


# Create probe on the correct device from the start
self.base_probe = Probe(xs, ys, self.aperture, self.voltage_eV, device=self.device)

Expand Down
2 changes: 1 addition & 1 deletion src/pyslice/multislice/multislice.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def aberrate(self,aberrations):
def aberrationFunction(kxs,kys,wavelength,aberrations): # aberrations should be a dict of Cnm following https://abtem.readthedocs.io/en/latest/user_guide/walkthrough/contrast_transfer_function.html
dPhi = xp.zeros((len(kxs),len(kys)))
ks = xp.sqrt( kxs[:,None]**2 + kys[None,:]**2 )
theta = xp.atan2( kys[None,:] , kxs[:,None] )
theta = xp.arctan2( kys[None,:] , kxs[:,None] )
for k in aberrations.keys():
n,m = int(k[1]),int(k[2]) # C03 --> 0,3
C = aberrations[k] ; phi0 = 0
Expand Down
6 changes: 3 additions & 3 deletions src/pyslice/postprocessing/wf_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ..multislice.multislice import Probe,aberrationFunction
from ..data import Signal, Dimensions, Dimension, GeneralMetadata
from pathlib import Path
from ..backend import mean
from ..backend import mean,zeros

try:
import torch ; xp = torch
Expand Down Expand Up @@ -406,7 +406,7 @@ def propagate_free_space(self,dz): # UNITS OF ANGSTROM
def applyMask(self, radius, realOrReciprocal="reciprocal"):
if realOrReciprocal == "reciprocal":
radii = xp.sqrt( self._kxs[:,None]**2 + self._kys[None,:]**2 )
mask = xp.zeros(radii.shape, device=self._array.device if TORCH_AVAILABLE else None)
mask = zeros(radii.shape, device=self._array.device if TORCH_AVAILABLE else None)
mask[radii<radius]=1
self._array*=mask[None,None,:,:,None]
else:
Expand All @@ -417,7 +417,7 @@ def applyMask(self, radius, realOrReciprocal="reciprocal"):
radii = xp.tensor(radii_np, dtype=self._array.real.dtype, device=self._array.device)
else:
radii = radii_np
mask = xp.zeros(radii.shape, device=self._array.device if TORCH_AVAILABLE else None)
mask = zeros(radii.shape, device=self._array.device if TORCH_AVAILABLE else None)
mask[radii<radius]=1
kwarg = {"dim":(2,3)} if TORCH_AVAILABLE else {"axes":(2,3)}
real = xp.fft.ifft2(xp.fft.ifftshift(self._array,**kwarg),**kwarg)
Expand Down
20 changes: 10 additions & 10 deletions tests/06_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import matplotlib.pyplot as plt
import numpy as np

# Remove previously-cached npy files (we want to rest reloading them)
# Remove previously-cached npy files (we want to test reloading them)
outfiles=glob.glob("inputs/*.npy")
for f in outfiles:
if "-test" not in f:
Expand All @@ -18,22 +18,22 @@
# https://www.ovito.org/manual/reference/file_formats/file_formats_input.html
# https://www.ovito.org/manual/usage/data_model.html#usage-particle-properties

# define our test input files. all of these should be supported
testFiles={"silicon.positions":{"atom_style":"molecular"}, # lammps input positions file, generated via generatePositions.py
"silicon.xyz": None, # xyz file following wikipedia conventions (https://en.wikipedia.org/wiki/XYZ_file_format), generated via generatePositions.py
"silicon.cif": None, # generated via ase.io.read/write from silicon.xyz
"hBN.cif": None, # taken from DOI: 10.1016/j.matlet.2006.07.108 https://materials.springer.com/isp/crystallographic/docs/sd_1923917
"hBN.xyz": None, # taken from DOI: 10.17863/CAM.66112
"hBN_truncated.lammpstrj": None, # multiple timesteps, generated via a custom dump command from lammps
"hBN_GAP_ase.trj": None, # multiple timesteps, generated via a ASE MD run using the GAP potential from https://doi.org/10.1021/acs.jpcc.0c05831
# define our test input files. all of these should be supported. additional keyword args may be required
testFiles={"silicon_pos.positions":{"ovitokwargs":{"atom_style":"molecular"}}, # lammps input positions file, generated via generatePositions.py
#"silicon_xyz.xyz": {}, # xyz file following wikipedia conventions (https://en.wikipedia.org/wiki/XYZ_file_format), generated via generatePositions.py
#"silicon_cif.cif": {}, # generated via ase.io.read/write from silicon.xyz
"hBN_cif.cif": {}, # taken from DOI: 10.1016/j.matlet.2006.07.108 https://materials.springer.com/isp/crystallographic/docs/sd_1923917
#"hBN_xyz.xyz": {}, # taken from DOI: 10.17863/CAM.66112
"hBN_truncated.lammpstrj": {"atom_mapping":{1:"B",2:"N"}}, # multiple timesteps, generated via a custom dump command from lammps
"hBN_GAP_ase.trj": {}, # multiple timesteps, generated via a ASE MD run using the GAP potential from https://doi.org/10.1021/acs.jpcc.0c05831
}


# for each: load, generate potential, plot potential
for i,filename in enumerate(testFiles.keys()):
# LOAD IT
print("attempting to load","inputs/"+filename)
trajectory=Loader("inputs/"+filename,ovitokwargs=testFiles[filename]).load()
trajectory=Loader("inputs/"+filename,**testFiles[filename]).load()
# DIFF IT
positions = trajectory.positions[0]
differ(positions,"outputs/loaders-test_"+filename+".npy","POSITIONS")
Expand Down
2 changes: 1 addition & 1 deletion tests/08_LACBED_iterative.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@
#if hasattr(ary, 'cpu'):
# ary = ary.cpu().numpy()

differ(ary[::10,::10],"outputs/lacbed-test.npy","LACBED")
differ(ary[:,:,::10,::10,:],"outputs/lacbed-test.npy","LACBED")
10 changes: 10 additions & 0 deletions tests/cpu.sberr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-------------------------------------------------------------------------------
There are messages associated with the following module(s):
-------------------------------------------------------------------------------

cuda/11.4.0:
Please note, CUDA/11.4.0 is required if compiling for NVIDIA K80 GPUs.
Newer toolchain versions will not work for K80's.

-------------------------------------------------------------------------------DeprecationWarning: 'source deactivate' is deprecated. Use 'conda deactivate'.
slurmstepd: error: *** JOB 4394420 ON or-condo-c75 CANCELLED AT 2026-01-07T14:44:01 ***
Empty file added tests/cpu.sbout
Empty file.
18 changes: 18 additions & 0 deletions tests/cpu.slurm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
#SBATCH -A birthright
#SBATCH --partition=batch
#SBATCH --time=12:00:00
#SBATCH --mem=16G
#SBATCH -N 1
#SBATCH -n 1
#SBATCH --output=cpu.sbout
#SBATCH --error=cpu.sberr

module load cuda/11.4.0
module load gcc
source deactivate base
conda activate /home/qwe/.conda/envs/pyslice_env

bash runAllTests.sh torchcpu


9 changes: 9 additions & 0 deletions tests/gpu.sberr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-------------------------------------------------------------------------------
There are messages associated with the following module(s):
-------------------------------------------------------------------------------

cuda/11.4.0:
Please note, CUDA/11.4.0 is required if compiling for NVIDIA K80 GPUs.
Newer toolchain versions will not work for K80's.

-------------------------------------------------------------------------------DeprecationWarning: 'source deactivate' is deprecated. Use 'conda deactivate'.
Empty file added tests/gpu.sbout
Empty file.
18 changes: 18 additions & 0 deletions tests/gpu.slurm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
#SBATCH -A birthright
#SBATCH --partition=burst
#SBATCH --time=12:00:00
#SBATCH --mem=16G
#SBATCH -N 1
#SBATCH -n 1
#SBATCH -c 1
#SBATCH -G v100:1
#SBATCH --output=gpu.sbout
#SBATCH --error=gpu.sberr

module load cuda/11.4.0
module load gcc
source deactivate base
conda activate /home/qwe/.conda/envs/pyslice_env

bash runAllTests.sh torchgpu
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions tests/numpy.sberr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-------------------------------------------------------------------------------
There are messages associated with the following module(s):
-------------------------------------------------------------------------------

cuda/11.4.0:
Please note, CUDA/11.4.0 is required if compiling for NVIDIA K80 GPUs.
Newer toolchain versions will not work for K80's.

-------------------------------------------------------------------------------DeprecationWarning: 'source deactivate' is deprecated. Use 'conda deactivate'.
slurmstepd: error: *** JOB 4394419 ON or-condo-c75 CANCELLED AT 2026-01-07T14:43:59 ***
Empty file added tests/numpy.sbout
Empty file.
18 changes: 18 additions & 0 deletions tests/numpy.slurm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
#SBATCH -A birthright
#SBATCH --partition=batch
#SBATCH --time=12:00:00
#SBATCH --mem=16G
#SBATCH -N 1
#SBATCH -n 1
#SBATCH --output=numpy.sbout
#SBATCH --error=numpy.sberr

module load cuda/11.4.0
module load gcc
source deactivate base
conda activate /home/qwe/.conda/envs/numpy_env

bash runAllTests.sh numpy


Binary file modified tests/outputs/figs/00_probe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/00_probe_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/00_probe_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/00_probe_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/00_probe_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/00_probe_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/01_potentials.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/02_propagate_otf=False.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/02_propagate_otf=True.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/03_manyprobes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/04_haadf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/04_haadf_cbed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/05_tacaw_30THz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/05_tacaw_diff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/05_tacaw_disp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/05_tacawcrop_30THz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/05_tacawcrop_diff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/05_tacawcrop_disp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/06_loaders_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/06_loaders_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/06_loaders_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/06_loaders_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/06_loaders_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/06_loaders_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/06_loaders_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/outputs/figs/07_defocus_2D.png
Binary file modified tests/outputs/figs/07_defocus_3D.png
Binary file modified tests/outputs/figs/08_LACBED_iterative.png
Binary file modified tests/outputs/figs/08_LACBED_onthefly.png
Binary file modified tests/outputs/figs/10_midgley_30THz.png
Binary file modified tests/outputs/figs/10_midgley_diff.png
Binary file modified tests/outputs/figs/10_midgley_diff2.png
Binary file modified tests/outputs/figs/10_midgley_disp.png
Binary file modified tests/outputs/figs/11_SED_30THz.png
Binary file modified tests/outputs/figs/12_aberrations_espread.png
Binary file modified tests/outputs/figs/12_aberrations_tableau.png
Binary file modified tests/outputs/manyprobes-test.npy
Binary file not shown.
Binary file modified tests/outputs/tacawcrop-test.npy
Binary file not shown.
Loading