Skip to content

Commit

Permalink
Merge hackathon branch into development (#87)
Browse files Browse the repository at this point in the history
Co-authored-by: Axel Huebl <[email protected]>
Co-authored-by: Maxence Thévenet <[email protected]>
Co-authored-by: Rob Shalloo <[email protected]>
Co-authored-by: Sören Jalas <[email protected]>
Co-authored-by: Luca Fedeli <[email protected]>
Co-authored-by: Igor Andriyash <[email protected]>
  • Loading branch information
7 people authored Feb 4, 2023
1 parent d8b8d7d commit 40f0b26
Show file tree
Hide file tree
Showing 19 changed files with 415 additions and 100 deletions.
52 changes: 18 additions & 34 deletions .github/workflows/unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,37 @@ concurrency:
cancel-in-progress: true

jobs:
test:
unittest:
strategy:
matrix:
python-version: ["3.10"]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- name: Cache conda
uses: actions/cache@v2
# Increase this value to reset cache
env: {CACHE_NUMBER: 0}
with:
path: ~/conda_pkgs_dir
key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ matrix.python-version }}

- uses: conda-incubator/setup-miniconda@v2
name: Setup conda
with:
auto-update-conda: true
activate-environment: testing
auto-activate-base: false
channels: conda-forge,defaults
channel-priority: true

- shell: bash -eo pipefail -l {0}
name: Install dependencies

- name: Install dependencies
run: |
conda install -y -c conda-forge mamba
mamba install -y -c conda-forge python=${{ matrix.python-version }} pyflakes pytest
mamba env update --name testing --file conda.yml
python3 -m pip install -U pip
python3 -m pip install -r requirements.txt
python3 -m pip install -r tests/requirements.txt
- shell: bash -eo pipefail -l {0}
name: Install
- name: Install
run: python -m pip install -v .

- shell: bash -eo pipefail -l {0}
name: pyflakes
run: python -m pyflakes lasy

- shell: bash -eo pipefail -l {0}
name: Run Unit Tests
- name: Run Unit Tests
run: python -m pytest tests/

- shell: bash -eo pipefail -l {0}
name: Run Examples
- name: Run Examples
run: |
cd examples
python test.py
pyflakes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: python3 -m pip install -U pyflakes
- name: pyflakes
run: python -m pyflakes lasy
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ Then, for each contribution:
python3 -m pip install -v .
```

For tests, you need to have `pytest` installed:
For tests, you need to have a few extra packages, such as `pytest` and `openpmd-viewer` installed:
```bash
python3 -m pip install -U pytest
python3 -m pip install -r tests/requirements.txt
```

## Test
Expand Down
2 changes: 2 additions & 0 deletions conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencies:
- mamba
- numpy
- openpmd-api~=0.14.5
- openpmd-viewer
- pytest
- python>=3.7
- scipy

Expand Down
126 changes: 126 additions & 0 deletions examples/lasy_propagator_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import numpy as np
import matplotlib.pyplot as plt

from lasy.laser import Laser
from lasy.profiles.gaussian_profile import GaussianProfile

# Case with Gaussian laser

wavelength = 0.8e-6
pol = (1, 0)
laser_energy = 1. # J
t_peak = 0.0e-15 # s
tau = 30.e-15 # s
w0 = 5.e-6 # m

profile = GaussianProfile(wavelength, pol, laser_energy, w0, tau, t_peak)

# - RT Cartesian case
dim = 'rt'
lo = (0e-6, -150e-15)
hi = (100e-6, 150e-15)
npoints = (96, 1024)

laser = Laser(dim, lo, hi, npoints, profile)

propagate_step = 600e-6

for step in range(2):
E_rt, imshow_extent = laser.get_full_field()
imshow_extent[:2] *= 1e15
imshow_extent[2:] *= 1e6
vmax = np.abs(E_rt).max()

plt.figure()
plt.imshow(E_rt.T,
origin='lower',
aspect='auto',
vmax=vmax, vmin=-vmax,
extent=imshow_extent,
cmap=plt.cm.bwr
)

plt.colorbar()
plt.xlabel(r'time (fs)', fontsize=14)
plt.ylabel(r'R ($\mu$m)', fontsize=14);

t0 = imshow_extent[:2].mean()
plt.xlim(t0-70, t0+70)

laser.propagate(propagate_step);

wavelength = 0.8e-6
pol = (1, 0)
laser_energy = 1. # J
t_peak = 0.0e-15 # s
tau = 30.e-15 # s
w0 = 5.e-6 # m
profile = GaussianProfile(wavelength, pol, laser_energy, w0, tau, t_peak)

# - 3D Cartesian case
dim = 'xyt'
lo = (-100e-6, -100e-6, -150e-15)
hi = (+100e-6, +100e-6, +150e-15)
npoints = (192, 192, 1024)

laser = Laser(dim, lo, hi, npoints, profile)

propagate_step = 800e-6

for step in range(2):
E_xt, imshow_extent = laser.get_full_field()
imshow_extent[:2] *= 1e15
imshow_extent[2:] *= 1e6
vmax = np.abs(E_xt).max()

plt.figure()
plt.imshow(E_xt.T,
origin='lower',
aspect='auto',
extent=imshow_extent,
vmax=vmax, vmin=-vmax,
cmap=plt.cm.bwr)

plt.colorbar()
plt.xlabel(r'time (fs)', fontsize=14)
plt.ylabel(r'R ($\mu$m)', fontsize=14);

t0 = imshow_extent[:2].mean()
plt.xlim(t0-70, t0+70)

laser.propagate(propagate_step);

propagate_distance = 2e-3
propagate_step = 25e-6

Nstep = int(np.round(propagate_distance/propagate_step))
dim = 'rt'
lo = (0e-6, -150e-15)
hi = (100e-6, 150e-15)
npoints = (96, 1024)
laser = Laser(dim, lo, hi, npoints, profile)

for step in range(Nstep):
laser.propagate(propagate_step, nr_boundary=32);

E_rt, imshow_extent = laser.get_full_field()
imshow_extent[:2] *= 1e15
imshow_extent[2:] *= 1e6
vmax = np.abs(E_rt).max()

plt.figure()
plt.imshow(E_rt.T,
origin='lower',
aspect='auto',
extent=imshow_extent,
vmax=vmax, vmin=-vmax,
cmap=plt.cm.bwr)

plt.colorbar()
t0 = imshow_extent[:2].mean()
plt.xlim(t0-70, t0+70)

plt.xlabel(r'time (fs)', fontsize=14)
plt.ylabel(r'R ($\mu$m)', fontsize=14);

plt.show()
Loading

0 comments on commit 40f0b26

Please sign in to comment.