Skip to content

Commit 6cf7674

Browse files
authored
Merge pull request #335 from MIT-PSFC/dev
Release v0.9
2 parents bf8820f + d746573 commit 6cf7674

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3121
-2836
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,9 @@
33
version: 2
44
updates:
55

6-
- package-ecosystem: "pip"
7-
directory: "/"
8-
target-branch: "dev"
9-
versioning-strategy: increase-if-necessary
10-
schedule:
11-
interval: "monthly"
12-
reviewers:
13-
- gtrevisan
14-
open-pull-requests-limit: 10
15-
166
- package-ecosystem: "github-actions"
177
directory: "/"
8+
target-branch: "dev"
189
schedule:
1910
interval: "monthly"
2011
reviewers:

.github/workflows/build.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ jobs:
2121

2222

2323
build:
24-
runs-on: ubuntu-latest
24+
if: |
25+
github.event_name == 'push' ||
26+
github.event_name == 'release' ||
27+
github.event.pull_request.draft == false
28+
runs-on: ubuntu-22.04
2529
steps:
2630

2731
- name: Checkout
2832
uses: actions/checkout@v4
2933

3034
- name: Install poetry
31-
run: pipx install poetry
35+
run: pipx install 'poetry<2.0.0'
3236

3337
- name: Setup Python
3438
uses: actions/setup-python@v5

.github/workflows/docs.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ concurrency:
2525

2626
jobs:
2727

28-
build:
29-
runs-on: ubuntu-latest
28+
docs:
29+
runs-on: ubuntu-22.04
3030
if: |
3131
github.event_name == 'push' ||
3232
github.event.pull_request.draft == false
@@ -36,7 +36,7 @@ jobs:
3636
uses: actions/checkout@v4
3737

3838
- name: Install poetry
39-
run: pipx install poetry
39+
run: pipx install 'poetry<2.0.0'
4040

4141
- name: Setup Python
4242
uses: actions/setup-python@v5
@@ -60,8 +60,8 @@ jobs:
6060
environment:
6161
name: github-pages
6262
url: ${{ steps.deployment.outputs.page_url }}
63-
runs-on: ubuntu-latest
64-
needs: build
63+
runs-on: ubuntu-22.04
64+
needs: docs
6565
steps:
6666
- name: Deploy to GitHub Pages
6767
id: deployment

.github/workflows/lint.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919

2020
black:
21-
runs-on: ubuntu-latest
21+
runs-on: ubuntu-22.04
2222
if: |
2323
github.event_name == 'push' ||
2424
github.event.pull_request.draft == false
@@ -27,7 +27,7 @@ jobs:
2727
- uses: actions/checkout@v4
2828

2929
- name: Install poetry
30-
run: pipx install poetry
30+
run: pipx install 'poetry<2.0.0'
3131

3232
- name: Setup Python
3333
uses: actions/setup-python@v5
@@ -43,7 +43,7 @@ jobs:
4343

4444

4545
pylint:
46-
runs-on: ubuntu-latest
46+
runs-on: ubuntu-22.04
4747
if: |
4848
github.event_name == 'push' ||
4949
github.event.pull_request.draft == false
@@ -52,7 +52,7 @@ jobs:
5252
- uses: actions/checkout@v4
5353

5454
- name: Install poetry
55-
run: pipx install poetry
55+
run: pipx install 'poetry<2.0.0'
5656

5757
- name: Setup Python
5858
uses: actions/setup-python@v5
@@ -68,7 +68,7 @@ jobs:
6868

6969

7070
ruff:
71-
runs-on: ubuntu-latest
71+
runs-on: ubuntu-22.04
7272
if: |
7373
github.event_name == 'push' ||
7474
github.event.pull_request.draft == false
@@ -77,7 +77,7 @@ jobs:
7777
- uses: actions/checkout@v4
7878

