Skip to content
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
b315069
Add radio-astronomy use case
okrochak Jan 23, 2025
b1755f4
radio-astronomy-raw file/dependecies clean-up
okrochak Jan 23, 2025
2b61a67
Update the dependencies for radio-astronomy
okrochak Jan 28, 2025
6ef72af
update lock file
okrochak Jan 30, 2025
05671c1
comment out real data tests
okrochak Jan 31, 2025
cc3f35c
Skeleton structure for radio-astronomy integration
Feb 18, 2025
bcbc1ac
WIP: radio-astronomy integration
Feb 19, 2025
6ef0d73
radio-astronomy inte
okrochak Feb 26, 2025
8dc7eaf
Refactoring some code, added a pipeline.py file to test config.yaml f…
okrochak Feb 26, 2025
99e9900
updated data storage loc for git ignore
Mar 11, 2025
64ea1e1
merging from origin/main, keep my uv.lock file
Mar 11, 2025
41f56f0
mergen from origin/main
Mar 11, 2025
7960c3e
WIP set-up exec-pipeline from config.yaml
Mar 13, 2025
f556295
WIP running from config.yaml
Mar 13, 2025
52f9e55
additional config files for various networks
okrochak Mar 13, 2025
c96a6f8
radio-astronomy integration
okrochak Mar 17, 2025
e323381
finalized execution from Hydra config
okrochak Mar 17, 2025
ca03dbb
Restructuring radio-astronomy use-case
okrochak Mar 18, 2025
065f619
Fine-tuning of config.yaml for HPC deployment
okrochak Mar 18, 2025
167addb
removed radio-astronomy-raw
okrochak Mar 19, 2025
a7535f2
further fixes for multi-node deployment
okrochak Mar 19, 2025
9d83812
WIP radio-astronomy - setting up for HPC/laptop use
okrochak Mar 25, 2025
13a383b
pipeline_methods model loading fix
okrochak Mar 26, 2025
2ee572c
pipeline_methods hotfix
okrochak Mar 26, 2025
193d92d
writing tests for radio-astronomy
okrochak Mar 27, 2025
4b67117
Radio-astronomy use-case
okrochak Mar 31, 2025
58b289a
Pull the latest changes from main before submitting a PR
okrochak Mar 31, 2025
fd184f9
adjust for new TorchTrainer.execute() implementation
okrochak Mar 31, 2025
b1ca37b
fix documentation warnings and failing radio-astronomy tests due to n…
okrochak Apr 1, 2025
b5d05ab
fix title underline too short sphinx warning
okrochak Apr 1, 2025
f9fa442
attempt to make radio-astronomy pytests pass on GH
okrochak Apr 1, 2025
764e864
Attempt to make radio-astronomy pytests pass in GH env
okrochak Apr 1, 2025
79a0cd9
attempt to fix failing pytest
okrochak Apr 7, 2025
141de2d
pytest fix
okrochak Apr 7, 2025
8eb9647
responding to Jarl's comments - refactoring of dataset classes into one
okrochak Apr 7, 2025
e18492e
"Integration of new PulsarDataset class, updated configuration files"
okrochak Apr 9, 2025
f72e59b
responding to Jarl's comments - refactoring of dataset classes into o…
okrochak Apr 9, 2025
f27d095
code refactoring
okrochak Apr 9, 2025
5d01de6
Refactoring to remove src/ folder and get use-case dependencies throu…
okrochak Apr 15, 2025
d5d54c1
quickfix failing unet test
okrochak Apr 15, 2025
17fbb82
Refactoring with black to match coding style
okrochak Apr 16, 2025
eb17b5b
Add optional scaling functionality to trainer and config
okrochak Apr 16, 2025
c05e0d4
Update use-case code signatures. Remove binary model files. Include a…
okrochak Apr 16, 2025
6c938bc
test retry
okrochak Apr 16, 2025
c608fc5
pytest fix
okrochak Apr 16, 2025
4b79940
update radio-astornomy test suite
okrochak Apr 16, 2025
e634cfc
Removed dependency on .test_dataset, had to adjust the test suite
okrochak Apr 16, 2025
a7e5d25
test retry
okrochak Apr 16, 2025
e25e072
test fix
okrochak Apr 16, 2025
5ac5210
retry tick pipeline
okrochak Apr 16, 2025
bea602b
add loadfile to tests
jarlsondre Apr 23, 2025
abc789c
added fixtures for tests and updated data.py
okrochak Apr 23, 2025
ab0c4cf
Merge branch 'radio-astronomy' of github.com:interTwin-eu/itwinai int…
okrochak Apr 23, 2025
0dc6e46
--dist loadscope attepmt
okrochak Apr 23, 2025
eb637d1
retry test fix
okrochak May 5, 2025
60eee30
Merge remote-tracking branch 'origin/main' into radio-astronomy
okrochak May 5, 2025
e239623
test loadfile
okrochak May 5, 2025
8566af3
pytest fix retry
okrochak May 5, 2025
e64c739
update uv.lock
okrochak May 5, 2025
c47cad6
pytest fix
okrochak May 5, 2025
52df3b2
pytest fix
okrochak May 5, 2025
445dcd0
pytest fix
okrochak May 5, 2025
6f4b5e6
.
okrochak May 5, 2025
93de7aa
.
okrochak May 5, 2025
b72d1c4
.
okrochak May 5, 2025
86c45bc
.
okrochak May 5, 2025
26880d6
.
okrochak May 5, 2025
7a0c645
.
okrochak May 5, 2025
a9cc5a2
.
okrochak May 5, 2025
319f243
.
okrochak May 5, 2025
982fb8a
.
okrochak May 5, 2025
333e780
.
okrochak May 5, 2025
fc92c3c
finally fixed pytest issue. Wrong UV error description.
okrochak May 5, 2025
d94391f
Final fixes to respond to PR comments:
okrochak May 7, 2025
b29a41c
Inshallah the test shall pass
okrochak May 7, 2025
5b3818c
Merge branch 'main' into radio-astronomy
okrochak May 13, 2025
573f80b
Added and tested support for deepspeed and horovod
okrochak May 14, 2025
3d2999f
Merge branch 'main' into radio-astronomy
okrochak May 14, 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
10 changes: 5 additions & 5 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
remove-android: true
remove-haskell: true
remove-codeql: true

