Skip to content

Commit 65dc884

Browse files
authored
pytest and codeql (#50)
* first attempt * Update setup.py * typo * some tests * ignore failing test for now just to make PR less confusing to review * Update default.py * codeql
1 parent 479624b commit 65dc884

File tree

5 files changed

+209
-6
lines changed

5 files changed

+209
-6
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
name: "CodeQL"
7+
8+
on:
9+
push:
10+
branches: [main]
11+
pull_request:
12+
# The branches below must be a subset of the branches above
13+
branches: [main]
14+
schedule:
15+
- cron: '0 16 * * 4'
16+
17+
jobs:
18+
analyze:
19+
name: Analyze
20+
runs-on: ubuntu-latest
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
# Override automatic language detection by changing the below list
26+
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
27+
language: ['python']
28+
# Learn more...
29+
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
with:
35+
# We must fetch at least the immediate parents so that if this is
36+
# a pull request then we can checkout the head.
37+
fetch-depth: 2
38+
39+
# If this run was triggered by a pull request event, then checkout
40+
# the head of the pull request instead of the merge commit.
41+
- run: git checkout HEAD^2
42+
if: ${{ github.event_name == 'pull_request' }}
43+
44+
# Initializes the CodeQL tools for scanning.
45+
- name: Initialize CodeQL
46+
uses: github/codeql-action/init@v2
47+
with:
48+
languages: ${{ matrix.language }}
49+
# If you wish to specify custom queries, you can do so here or in a config file.
50+
# By default, queries listed here will override any specified in a config file.
51+
# Prefix the list here with "+" to use these queries and those in the config file.
52+
queries: +security-and-quality
53+
54+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55+
# If this step fails, then you should remove it and run the build manually (see below)
56+
- name: Autobuild
57+
uses: github/codeql-action/autobuild@v2
58+
59+
# ℹ️ Command-line programs to run using the OS shell.
60+
# 📚 https://git.io/JvXDl
61+
62+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63+
# and modify them (or add more) to build your code if your project
64+
# uses a compiled language
65+
66+
#- run: |
67+
# make bootstrap
68+
# make release
69+
70+
- name: Perform CodeQL Analysis
71+
uses: github/codeql-action/analyze@v2

.github/workflows/python-test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: test python
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened]
6+
push:
7+
8+
jobs:
9+
build:
10+
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, windows-latest]
15+
python-version: [3.8, 3.9, '3.10', 3.11]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip wheel setuptools
26+
python -m pip install --upgrade .[dev]
27+
- name: Test with pytest
28+
run: |
29+
pytest --color=yes

