From 13e74f1808f7cdd3b9fe705ed77ac4c6471a7650 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 29 Oct 2024 09:36:47 -0400 Subject: [PATCH 1/8] added test folder --- test/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/__init__.py diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 00000000..e69de29b From 4b8940df3fedfe0db5b7096710e298ee2d973f20 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 29 Oct 2024 09:42:17 -0400 Subject: [PATCH 2/8] pyproject.toml --- pyproject.toml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..2a856caf --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,38 @@ +[build-system] +requires = ["setuptools >= 61", "wheel", "setuptools-scm[toml] >= 7.0.5"] +build-backend = "setuptools.build_meta" + +[project] +authors = [ + { name = "Kaelyn Dunnell" }, + { email = "kaelyn@mit.edu" }, +] +dynamic = ["version"] +name = "HISP" +description = "Hydrogen Inventory Simulations of PFCs" +readme = "README/md" +requires-python = ">=3.9" +license = { file = "LICENSE" } +dependencies = ["h_transport_materials"] +classifiers = [ + "Natural Language :: English", + "Topic :: Scientific/Engineering", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", +] + +[project.optional-dependencies] +test = ["pytest >= 5.4.3", "pytest-cov"] + +[project.urls] +Homepage = "https://github.com/RemDelaporteMathurin/FESTIM" +Issues = "https://github.com/RemDelaporteMathurin/FESTIM/issues" + + +[tool.setuptools_scm] +write_to = "src/hisp/_version.py" From 50e1f784d856076be45a33f1075f682881b2d086 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 29 Oct 2024 09:53:04 -0400 Subject: [PATCH 3/8] src structure + tests + gitignore --- .gitignore | 112 ++++++++++++++++++++ src/hisp/__init__.py | 1 + helpers.py => src/hisp/helpers.py | 0 scenario_test.txt => test/scenario_test.txt | 0 test/test_scenario.py | 27 +++++ 5 files changed, 140 insertions(+) create mode 100644 .gitignore create mode 100644 src/hisp/__init__.py rename helpers.py => src/hisp/helpers.py (100%) rename scenario_test.txt => test/scenario_test.txt (100%) create mode 100644 test/test_scenario.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e9a471c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,112 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# version file +**_version.py + +# Input/Output files +*.bp +*.xdmf +*.h5 \ No newline at end of file diff --git a/src/hisp/__init__.py b/src/hisp/__init__.py new file mode 100644 index 00000000..e7c053e3 --- /dev/null +++ b/src/hisp/__init__.py @@ -0,0 +1 @@ +from .helpers import PulsedSource, Scenario diff --git a/helpers.py b/src/hisp/helpers.py similarity index 100% rename from helpers.py rename to src/hisp/helpers.py diff --git a/scenario_test.txt b/test/scenario_test.txt similarity index 100% rename from scenario_test.txt rename to test/scenario_test.txt diff --git a/test/test_scenario.py b/test/test_scenario.py new file mode 100644 index 00000000..7fdc624d --- /dev/null +++ b/test/test_scenario.py @@ -0,0 +1,27 @@ +from hisp.helpers import Scenario +import os +import pytest + +current_dir = os.path.dirname(__file__) +scenario_path = os.path.join(current_dir, "scenario_test.txt") + + +def test_maximum_time(): + # BUILD + my_scenario = Scenario(scenario_path) + expected_maximum_time = 2 * (455 + 455 + 650 + 1000) + 2 * (36 + 36 + 180 + 1000) + + # RUN + computed_maximum_time = my_scenario.get_maximum_time() + + # TEST + assert computed_maximum_time == expected_maximum_time + + +@pytest.mark.parametrize("t, expected_row", [(0, 0), (6000, 1)]) +def test_get_pulse_row(t, expected_row): + my_scenario = Scenario(scenario_path) + + pulse_row = my_scenario.get_row(t=t) + + assert pulse_row == expected_row From 029143e6d1521d9dd2413313b8081809996621c4 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 29 Oct 2024 09:53:44 -0400 Subject: [PATCH 4/8] fixed workflow file --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 193479e7..1ea23677 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: shell: bash -l {0} run: python simple_mb.py - - name: Install dependencies + - name: Install dependencies shell: bash -l {0} run: | pip install pytest pytest-cov @@ -35,4 +35,4 @@ jobs: - name: Run tests shell: bash -l {0} run: | - pytest tests/ --cov festim --cov-report xml --cov-report term + pytest test/ --cov festim --cov-report xml --cov-report term From c74cbacd91e7abfb1038efe64475671897b9f4f2 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 29 Oct 2024 09:56:13 -0400 Subject: [PATCH 5/8] moved example to CI --- example_reading_scenario_file.py | 31 ------------------------------- test/test_scenario.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 31 deletions(-) delete mode 100644 example_reading_scenario_file.py diff --git a/example_reading_scenario_file.py b/example_reading_scenario_file.py deleted file mode 100644 index f1757378..00000000 --- a/example_reading_scenario_file.py +++ /dev/null @@ -1,31 +0,0 @@ -from helpers import Scenario - -my_scenario = Scenario("scenario.txt") - -print(my_scenario.data) - -import numpy as np - -times = np.linspace(0, my_scenario.get_maximum_time(), 1000) -pulse_types = [] -for t in times: - pulse_type = my_scenario.get_pulse_type(t) - pulse_types.append(pulse_type) - -import matplotlib.pyplot as plt - -# color the line based on the pulse type -color = { - "FP": "red", - "ICWC": "blue", - "RISP": "green", - "GDC": "orange", - "BAKE": "purple", -} - -colors = [color[pulse_type] for pulse_type in pulse_types] - -for i in range(len(times) - 1): - plt.plot(times[i : i + 2], np.ones_like(times[i : i + 2]), c=colors[i]) -# plt.xscale("log") -plt.show() diff --git a/test/test_scenario.py b/test/test_scenario.py index 7fdc624d..0b3eee08 100644 --- a/test/test_scenario.py +++ b/test/test_scenario.py @@ -1,6 +1,8 @@ from hisp.helpers import Scenario import os import pytest +import numpy as np +import matplotlib.pyplot as plt current_dir = os.path.dirname(__file__) scenario_path = os.path.join(current_dir, "scenario_test.txt") @@ -25,3 +27,29 @@ def test_get_pulse_row(t, expected_row): pulse_row = my_scenario.get_row(t=t) assert pulse_row == expected_row + + +def test_reading_a_file(): + my_scenario = Scenario(scenario_path) + + times = np.linspace(0, my_scenario.get_maximum_time(), 1000) + pulse_types = [] + for t in times: + pulse_type = my_scenario.get_pulse_type(t) + pulse_types.append(pulse_type) + + # color the line based on the pulse type + color = { + "FP": "red", + "ICWC": "blue", + "RISP": "green", + "GDC": "orange", + "BAKE": "purple", + } + + colors = [color[pulse_type] for pulse_type in pulse_types] + + for i in range(len(times) - 1): + plt.plot(times[i : i + 2], np.ones_like(times[i : i + 2]), c=colors[i]) + # plt.xscale("log") + # plt.show() From 596705edcda6ef5c98793fa546c3dfde602bead8 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 29 Oct 2024 10:00:10 -0400 Subject: [PATCH 6/8] moved CustomClass to package --- simple_mb.py | 4 ++-- src/hisp/__init__.py | 2 ++ new_h_transport_class.py => src/hisp/h_transport_class.py | 0 3 files changed, 4 insertions(+), 2 deletions(-) rename new_h_transport_class.py => src/hisp/h_transport_class.py (100%) diff --git a/simple_mb.py b/simple_mb.py index d0a2d329..a95d3f56 100644 --- a/simple_mb.py +++ b/simple_mb.py @@ -10,8 +10,8 @@ import dolfinx.fem as fem import dolfinx -from helpers import PulsedSource, Scenario -from new_h_transport_class import CustomProblem +from hisp.helpers import PulsedSource, Scenario +from hisp import CustomProblem # dolfinx.log.set_log_level(dolfinx.log.LogLevel.INFO) diff --git a/src/hisp/__init__.py b/src/hisp/__init__.py index e7c053e3..391c7d92 100644 --- a/src/hisp/__init__.py +++ b/src/hisp/__init__.py @@ -1 +1,3 @@ from .helpers import PulsedSource, Scenario + +from .h_transport_class import CustomProblem diff --git a/new_h_transport_class.py b/src/hisp/h_transport_class.py similarity index 100% rename from new_h_transport_class.py rename to src/hisp/h_transport_class.py From 940b17fa942a1dffd4d4c947bf0f44c4502e3f09 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 29 Oct 2024 10:02:09 -0400 Subject: [PATCH 7/8] changed license --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2a856caf..49ecce08 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", - "License :: OSI Approved :: Apache Software License", + "License :: OSI Approved :: MIT", "Operating System :: OS Independent", ] From e19413dd81a4c62e3a276b3971006f7b98c3f644 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Tue, 29 Oct 2024 10:03:52 -0400 Subject: [PATCH 8/8] better install --- .github/workflows/ci.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ea23677..f154d4b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,16 +23,15 @@ jobs: channels: conda-forge environment-file: environment.yml - - name: Run example + - name: install HISP shell: bash -l {0} - run: python simple_mb.py - - - name: Install dependencies - shell: bash -l {0} - run: | - pip install pytest pytest-cov + run: python -m pip install .[test] - name: Run tests shell: bash -l {0} run: | pytest test/ --cov festim --cov-report xml --cov-report term + + - name: Run example + shell: bash -l {0} + run: python simple_mb.py