Skip to content

Commit

Permalink
Merge branch 'main' of github.com:GilesStrong/mode_muon_tomography in…
Browse files Browse the repository at this point in the history
…to kuhn_scatter_model
  • Loading branch information
Zahraa Zaher committed Dec 6, 2023
2 parents 158d7c2 + 723387b commit c659f73
Show file tree
Hide file tree
Showing 63 changed files with 373 additions and 300 deletions.
23 changes: 16 additions & 7 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.8"
- uses: psf/black@22.1.0
Expand All @@ -21,17 +21,26 @@ jobs:
flake8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.8"
- uses: py-actions/flake8@v1


isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.8"
- uses: isort/isort-action@master

mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install Dependencies
Expand Down
11 changes: 5 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ repos:
- id: flake8
args: [--ignore=E741 W503 E203 E501 C901]

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.812
# hooks:
# - id: mypy
# exclude: tests/|setup.py
# args: [--disallow-untyped-calls, --disallow-untyped-defs, --check-untyped-defs, --ignore-missing-imports, --no-strict-optional]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]

- repo: local
hooks:
Expand Down
2 changes: 1 addition & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The TomOpt project, and its continued development and support, is the result of the combined work of many people, whose contributions are summarised below.

In order to start time, the TomOpt authors/contributors are: Giles Strong, Tommaso Dorigo, Andrea Giammanco, Pietro Vischia, Jan Kieseler, Maxime Lagrange, Federico Nardi, Haitham Zaraket, Max Lamparth, Federica Fanzago, Oleg Savchenko, Nitesh Sharma, Anna Bordignon, Mariam Safieldin.
In order to start time, the TomOpt authors/contributors are: Giles Strong, Tommaso Dorigo, Andrea Giammanco, Pietro Vischia, Jan Kieseler, Maxime Lagrange, Federico Nardi, Haitham Zaraket, Max Lamparth, Federica Fanzago, Oleg Savchenko, Nitesh Sharma, Anna Bordignon, Mariam Safieldin, Aitor Orio.

## Giles Chatham Strong (@GilesStrong)

Expand Down
3 changes: 2 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

# -- Path setup --------------------------------------------------------------

import datetime

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
import datetime

sys.path.insert(0, os.path.abspath("../.."))

Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# User requirements
functorch
torch>=1.10.0
torch>=1.10.0,<2.0.0 # pt 2 hasn't been fully tested yet
seaborn ~= 0.11.0
matplotlib >= 3.1
numpy >=1.20.2
Expand All @@ -21,4 +21,5 @@ pytest
mypy
pytest-mock
flaky
pytest-lazy-fixture
pytest-lazy-fixture
isort
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ license_files = LICENSE
[bdist_wheel]
universal=0

[isort]
profile = black

[mypy]
python_version = 3.8
disallow_untyped_calls = False
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# -*- coding: utf-8 -*-

try:
from setuptools import setup, find_packages
from setuptools import find_packages, setup
except ImportError:
from distutils.core import setup, find_packages
from distutils.core import find_packages, setup

with open("README.md", encoding="utf-8") as fin:
long_description = fin.read()

dev_only = ["pre-commit", "black", "flake8", "mypy", "pytest", "pytest-mock", "flaky", "pytest-lazy-fixture"]
dev_only = ["pre-commit", "black", "flake8", "mypy", "pytest", "isort", "pytest-mock", "flaky", "pytest-lazy-fixture"]
with open("requirements.txt", encoding="utf-8") as f:
requirements = [r for r in f.read().strip().split("\n") if r not in dev_only]

Expand Down
61 changes: 35 additions & 26 deletions tests/test_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,53 @@
import pytest
import numpy as np
from pytest_mock import mocker # noqa F401
import math
import pandas as pd
import os
from functools import partial
from glob import glob
from fastcore.all import Path
import matplotlib.pyplot as plt
import h5py
import os

import h5py
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pytest
import torch
from torch import Tensor
import torch.nn.functional as F
from fastcore.all import Path
from pytest_mock import mocker # noqa F401
from torch import Tensor