- uses: actions/checkout@v4

- name: Move Docker directory
Expand All @@ -30,7 +30,7 @@ jobs:
sudo mv /var/lib/docker /docker/ &&
sudo ln -s /docker/docker /var/lib/docker &&
sudo systemctl restart docker

# Run tests with pytest in a container
- name: Run Integration Test (development pipeline)
uses: dagger/dagger-for-github@v7
Expand All @@ -42,7 +42,7 @@ jobs:
--context ..
--dockerfile ../env-files/torch/skinny.Dockerfile
test-local
--cmd "pytest,-v,--disable-warnings,-n,logical,/app/tests/,-m,not hpc and not tensorflow"
--cmd "pytest,-v,--disable-warnings,-n,logical,/app/tests/,--dist,loadfile,-m,not hpc and not tensorflow"
logs
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
version: "0.18.0"
Expand All @@ -61,14 +61,14 @@ jobs:
# - name: Make PyTorch virtualenv
# shell: bash -l {0}
# run: make torch-env-cpu

# # Comment this back in to also build tensorflow env
# # - name: Make Tensorflow virtualenv
# # shell: bash -l {0}
# # run: make tensorflow-env-cpu

# # NOTE, to change the name of the env in which tests are run, set custom TORCH_ENV
# # and TF_ENV env variables. Default environment names are ".venv-pytorch" and
# # and TF_ENV env variables. Default environment names are ".venv-pytorch" and
# # ".venv-tf"

# - name: Run pytest for workflows
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ mnist-sample-data/
exp_data/
mnist_dataset/


# Kubernetes
secret*.yaml

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ contains thoroughly tested features aligned with the toolkit's most recent relea
use-cases/cyclones_doc
use-cases/mnist_doc
use-cases/xtclim_doc
use-cases/radio-astronomy

.. toctree::
:maxdepth: 2
Expand Down
58 changes: 58 additions & 0 deletions docs/use-cases/radio-astronomy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Pulsar Segmentation and Analysis for Radio-Astronomy (HTW Berlin)
===============================================================================================
The code is adapted from
`this repository <https://gitlab.com/ml-ppa/pulsarrfi_nn/-/tree/version_0.2/unet_semantic_segmentation?ref_type=heads>`_.
Please visit the original repository for more technical information on the code.
This use case features a sophisticated pipeline composed of few neural networks.

Integration Author: Oleksandr Krochak, FZJ

Environment Management
-----------------------------------------------------------------------------------------------
It is recommended to use the UV environment for running this pipeline.
The overview of itwinai-wide module dependencies can be found in `intertwin/pyproject.toml`.
By running `uv sync --extra devel --extra torch --extra radio-astronomy`, the uv lockfile will
be generated/updated that ensures that correct dependencies are installed. If you want to
change some use-case specific dependencies, please do so in pyproject.toml in the radio-astronomy
section. Afterwards, re-run `uv sync` with the same flags.

Alternatively, you can install the required dependencies from the use-case directory:
`pip install requirements.txt`

