Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates on NN architecture, Filters, redshift and tests #17

Merged
merged 34 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
db95c21
Added classes for convolutional neural networks and conditional
Dec 20, 2024
7c31ab6
Reorganized neuralnetworks and lightcurve model to accomodate the
Jan 6, 2025
d9cd71e
Added some stuff for cVAEs in Benchmarker and FluxTrainer and then
Jan 9, 2025
c83331d
Import pbag at the right place
Jan 9, 2025
13ac09a
Added some documentation and comments for FluxTrainer API and
Jan 10, 2025
b30a8bb
Added conversion functions for fluxes and magnitudes and added these as
Jan 16, 2025
9ce4319
Reorganize the DataManager class into its own file and add
Jan 16, 2025
0ccdcf4
Restructured the benchmarking script for better readability and so that
Jan 22, 2025
167da3c
Deleted the old benchmarker files.
Jan 22, 2025
412174b
Added the classical NMMA approach to surrogate training in the form of
Jan 22, 2025
fc55585
Clean up the lightcurve model folder.
Jan 22, 2025
dec39a0
Small improvements in utils and FluxTrainer. Filter now have a
Jan 22, 2025
7374ef4
Reogranized and improved the lightcurve models. Most importantly, the
Jan 22, 2025
503a9c8
Fix issues that caused the pylint check to fail.
Jan 23, 2025
bff04f6
Add unit tests for FluxModel and FluxTrainer and commit workflow for
Jan 23, 2025
2446d1a
Fix issues in the workflow .yml files.
Jan 23, 2025
d7c4386
Improved unittest workflow .yml
Jan 23, 2025
3e6ee88
Make the unit test workflow run. In particular, remove liniting with
Jan 24, 2025
888e207
Remove the egg-info files from pip install -e .
Jan 24, 2025
76b2a67
added __init__ files
Jan 24, 2025
a9f43ee
Remove unnecessary files
Jan 24, 2025
fe21ed7
src style improvements
Jan 24, 2025
8c5e3d7
Make tests suitable for pytest.
Jan 25, 2025
70f79ff
Redshift update
Jan 27, 2025
945d001
Filter update
Jan 27, 2025
9f09123
Updated tests
Jan 27, 2025
2c8c618
Reorganized the injection classes. Injections are now possible with
Feb 4, 2025
2af12ba
Polished the load_event_data function.
Feb 5, 2025
b8e4ae0
Added saving to fiesta class and small adaptions in likelihood.py .
Feb 5, 2025
d01a1c5
Adapting Benchmarker to new lightcurve model output
Feb 5, 2025
b3231c7
Added Integrated filter XRT-type
Feb 7, 2025
be39260
Fix for plotting lightcurves
Feb 7, 2025
8d77a1a
Added models to git
Feb 7, 2025
5e97990
Update for pbag runs
Feb 7, 2025
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
5 changes: 3 additions & 2 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -18,6 +18,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pylint
python -m pip install .
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
pylint --fail-under=5 --disable=C,R,W $(git ls-files 'src/*.py')
40 changes: 40 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Unittest

on:
push:
pull_request:

jobs:
test:
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Set up Python with Conda ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ 'x86_64' }}
miniforge-version: latest
use-mamba: true
mamba-version: "*"
activate-environment: fiesta_env

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install pytest pytest-cov pytest-aiohttp sqlparse freezegun PyJWT joblib coveralls
python -m pip install .

- name: Perform tests with pytest
run: |
python -m coverage run --source fiesta -m pytest tests/*.py
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
__pycache__
.coverage
*egg-info
/flux_models/*/benchmarks
/lightcurve_models/*/benchmarks
/flux_models/*/model/*.h5
/lightcurve_models/*/model/*.h5
*nohup.out
*.sbatch
*/log
*/err
1 change: 0 additions & 1 deletion benchmarks/GRB/benchmark_afterglowpy_tophat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
file_ending = "Linf"