from tomopt.optimisation.callbacks.callback import Callback
from tomopt.optimisation.callbacks.eval_metric import EvalMetric
from tomopt.muon import MuonBatch, MuonGenerator2016
from tomopt.optimisation.callbacks import (
NoMoreNaNs,
PredHandler,
CostCoefWarmup,
HeatMapGif,
HitRecord,
MetricLogger,
MuonResampler,
NoMoreNaNs,
OneCycle,
PanelMetricLogger,
ScatterRecord,
HitRecord,
CostCoefWarmup,
PanelOptConfig,
MuonResampler,
HeatMapGif,
VolumeTargetPredHandler,
Save2HDF5PredHandler,
WarmupCallback,
PanelUpdateLimiter,
PostWarmupCallback,
PredHandler,
Save2HDF5PredHandler,
ScatterRecord,
SigmoidPanelSmoothnessSchedule,
PanelUpdateLimiter,
OneCycle,
VolumeTargetPredHandler,
WarmupCallback,
)
from tomopt.optimisation.callbacks.callback import Callback
from tomopt.optimisation.callbacks.eval_metric import EvalMetric
from tomopt.optimisation.loss import VoxelX0Loss
from tomopt.optimisation.wrapper.volume_wrapper import AbsVolumeWrapper, FitParams, PanelVolumeWrapper
from tomopt.volume import PanelDetectorLayer, DetectorPanel, DetectorHeatMap, SigmoidDetectorPanel
from tomopt.muon import MuonBatch, MuonGenerator2016
from tomopt.optimisation.wrapper.volume_wrapper import (
AbsVolumeWrapper,
FitParams,
PanelVolumeWrapper,
)
from tomopt.volume import (
DetectorHeatMap,
DetectorPanel,
PanelDetectorLayer,
SigmoidDetectorPanel,
)

LW = Tensor([1, 1])
SZ = 0.1
Expand Down
19 changes: 13 additions & 6 deletions tests/test_forwards_backwards.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
from collections import defaultdict
import pytest
from pytest_lazyfixture import lazy_fixture

import pytest
import torch
from torch import nn, Tensor
import torch.nn.functional as F
from pytest_lazyfixture import lazy_fixture
from torch import Tensor, nn

from tomopt.core import X0
from tomopt.volume import Volume, PassiveLayer, PanelDetectorLayer, DetectorPanel, DetectorHeatMap, SigmoidDetectorPanel
from tomopt.inference import PanelX0Inferrer, ScatterBatch
from tomopt.muon import MuonBatch, MuonGenerator2016
from tomopt.inference import ScatterBatch, PanelX0Inferrer
from tomopt.optimisation import VoxelX0Loss, MuonResampler
from tomopt.optimisation import MuonResampler, VoxelX0Loss
from tomopt.volume import (
DetectorHeatMap,
DetectorPanel,
PanelDetectorLayer,
PassiveLayer,
SigmoidDetectorPanel,
Volume,
)

LW = Tensor([1, 1])
SZ = 0.1
Expand Down
19 changes: 9 additions & 10 deletions tests/test_heatmap.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import pytest
from pytest_mock import mocker # noqa F401
from unittest.mock import patch
import numpy as np
from fastcore.all import Path
import os
from unittest.mock import patch

import numpy as np
import pytest
import torch
from fastcore.all import Path
from pytest_mock import mocker # noqa F401
from torch import Tensor, nn

from tomopt.volume import PassiveLayer, PanelDetectorLayer, DetectorHeatMap, Volume
from tomopt.volume.heatmap import GMM
from tomopt.optimisation import MuonResampler
from tomopt.muon import MuonBatch, MuonGenerator2016
from tomopt.core import X0
from tomopt.muon import MuonBatch, MuonGenerator2016
from tomopt.optimisation import MuonResampler
from tomopt.utils import jacobian

from tomopt.volume import DetectorHeatMap, PanelDetectorLayer, PassiveLayer, Volume
from tomopt.volume.heatmap import GMM

