Skip to content

Commit

Permalink
Merge branch 'main' into base-hamiltonian-class
Browse files Browse the repository at this point in the history
  • Loading branch information
ddkohler committed Sep 19, 2024
2 parents 71a3629 + 6b2c428 commit 5bd5d93
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 94 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
name: "CodeQL"

on:
push:
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [main]
schedule:
- cron: '0 16 * * 4'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['python']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
queries: +security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
29 changes: 29 additions & 0 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: test python

on:
pull_request:
types: [opened, reopened]
push:

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: [3.8, 3.9, '3.10', 3.11]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install --upgrade .[dev]
- name: Test with pytest
run: |
pytest --color=yes
4 changes: 2 additions & 2 deletions WrightSim/experiment/_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def efields(self, windowed=None):
efields_shape = list(efp.shape)
if windowed == self.windowed:
efields_shape[-1] = self.iprime
efields = np.zeros((efields_shape), dtype=np.complex)
efields = np.zeros((efields_shape), dtype=np.complex128)
with wt.kit.Timer():
for ind in np.ndindex(tuple(efields_shape[:-2])):
efi = self.pulse_class.pulse(efp[ind], self.t_args, pm=self.pm)
Expand All @@ -272,7 +272,7 @@ def efields(self, windowed=None):
else:
efields_shape[-1] = self.t.size

efields = np.zeros((efields_shape), dtype=np.complex)
efields = np.zeros((efields_shape), dtype=np.complex128)
with wt.kit.Timer():
for ind in np.ndindex(tuple(efields_shape[:-2])):
efi = self.pulse_class.pulse(efp[ind], self.t_args, pm=self.pm)
Expand Down
8 changes: 4 additions & 4 deletions WrightSim/hamiltonian/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ def __init__(
Order matters, and meaning is dependent on the individual Hamiltonian.
Default is two values, both initially 1.0.
omega : 1-D array <float64> (optional)
The energies of various transitions.
The energies of various transitions (wavenumbers).
The default uses w_central and coupling parameters to compute the appropriate
values for a TRIVE Hamiltonian
w_central : float (optional)
The cetral frequency of a resonance for a TRIVE Hamiltonian.
w_central : float (optional)
The central frequency (wavenumbers) of a resonance for a TRIVE Hamiltonian.
Used only when ``omega`` is ``None``.
coupling : float (optional)
coupling : float (optional) (wavenumbers)
The copuling of states for a TRIVE Hamiltonian.
Used only when ``omega`` is ``None``.
propagator : function (optional)
Expand Down
86 changes: 0 additions & 86 deletions scripts/test_default_phase_delay_dependence.py

This file was deleted.

19 changes: 17 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,23 @@
name="WrightSim",
packages=find_packages(),
package_data=extra_files,
install_requires=["h5py>=2.7.0", "numpy", "scipy", "WrightTools"],
extras_require={"docs": ["sphinx-gallery>=0.1.9"], "cuda": ["pycuda"]},
python_requires=">=3.7",
install_requires=[
"h5py>=2.7.0",
"numpy",
"scipy",
"WrightTools"
],
extras_require={
"docs": ["sphinx-gallery>=0.1.9"],
"cuda": ["pycuda"],
"dev": [
"black",
"pre-commit",
"pytest",
"pytest-cov",
]
},
version=version,
description="A simulation package for multidimensional spectroscopy.",
author="WrightSim Developers",
Expand Down
88 changes: 88 additions & 0 deletions tests/mixed/default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"""smokescreen checks of mixed domain default hamiltonian integration"""
import WrightSim as ws
import numpy as np
import pytest


dt = 20
nt = 21
wn_to_omega = 2 * np.pi * 3e-5 # cm / fs
w_central = 3000 # wn
coupling = 0 # wn

ham = ws.hamiltonian.Hamiltonian(
w_central=w_central,
coupling=coupling,
tau=100,
)
ham.recorded_elements = [7, 8]


@pytest.mark.skip("this test currently fails; bugfix needed")
def test_windowed():
exp = ws.experiment.builtin('trive')
exp.w1.points = w_central # wn
exp.w2.points = w_central # wn
exp.d2.points = 50 # np.zeros((1,)) # fs
exp.d1.points = 0 # fs
exp.s1.points = exp.s2.points = dt # fs

exp.d1.active = exp.d2.active = False

# 400 time points
exp.timestep = 1
exp.early_buffer = 100.
exp.late_buffer = 300.

scan = exp.run(ham, mp=False)
data = scan.sig

# shift delay so emission is timed differently
exp2 = ws.experiment.builtin('trive')
exp2.w1.points = w_central # wn
exp2.w2.points = w_central # wn
exp2.d2.points = 50 # np.zeros((1,)) # fs
exp2.d1.points = 0 # fs
exp2.s1.points = exp2.s2.points = dt # fs

exp2.d1.active = exp2.d2.active = False

exp2.timestep = 1
exp2.early_buffer = 100.
exp2.late_buffer = 300.

scan2 = exp2.run(ham, mp=False, windowed=True)
data2 = scan2.sig

assert data2.time.size == data.time.size
assert data2.time.size == data2.channels[0].size
assert np.all(np.isclose(data2.channels[0][:], data.channels[0][:]))


def test_frequency():

exp = ws.experiment.builtin('trive')
exp.w1.points = w_central # wn
exp.w2.points = w_central # wn
exp.d2.points = 0 # np.zeros((1,)) # fs
exp.d1.points = 0 # fs
exp.s1.points = exp.s2.points = dt # fs

exp.d1.active = exp.d2.active = False

# 400 time points
exp.timestep = 1
exp.early_buffer = 100.
exp.late_buffer = 300.

scan = exp.run(ham, mp=False)
data = scan.sig
wn = np.fft.fftfreq(n=data.time.size, d=exp.timestep) / 3e-5
sig_fft = np.abs(np.fft.fft(data.channels[0][:]))

assert np.abs(wn[np.argmax(sig_fft)] + w_central) < np.abs(wn[1] - wn[0])


if __name__ == "__main__":
test_windowed() # fails atm
test_frequency()
Loading

0 comments on commit 5bd5d93

Please sign in to comment.