B = Benchmarker(name = name,
parameter_grid = parameter_grid,
model_dir = model_dir,
MODEL = AfterglowpyLightcurvemodel,
filters = FILTERS,
Expand Down
58 changes: 24 additions & 34 deletions flux_models/afterglowpy_gaussian/benchmark_afterglowpy_gaussian.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,35 @@
import numpy as np
import matplotlib.pyplot as plt

from fiesta.train.BenchmarkerFluxes import Benchmarker
from fiesta.inference.lightcurve_model import AfterglowpyPCA
from fiesta.utils import Filter
from fiesta.train.Benchmarker import Benchmarker
from fiesta.inference.lightcurve_model import AfterglowFlux


name = "gaussian"
model_dir = f"./model/"
FILTERS = ["radio-3GHz", "radio-6GHz", "bessellv", "X-ray-1keV"]

for metric_name in ["$\\mathcal{L}_2$", "$\\mathcal{L}_\infty$"]:
if metric_name == "$\\mathcal{L}_2$":
file_ending = "L2"
else:
file_ending = "Linf"

B = Benchmarker(name = name,
model_dir = model_dir,
MODEL = AfterglowpyPCA,
filters = FILTERS,
metric_name = metric_name,
)


for filt in FILTERS:

fig, ax = B.plot_lightcurves_mismatch(filter =filt, parameter_labels = ["$\\iota$", "$\log_{10}(E_0)$", "$\\theta_{\\mathrm{c}}$", "$\\alpha_w$", "$\log_{10}(n_{\mathrm{ism}})$", "$p$", "$\\epsilon_E$", "$\\epsilon_B$"])
fig.savefig(f"./benchmarks/benchmark_{filt}_{file_ending}.pdf", dpi = 200)
lc_model = AfterglowFlux(name,
directory = model_dir,
filters = FILTERS,
model_type= "MLP")

for metric_name in ["L2", "Linf"]:


B.print_correlations(filter = filt)
benchmarker = Benchmarker(
model = lc_model,
data_file = "./model/afterglowpy_raw_data.h5",
metric_name = metric_name
)

fig, ax = B.plot_worst_lightcurves()
fig.savefig(f"./benchmarks/worst_lightcurves_{file_ending}.pdf", dpi = 200)


fig, ax = B.plot_error_distribution()
fig.savefig(f"./benchmarks/error_distribution.pdf", dpi = 200)

fig, ax = B.plot_error_over_time()
fig.savefig(f"./benchmarks/error_over_time.pdf", dpi = 200)
benchmarker.benchmark()

benchmarker.plot_lightcurves_mismatch(parameter_labels = ["$\\iota$",
"$\log_{10}(E_0)$",
"$\\theta_{\\mathrm{c}}$",
"$\\alpha_{\\mathrm{w}}$",
"$\log_{10}(n_{\mathrm{ism}})$",
"$p$",
"$\log_{10}(\\epsilon_e)$",
"$\log_{10}(\\epsilon_B)$"])



Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import numpy as np
import matplotlib.pyplot as plt

from fiesta.train.AfterglowData import AfterglowpyData

#############
### SETUP ###
#############

tmin = 0.1 # days
tmin = 1e-4 # days
tmax = 2000 # days
n_times = 200
n_times = 250


numin = 1e9 # Hz
numax = 2.5e18 # Hz (10 keV)
numax = 2.5e19 # Hz (100 keV)
n_nu = 256


Expand All @@ -34,7 +32,7 @@
jet_conversion = {"tophat": -1,
"gaussian": 0}

n_training = 45_000
n_training = 20_000
n_val = 0
n_test = 0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
from jax.random import PRNGKey
import numpy as np

from fiesta.train.AfterglowData import AfterglowpyData
from fiesta.inference.prior_dict import ConstrainedPrior
from fiesta.inference.prior import Uniform, Constraint

#############
### SETUP ###
#############


parameter_distributions = {
'inclination_EM': (0, np.pi/2, "uniform"),
'log10_E0': (47, 57, "uniform"),
'thetaCore': (0.01, np.pi/5, "loguniform"),
'alphaWing': (0.2, 3.5, "uniform"),
'log10_n0': (-6, 2, "uniform"),
'p': (2.01, 3, "uniform"),
'log10_epsilon_e': (-4, 0, "uniform"),
'log10_epsilon_B': (-8, 0, "uniform")
}



name = "tophat"
name = "gaussian"
outdir = f"./model/"

n_training = 0
n_val = 0
n_test = 0

n_pool = 24

size = 20_000


Expand All @@ -39,26 +31,28 @@
n_test = 0,
n_pool = n_pool)