LW = Tensor([1, 1])
SZ = 0.1
Expand Down
28 changes: 17 additions & 11 deletions tests/test_inference.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
import pytest
from pytest_mock import mocker # noqa F401
import numpy as np
from unittest.mock import patch
from typing import Tuple
import math
from pytest_lazyfixture import lazy_fixture
from typing import Tuple
from unittest.mock import patch

import numpy as np
import pytest
import torch
from torch import Tensor, nn
import torch.nn.functional as F
from pytest_lazyfixture import lazy_fixture
from pytest_mock import mocker # noqa F401
from torch import Tensor, nn

from tomopt.volume import PassiveLayer, Volume, PanelDetectorLayer, DetectorPanel, SigmoidDetectorPanel
from tomopt.muon import MuonBatch, MuonGenerator2016
from tomopt.core import X0
from tomopt.inference import (
DenseBlockClassifierFromX0s,
GenScatterBatch,
PanelX0Inferrer,
ScatterBatch,
GenScatterBatch,
DenseBlockClassifierFromX0s,
)
from tomopt.inference.volume import AbsIntClassifierFromX0
from tomopt.muon import MuonBatch, MuonGenerator2016
from tomopt.optimisation import MuonResampler
from tomopt.utils import jacobian
from tomopt.volume import (
DetectorPanel,
PanelDetectorLayer,
PassiveLayer,
SigmoidDetectorPanel,
Volume,
)

LW = Tensor([1, 1])
SZ = 0.1
Expand Down
15 changes: 10 additions & 5 deletions tests/test_loss.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from pytest_mock import mocker # noqa F401
import numpy as np

import torch
from torch import nn, Tensor
import torch.nn.functional as F

from tomopt.optimisation import VoxelX0Loss, VoxelClassLoss, VolumeClassLoss, VolumeIntClassLoss, integer_class_loss
from pytest_mock import mocker # noqa F401
from torch import Tensor, nn

from tomopt.optimisation import (
VolumeClassLoss,
VolumeIntClassLoss,
VoxelClassLoss,
VoxelX0Loss,
integer_class_loss,
)
from tomopt.optimisation.loss.loss import AbsDetectorLoss
from tomopt.volume import Volume

Expand Down
10 changes: 5 additions & 5 deletions tests/test_muon.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import pytest
from pytest_mock import mocker # noqa F401
import numpy as np

import pytest
import torch
from pytest_mock import mocker # noqa F401
from torch import Tensor, nn

from tomopt.muon import MuonGenerator2016, MuonGenerator2015, MuonBatch
from tomopt.volume import PassiveLayer, Volume, PanelDetectorLayer, DetectorPanel
from tomopt.core import X0
from tomopt.muon import MuonBatch, MuonGenerator2015, MuonGenerator2016
from tomopt.volume import DetectorPanel, PanelDetectorLayer, PassiveLayer, Volume

N = 3
LW = Tensor([1, 1])
Expand Down Expand Up @@ -307,6 +306,7 @@ def test_muon_batch_scatter_dtheta_dphi():
assert (batch.xy == start.xy).all()


@pytest.mark.flaky(max_runs=3, min_passes=1)
def test_muon_batch_angle_consistency():
volume = Volume(get_panel_layers())
mg = MuonGenerator2016.from_volume(volume)
Expand Down
11 changes: 5 additions & 6 deletions tests/test_passives.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import pytest

import torch
from torch import nn, Tensor
import torch.nn.functional as F
from torch import Tensor, nn

from tomopt.core import X0
from tomopt.optimisation.data.passives import (
AbsPassiveGenerator,
BlockPresentPassiveGenerator,
PassiveYielder,
VoxelPassiveGenerator,
RandomBlockPassiveGenerator,
BlockPresentPassiveGenerator,
AbsPassiveGenerator,
VoxelPassiveGenerator,
)
from tomopt.volume import Volume, PassiveLayer, PanelDetectorLayer, DetectorPanel
from tomopt.volume import DetectorPanel, PanelDetectorLayer, PassiveLayer, Volume

LW = Tensor([1, 1])
SZ = 0.1
Expand Down
Loading

0 comments on commit c659f73

Please sign in to comment.