Running from a configuration file
-----------------------------------------------------------------------------------------------
You can run the full pipeline sequence by executing the following commands locally.
itwinai will read these commands from the `config.yaml` file in the root of the repository.
1. Generate the synthetic data - `itwinai exec-pipeline +pipe_key=syndata_pipeline`
2. Initialize and train a UNet model - `itwinai exec-pipeline +pipe_key=unet_pipeline`
3. Initialize and train a FilterCNN model - `itwinai exec-pipeline +pipe_key=fcnn_pipeline`
4. Initialize and train a CNN1D model - `itwinai exec-pipeline +pipe_key=cnn1d_pipeline`
5. Compile a full pipeline and test it - `itwinai exec-pipeline +pipe_key=evaluate_pipeline`

When running on HPC, you can use the `batch.sh` SLURM script to run these commands.

Logging with MLflow
-----------------------------------------------------------------------------------------------
By default, the `config.yaml` ensures that the MLflow logging is enabled during the training.
During or after the run, you can launch an MLflow server by executing
`mlflow server --backend-store-uri mllogs/mlflow` and connecting to `http://127.0.0.1:5000/`
in your browser.

Test suite
-----------------------------------------------------------------------------------------------
The test suite is located in the `tests/use-cases/radio-astronomy` folder.

Before running the test suite, you should make sure that the pytorch fixture in:
`tests/use-cases/radio-astronomy/test_radio-astronomy.py`:torch_env()
is correctly defined and corresponds to the virtual environment where itwinai is installed on
your system.

It contains integration tests for each of the pipelines 1-5 mentioned above. The configuration
and execution of the test suite is defined in:
`tests/use-cases/radio-astronomy/test_radio-astronomy.py`
and in the configuration file in the use-case repository:
`use-cases/radio-astronomy/.config-test.yaml`.
If you are updating the test suite, make sure you update both of these files.

Feel free to change the pytest markers as needed, but be careful with pushing these changes.
Tests should be able to run in an isolated environment.
24 changes: 21 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
requires = ["setuptools", "setuptools-scm", "wheel"]
build-backend = "setuptools.build_meta"


[project]
name = "itwinai"
version = "0.3.1"
Expand Down Expand Up @@ -50,6 +51,19 @@ dependencies = [
]

[project.optional-dependencies]
# dependencies that are not included by dev or torch
# but needed for radio-astronomy.
radio-astronomy = [
"pulsarrfi-nn @ git+https://gitlab.com/ml-ppa/pulsarrfi_nn.git@version_0.2#subdirectory=unet_semantic_segmentation",
"pulsardt @ git+https://gitlab.com/ml-ppa/pulsardt@main",
"ipywidgets",
"tqdm>=4.65.0",
"numpyencoder>=0.3.0",
"pyquaternion>=0.9.9",
"scikit-image>=0.22.0",
"pyqt6>=6.0",
]