#import h5py
#with h5py.File(creator.outfile, "r+") as f:
# unproblematic = np.unique(np.where(~np.isinf(f["special_train"]["01"]["y"]))[0])
#
# X = f["special_train"]["01"]["X"][unproblematic]
# y = f["special_train"]["01"]["y"][unproblematic]
# breakpoint()
# creator._save_to_file(X, y, group = "special_train", label = "02", comment = "log10_E0 (54, 57) log10_n0 (-6, -4) thetaCore (0.4, np.pi/5)")



inclination = np.random.uniform(0, np.pi/2, size = size)
log10_E0 = np.random.uniform(54, 57, size = size)
thetaCore = np.random.uniform(0.4, np.pi/5, size= size)
alphaWing = np.random.uniform(0.2, 3.5, size = size)
log10_n0 = np.random.uniform(-6, -4, size = size)
p = np.random.uniform(2, 3, size = size)
log10_epsilon_e = np.random.uniform(-4, 0, size = size)
log10_epsilon_B = np.random.uniform(-8, 0, size = size)

X = np.array([inclination, log10_E0, thetaCore, alphaWing, log10_n0, p, log10_epsilon_e, log10_epsilon_B]).T

creator.create_special_data(X, label = "01", comment = "log10_E0 (54, 57) log10_n0 (-6, -4) thetaCore (0.4, np.pi/5)")
def conversion_function(sample):
converted_sample = sample
converted_sample["thetaWing"] = converted_sample["thetaCore"] * converted_sample["alphaWing"]
converted_sample["epsilon_tot"] = 10**(converted_sample["log10_epsilon_B"]) + 10**(converted_sample["log10_epsilon_e"])
return converted_sample

prior = ConstrainedPrior([
Uniform(xmin=0., xmax=np.pi/2, naming=["inclination_EM"]),
Uniform(xmin=54., xmax=57., naming=["log10_E0"]),
Uniform(xmin=0.35, xmax=np.pi/5, naming=["thetaCore"]),
Uniform(0.2, 3.5, naming=["alphaWing"]),
Uniform(xmin=-6.,xmax=-4.,naming=["log10_n0"]),
Uniform(xmin=2., xmax=3., naming=["p"]),
Uniform(xmin=-4., xmax=0., naming=["log10_epsilon_e"]),
Uniform(xmin=-8.,xmax=0., naming=["log10_epsilon_B"]),
Constraint(xmin=0., xmax=1., naming=["epsilon_tot"]),
Constraint(xmin=0., xmax=np.pi/2, naming=["thetaWing"])
],
conversion_function)

X = prior.sample(PRNGKey(2728), n_samples=size)
X = [X[p] for p in creator.parameter_names]
X = np.transpose(X)

creator.create_special_data(X, label = "01", comment = "log10_E0 (54, 57) log10_n0 (-6, -4) thetaCore (0.35, np.pi/5)")
Binary file modified flux_models/afterglowpy_gaussian/model/gaussian.pkl
Binary file not shown.
Binary file modified flux_models/afterglowpy_gaussian/model/gaussian_metadata.pkl
Binary file not shown.
Loading
Loading