WrightSim/hamiltonian/default.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ def __init__(
7171
Order matters, and meaning is dependent on the individual Hamiltonian.
7272
Default is two values, both initially 1.0.
7373
omega : 1-D array <float64> (optional)
74-
The energies of various transitions.
74+
The energies of various transitions (wavenumbers).
7575
The default uses w_central and coupling parameters to compute the appropriate
7676
values for a TRIVE Hamiltonian
77-
w_central : float (optional)
78-
The cetral frequency of a resonance for a TRIVE Hamiltonian.
77+
w_central : float (optional)
78+
The central frequency (wavenumbers) of a resonance for a TRIVE Hamiltonian.
7979
Used only when ``omega`` is ``None``.
80-
coupling : float (optional)
80+
coupling : float (optional) (wavenumbers)
8181
The copuling of states for a TRIVE Hamiltonian.
8282
Used only when ``omega`` is ``None``.
8383
propagator : function (optional)

setup.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,23 @@
1414
name="WrightSim",
1515
packages=find_packages(),
1616
package_data=extra_files,
17-
install_requires=["h5py>=2.7.0", "numpy", "scipy", "WrightTools"],
18-
extras_require={"docs": ["sphinx-gallery>=0.1.9"], "cuda": ["pycuda"]},
17+
python_requires=">=3.7",
18+
install_requires=[
19+
"h5py>=2.7.0",
20+
"numpy",
21+
"scipy",
22+
"WrightTools"
23+
],
24+
extras_require={
25+
"docs": ["sphinx-gallery>=0.1.9"],
26+
"cuda": ["pycuda"],
27+
"dev": [
28+
"black",
29+
"pre-commit",
30+
"pytest",
31+
"pytest-cov",
32+
]
33+
},
1934
version=version,
2035
description="A simulation package for multidimensional spectroscopy.",
2136
author="WrightSim Developers",

tests/mixed/default.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"""smokescreen checks of mixed domain default hamiltonian integration"""
2+
import WrightSim as ws
3+
import numpy as np
4+
import pytest
5+
6+
7+
dt = 20
8+
nt = 21
9+
wn_to_omega = 2 * np.pi * 3e-5 # cm / fs
10+
w_central = 3000 # wn
11+
coupling = 0 # wn
12+
13+
ham = ws.hamiltonian.Hamiltonian(
14+
w_central=w_central,
15+
coupling=coupling,
16+
tau=100,
17+
)
18+
ham.recorded_elements = [7, 8]
19+
20+
21+
@pytest.mark.skip("this test currently fails; bugfix needed")
22+
def test_windowed():
23+
exp = ws.experiment.builtin('trive')
24+
exp.w1.points = w_central # wn
25+
exp.w2.points = w_central # wn
26+
exp.d2.points = 50 # np.zeros((1,)) # fs
27+
exp.d1.points = 0 # fs
28+
exp.s1.points = exp.s2.points = dt # fs
29+
30+
exp.d1.active = exp.d2.active = False
31+
32+
# 400 time points
33+
exp.timestep = 1
34+
exp.early_buffer = 100.
35+
exp.late_buffer = 300.
36+
37+
scan = exp.run(ham, mp=False)
38+
data = scan.sig
39+
40+
# shift delay so emission is timed differently
41+
exp2 = ws.experiment.builtin('trive')
42+
exp2.w1.points = w_central # wn
43+
exp2.w2.points = w_central # wn
44+
exp2.d2.points = 50 # np.zeros((1,)) # fs
45+
exp2.d1.points = 0 # fs
46+
exp2.s1.points = exp2.s2.points = dt # fs
47+
48+
exp2.d1.active = exp2.d2.active = False
49+
50+
exp2.timestep = 1
51+
exp2.early_buffer = 100.
52+
exp2.late_buffer = 300.
53+
54+
scan2 = exp2.run(ham, mp=False, windowed=True)
55+
data2 = scan2.sig
56+
57+
assert data2.time.size == data.time.size
58+
assert data2.time.size == data2.channels[0].size
59+
assert np.all(np.isclose(data2.channels[0][:], data.channels[0][:]))
60+
61+
62+
def test_frequency():
63+
64+
exp = ws.experiment.builtin('trive')
65+
exp.w1.points = w_central # wn
66+
exp.w2.points = w_central # wn
67+
exp.d2.points = 0 # np.zeros((1,)) # fs
68+
exp.d1.points = 0 # fs
69+
exp.s1.points = exp.s2.points = dt # fs
70+
71+
exp.d1.active = exp.d2.active = False
72+
73+
# 400 time points
74+
exp.timestep = 1
75+
exp.early_buffer = 100.
76+
exp.late_buffer = 300.
77+
78+
scan = exp.run(ham, mp=False)
79+
data = scan.sig
80+
wn = np.fft.fftfreq(n=data.time.size, d=exp.timestep) / 3e-5
81+
sig_fft = np.abs(np.fft.fft(data.channels[0][:]))
82+
83+
assert np.abs(wn[np.argmax(sig_fft)] + w_central) < np.abs(wn[1] - wn[0])
84+
85+
86+
if __name__ == "__main__":
87+
test_windowed() # fails atm
88+
test_frequency()

0 commit comments

Comments
 (0)