7979
- name: Install poetry
80-
run: pipx install poetry
80+
run: pipx install 'poetry<2.0.0'
8181

8282
- name: Setup Python
8383
uses: actions/setup-python@v5
@@ -93,7 +93,7 @@ jobs:
9393

9494

9595
shellcheck:
96-
runs-on: ubuntu-latest
96+
runs-on: ubuntu-22.04
9797
if: |
9898
github.event_name == 'push' ||
9999
github.event.pull_request.draft == false
@@ -109,7 +109,7 @@ jobs:
109109

110110

111111
yamllint:
112-
runs-on: ubuntu-latest
112+
runs-on: ubuntu-22.04
113113
if: |
114114
github.event_name == 'push' ||
115115
github.event.pull_request.draft == false
@@ -118,7 +118,7 @@ jobs:
118118
- uses: actions/checkout@v4
119119

120120
- name: Install poetry
121-
run: pipx install poetry
121+
run: pipx install 'poetry<2.0.0'
122122

123123
- name: Setup Python
124124
uses: actions/setup-python@v5

.github/workflows/stale.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@ name: Stale
55
# yamllint disable-line rule:truthy
66
on:
77
schedule:
8-
- cron: '30 1 * * *'
8+
- cron: '30 1 * * MON-FRI'
99

1010
permissions:
1111
issues: write
1212
pull-requests: write
1313

1414
jobs:
1515
stale:
16-
runs-on: ubuntu-latest
16+
runs-on: ubuntu-22.04
1717
steps:
1818
- uses: actions/stale@v9
1919
with:
2020
days-before-stale: 90
21-
days-before-close: 15
21+
days-before-close: 30
22+
stale-issue-message: >
23+
This issue has been open for 3 months with no activity.
24+
stale-pr-message: >
25+
This pull request has been open for 3 months with no activity.
26+
stale-issue-label: stale
27+
exempt-issue-labels: eternal
28+
exempt-pr-labels: eternal

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919

2020
pytest:
21-
runs-on: ubuntu-latest
21+
runs-on: ubuntu-22.04
2222
if: |
2323
github.event_name == 'push' ||
2424
github.event.pull_request.draft == false
@@ -113,7 +113,7 @@ jobs:
113113
| tee -a "$GITHUB_ENV"
114114
115115
- name: Install poetry
116-
run: pipx install poetry
116+
run: pipx install 'poetry<2.0.0'
117117

118118
- name: Setup Python
119119
uses: actions/setup-python@v5

README.md

Lines changed: 91 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,103 @@
11

22
# DisruptionPy
33

4-
An interoperable Python package for plasma disruption analysis and prediction using ML.
4+
#### An open-source physics-based Scientific Framework for Disruption Analysis of Fusion Plasmas for AI/ML applications
55