torch = [
"torch==2.4.*",
"lightning>=2",
Expand Down Expand Up @@ -130,16 +144,20 @@ conflicts = [[{ extra = "tf-cuda" }, { extra = "torch" }]]
# Use PyTorch with CUDA for anything that is not macos
[tool.uv.sources]
torch = [{ index = "pytorch-cu121", marker = "platform_system != 'Darwin'" }]
torchvision = [
{ index = "pytorch-cu121", marker = "platform_system != 'Darwin'" },
]
torchvision = [{ index = "pytorch-cu121", marker = "platform_system != 'Darwin'" }]
pulsardt = [{ index = "pulsar-dt"}]

# Specific index for pytorch
[[tool.uv.index]]
name = "pytorch-cu121"
url = "https://download.pytorch.org/whl/cu121"
explicit = true

[[tool.uv.index]]
name = "pulsar-dt"
url = "https://gitlab.com/api/v4/projects/59840702/packages/pypi/simple"
explicit = true

# Ruff configuration: https://docs.astral.sh/ruff/configuration/
[tool.ruff]
line-length = 95
Expand Down
2 changes: 1 addition & 1 deletion tests/loggers/test_prov4ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@ def test_log_prov_documents(logger_instance, mlflow_run):

log_prov_documents.assert_called_once_with(create_graph=True, create_svg=True)
mlflow_log_artifact.assert_any_call("doc1")
mlflow_log_artifact.assert_any_call("doc2")
mlflow_log_artifact.assert_any_call("doc2")
121 changes: 121 additions & 0 deletions tests/use-cases/test_radio_astronomy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# --------------------------------------------------------------------------------------
# Part of the interTwin Project: https://www.intertwin.eu/
#
# Created by: Alex Krochak
#
# Credit:
# - Alex Krochak <o.krochak@fz-juelich.de> - FZJ
# --------------------------------------------------------------------------------------

"""Tests for radio-astronomy use case.

Intended to be integration tests, to make sure that updates in the code base
do not break use cases' workflows.

This is meant to be run from the main itwinai directory, not the use-case folder !!!
"pytest use-cases/radio-astronomy/tests/test_radio-astronomy.py"

NOTE FOR DEVELOPERS: if you are editing this file, make sure that entries in
use-cases/radio-astronomy/.config-test.yaml are updated accordingly !!!
"""

import os
import subprocess
from pathlib import Path
import shutil

import pytest

USECASE_FOLDER = Path("use-cases", "radio-astronomy").resolve()

@pytest.fixture
def torch_env() -> str:
"""Returns absolute path to torch virtual environment."""
env_path = Path(os.environ.get("TORCH_ENV", "./.venv"))
return str(env_path.resolve())

@pytest.fixture
def syndata(tmp_path, torch_env,install_requirements):
# This fixture implicitly tests the synthetic data generation pipeline
install_requirements(USECASE_FOLDER, torch_env)

cmd_data = (
f"{torch_env}/bin/itwinai exec-pipeline --config-name .config-test "
f"+pipe_key=syndata_pipeline ++syndata_test_dir={tmp_path}/ "
)
if len(os.listdir(tmp_path)) == 0: # only run if directory is empty
# Copy the necessary files to the temporary directory for testing
shutil.copy(USECASE_FOLDER / ".config-test.yaml", tmp_path)
shutil.copy(USECASE_FOLDER / "data.py", tmp_path)
shutil.copy(USECASE_FOLDER / "trainer.py", tmp_path)

subprocess.run(cmd_data.split(), check=True, cwd=tmp_path)

return tmp_path

@pytest.fixture
def generate_unet(torch_env, syndata):
"""Generate the U-Net model for the Filter-CNN test. """
cmd = (
f"{torch_env}/bin/itwinai exec-pipeline --config-name .config-test "
f"+pipe_key=unet_pipeline ++image_directory={syndata}/ ++mask_directory={syndata}/ "
)

subprocess.run(cmd.split(), check=True, cwd=syndata)

# @pytest.mark.skip(reason="dependent on .test_dataset, incoroporated into integration test")
def test_radio_astronomy_unet(torch_env, syndata, install_requirements):
"""Test U-Net Pulsar-DDT trainer by running it end-to-end
via the config-test.yaml configuration file."""

install_requirements(USECASE_FOLDER, torch_env)

cmd = (
f"{torch_env}/bin/itwinai exec-pipeline --config-name .config-test "
f"+pipe_key=unet_pipeline ++image_directory={syndata}/ ++mask_directory={syndata}/ "
)

subprocess.run(cmd.split(), check=True, cwd=syndata)

@pytest.mark.functional
def test_radio_astronomy_filtercnn(torch_env, syndata, generate_unet, install_requirements):
"""Test Filter-CNN Pulsar-DDT trainer by running it end-to-end
via the config-test.yaml configuration file. Requires the U-Net model to be present."""

install_requirements(USECASE_FOLDER, torch_env)

cmd = (
f"{torch_env}/bin/itwinai exec-pipeline --config-name .config-test "
f"+pipe_key=fcnn_pipeline ++image_directory={syndata}/ ++mask_directory={syndata}/ "
)

subprocess.run(cmd.split(), check=True, cwd=syndata)

def test_radio_astronomy_cnn1d(torch_env, syndata, install_requirements):
"""Test CNN-1D Pulsar-DDT trainer by running it end-to-end
via the config-test.yaml configuration file."""

install_requirements(USECASE_FOLDER, torch_env)

cmd = (
f"{torch_env}/bin/itwinai exec-pipeline --config-name .config-test "
f"+pipe_key=cnn1d_pipeline ++image_directory={syndata}/ ++mask_directory={syndata}/ "
)

subprocess.run(cmd.split(), check=True, cwd=syndata)

@pytest.mark.skip(reason="dependent on large real data set")
def test_radio_astronomy_evaluate(torch_env):
"""Test the evaluate pipeline by running it end-to-end
via the config-test.yaml configuration file."""

cmd = (
f"{torch_env}/bin/itwinai exec-pipeline "
f"--config-name .config-test "
f"+pipe_key=evaluate_pipeline "
)

## Run the pipeline and check file generation in the use-case folder
subprocess.run(cmd.split(), check=True, cwd=USECASE_FOLDER)
## Clean up the use-case folder
subprocess.run("./.pytest-clean", check=True, cwd=USECASE_FOLDER)
Loading