6-
## Background
6+
[![Workflow: Lint](https://github.com/MIT-PSFC/disruption-py/actions/workflows/lint.yml/badge.svg)](https://github.com/MIT-PSFC/disruption-py/actions/workflows/lint.yml)
7+
[![Workflow: Tests](https://github.com/MIT-PSFC/disruption-py/actions/workflows/tests.yml/badge.svg)](https://github.com/MIT-PSFC/disruption-py/actions/workflows/tests.yml)
8+
[![Workflow: Build](https://github.com/MIT-PSFC/disruption-py/actions/workflows/build.yml/badge.svg)](https://github.com/MIT-PSFC/disruption-py/actions/workflows/build.yml)
9+
[![Workflow: Docs](https://github.com/MIT-PSFC/disruption-py/actions/workflows/docs.yml/badge.svg)](https://github.com/MIT-PSFC/disruption-py/actions/workflows/docs.yml)
10+
[![Workflow: Dependabot](https://img.shields.io/badge/Dependabot-enabled-34d058?logo=github)](https://github.com/MIT-PSFC/disruption-py/actions/workflows/dependabot/dependabot-updates)
11+
[![Workflow: Stale](https://img.shields.io/badge/Stale%20bot-enabled-34d058?logo=github)](https://github.com/MIT-PSFC/disruption-py/actions/workflows/stale.yml)
712

8-
A key element of plasma control systems (PCS) in tokamak reactors is the prediction and avoidance of disruptions, sudden losses of the thermal and magnetic energy stored within the plasma that can occur when tokamaks operate near regions of plasma instability or because of system malfunctions.
9-
The energy released during disruptions can cause severe damage to plasma-facing components, limiting experimental operation or even the device lifetime.
10-
This poses a serious challenge to next-step fusion experiments such as SPARC, which will have to operate near some of the limits of plasma stability to achieve its intended performance and will do so at for long and frequent intervals.
11-
Previous work has shown the promise of machine-learning (ML) algorithms for disruption prediction in both DIII-D and EAST -- the Experimental Advanced Superconducting Tokamak in China -- PCS.
12-
This is also due to the fact that fusion science currently lacks first-principle, theoretical solutions to fully predict and avoid disruptions.
13+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
14+
[![Linting: pylint](https://img.shields.io/badge/linting-pylint-yellowgreen)](https://github.com/pylint-dev/pylint)
15+
[![Linting: ruff](https://img.shields.io/badge/linting-ruff-purple)](https://github.com/astral-sh/ruff)
16+
[![Linting: shellcheck](https://img.shields.io/badge/linting-shellcheck-lightgreen)](https://github.com/koalaman/shellcheck)
17+
[![Linting: yamllint](https://img.shields.io/badge/linting-yamllint-lightblue)](https://github.com/adrienverge/yamllint)
18+
[![Testing: pytest](https://img.shields.io/badge/testing-pytest-red)](https://github.com/pylint-dev/pylint-pytest)
19+
20+
[![Supported versions](https://img.shields.io/pypi/pyversions/disruption-py)](https://github.com/MIT-PSFC/disruption-py/blob/main/pyproject.toml)
21+
[![Stats: downloads](https://static.pepy.tech/badge/disruption-py)](https://pepy.tech/project/disruption-py)
22+
[![Available: PyPI](https://img.shields.io/pypi/v/disruption-py.svg)](https://pypi.org/project/disruption-py/)
23+
[![Available: Zenodo](https://zenodo.org/badge/DOI/10.5281/zenodo.13935223.svg)](https://doi.org/10.5281/zenodo.13935223)
24+
[![License: MIT](https://img.shields.io/pypi/l/disruption-py?color=750014)](https://github.com/MIT-PSFC/disruption-py/blob/main/LICENSE)
25+
26+
## Concept
27+
28+
DisruptionPy is an open-source Scientific Python package for fast retrieval of experimental Fusion data from [MDSplus](https://www.mdsplus.org/) servers.
29+
The library allows an efficient database preparation for downstream analysis and/or ML model development for disruption studies.
30+
At present, the main supported machines are [Alcator C-Mod](https://en.wikipedia.org/wiki/Alcator_C-Mod) and [DIII-D](https://en.wikipedia.org/wiki/DIII-D_(tokamak)).
1331

14-
DisruptionPy is an open-source python package for training, updating, and evaluating algorithms for disruption prediction and avoidance that can be applied to Alcator C-Mod and DIII-D data, and can deploy models in DIII-D and EAST (TBD) PCSs.
1532

1633
## Overview
1734

18-
DisruptionPy makes it easy to retrieve tabular data from MDSplus databases efficiently.
19-
Users can create their own methods and/or use built-in methods that retrieve and derive a variety of important parameters from experimental data for disruption analysis.
20-
These methods are run across all provided sets of discharges (or shot ids), outputting tabular data in customizable formats.
35+
### Background
36+
37+
A key element to ensure steady state operations in magnetically confined tokamak devices is the prediction and avoidance of disruptions.
38+
These are sudden losses of the thermal and magnetic energy stored within the plasma, which can occur when tokamaks operate near stability boundaries or because of hardware anomalies.
39+
The energy stored in the plasma and released during disruptions over milliseconds can cause severe damage to plasma-facing components, limiting experimental operations and the device's lifespan [[1](https://doi.org/10.1080/15361055.2023.2229675)].
40+
Disruptions still pose a serious challenge to next-generation fusion devices such as ITER or SPARC, which will have to operate near some of the limits of plasma stability to achieve intended performance and will do so at for long and frequent intervals.
41+
Fusion science currently lacks first-principle, theoretical solutions to fully predict and avoid disruptions.
42+
However, previous work [[2](https://doi.org/10.1088/1741-4326/ab28bf), [3](https://doi.org/10.1088/1741-4326/abf74d)] has shown the usefulness of machine-learning (ML) algorithms for disruption prevention for both DIII-D and EAST -- the Experimental Advanced Superconducting Tokamak in China -- operations.
43+
DisruptionPy provides a standardized analysis pipeline across different fusion devices to build ML-ready datasets.
44+
45+
### Workflow
46+
47+
DisruptionPy makes it easy to retrieve experimental data from [MDSplus](https://www.mdsplus.org/) fusion repositories efficiently.
48+
Users can create their own routines and/or use built-in ones that retrieve and derive a variety of important signals from experimental data for disruption analysis.
49+
These routines are then interpolated on a requested timebase across the specified set of plasma discharges (or shots) to assemble a dataset and save it under a variety of available formats.
50+
51+
<img src="docs/workflow.png" alt="Schematic flowchart of a typical DisruptionPy workflow. By Y Wei (2024)" width="400" onerror="this.onerror=null;this.src='workflow.png';" />
52+
53+
_Figure: Schematic flowchart of a typical DisruptionPy workflow. By Y Wei (2024) [6]._
54+
55+
### Acknowledgments
56+
57+
The most recent revamp of DisruptionPy [4, 5, 6] was partially supported by DOE FES under Award DE-SC0024368, "Open and FAIR Fusion for Machine Learning Applications" [7].
58+
59+
### References
60+
61+
1. AD Maris, A Wang, C Rea, RS Granetz, E Marmar (2023), _"The Impact of Disruptions on the Economics of a Tokamak Power Plant"_, **Fusion Science and Technology** 80(5) 636-652, [DOI:10.1080/15361055.2023.2229675](https://doi.org/10.1080/15361055.2023.2229675).
62+
63+
2. C Rea, KJ Montes, KG Erickson, RS Granetz & RA Tinguely (2019), _"A real-time machine learning-based disruption predictor in DIII-D"_, **Nuclear Fusion** 59 096016, [DOI:10.1088/1741-4326/ab28bf](https://doi.org/10.1088/1741-4326/ab28bf).
64+
65+
3. WH Hu, C Rea, et al. (2021), _"Real-time prediction of high-density EAST disruptions using random forest"_, **Nuclear Fusion** 61 066034, [DOI:10.1088/1741-4326/abf74d](https://doi.org/10.1088/1741-4326/abf74d).
66+
67+
4. C Rea, et al. (2024), _"Open and FAIR Fusion for Machine Learning Applications"_, 66th APS Division of Plasma Physics Meeting, [PP12.27](https://meetings.aps.org/Meeting/DPP24/Session/PP12.27).
68+
69+
5. GL Trevisan, et al. (2024), _"Functional Improvements and Technical Developments of a Community-driven and Physics-informed Numerical Library for Disruption Studies"_, 66th APS Division of Plasma Physics Meeting, [PP12.9](https://meetings.aps.org/Meeting/DPP24/Session/PP12.9).
70+
71+
6. Y Wei, et al. (2024), _"Physics validation of parameter methods in DisruptionPy"_, 66th APS Division of Plasma Physics Meeting, [PP12.10](https://meetings.aps.org/Meeting/DPP24/Session/PP12.10).
72+
73+
7. C Rea, et al. (2023), _"Open and FAIR Fusion for Machine Learning Applications"_, [Project website](https://crea-psfc.github.io/open-fair-fusion/).
74+
75+
76+
## Repository layout
77+
78+
Notable branches:
79+
80+
- `main`, the [stable branch](https://github.com/MIT-PSFC/disruption-py/tree/main),
81+
- `dev`, the [development branch](https://github.com/MIT-PSFC/disruption-py/tree/dev),
82+
- `matlab`, the [historical branch](https://github.com/MIT-PSFC/disruption-py/tree/matlab).
83+
2184

2285
## Project layout
2386

24-
```python
25-
disruption_py/ # source code
26-
docs/ # documentation
27-
examples/ # example workflows
28-
scripts/ # miscellaneous scripts
29-
tests/ # automated testing
30-
```
87+
Brief description of the folders in our project:
88+
89+
- `disruption_py/`, package source code,
90+
- `docs/`, documentation sources,
91+
- `drafts/`, experimental scripts,
92+
- `examples/`, example workflows,
93+
- `scripts/`, miscellaneous scripts,
94+
- `tests/`, testing workflows.
3195

32-
The original Matlab scripts are now stored in the `matlab` [protected branch](https://github.com/MIT-PSFC/disruption-py/tree/matlab).
3396

3497
## Installation
3598

3699
DisruptionPy is now open-source and [available at PyPI](https://pypi.org/project/disruption-py/)!
100+
37101
For standard installations, please follow the usual way:
38102

39103
```bash
@@ -46,14 +110,17 @@ pip install disruption-py
46110

47111
For custom installations, please refer to our [Installation guide](docs/INSTALL.md).
48112

113+
49114
## Getting Started
50115

51-
Please see the project [quickstart](https://mit-psfc.github.io/disruption-py/quickstart/usage_quickstart/).
116+
Please see the [project quickstart](https://mit-psfc.github.io/disruption-py/quickstart/usage_quickstart/).
52117

53-
## Issues
54118

55-
If you have an issue please crate an issue on the GitHub repository
119+
## Contributing
56120

57-
## Development
121+
> [!IMPORTANT]
122+
> Make sure you refer to the latest version of our [development branch](https://github.com/MIT-PSFC/disruption-py/tree/dev)!
58123
59-
Please create a pull request if you have something to contribute!
124+
- If you encounter any problems, please [create a new issue](https://github.com/MIT-PSFC/disruption-py/issues/new).
125+
- If you would like to contribute, please [submit a pull request](https://github.com/MIT-PSFC/disruption-py/compare/dev...).
126+
- If you have general questions, please [start a new discussion](https://github.com/MIT-PSFC/disruption-py/discussions/new?category=q-a).

SECURITY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Security Policy
3+
4+
To report a security vulnerability, please [send us an email](mailto:gtrevisan@psfc.mit.edu?subject=disruption-py%20security%20vulnerability).

disruption_py/config.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,20 @@ def config(tokamak: Union[Enum, str] = None):
3333
tokamak = tokamak.value
3434

3535
if tokamak not in configs:
36+
37+
# enforce permissions for user config
38+
user_config = os.path.expanduser("~/.config/disruption-py/user.toml")
39+
if os.path.exists(user_config):
40+
os.chmod(user_config, 0o600)
41+
3642
configs[tokamak] = Dynaconf(
3743
envvar_prefix="DISPY",
3844
root_path=os.path.dirname(__file__),
39-
settings_file="config.toml",
45+
settings_files=[
46+
"config.toml",
47+
f"machine/{tokamak}/config.toml",
48+
user_config,
49+
],
4050
environments=True,
4151
default_env="default",
4252
env=tokamak,

0 commit comments

Comments
 (0)