Skip to content

Commit bb352df

Browse files
authored
Merge pull request #107 from pabloprf/development
MITIM 4.0.0, with big refactoring of PORTALS and simulation modules
2 parents 3c4c6d2 + d602b66 commit bb352df

File tree

157 files changed

+18443
-15836
lines changed

Some content is hidden

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

157 files changed

+18443
-15836
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/scratch/*
55
*.DS_Store*
66
config_user.json
7-
.DS_Store
87
*.egg-info/
98
docs/build/
109
*.bat

docs/capabilities/misc_capabilities.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Miscellaneous
1010
Interpret Tokamak equilibrium
1111
-----------------------------
1212

13-
MITIM has a quick g-eqdsk file reader and visualizer that is based on the ``omfit-classes`` package.
13+
MITIM has a quick g-eqdsk file reader and visualizer that is based on the ``megpy`` package.
1414

1515
To open and plot a g-eqdsk file:
1616

@@ -47,7 +47,7 @@ To open and plot an ``input.gacode`` file:
4747
.. code-block:: python
4848
4949
from mitim_tools.gacode_tools import PROFILEStools
50-
p = PROFILEStools.PROFILES_GACODE(file)
50+
p = PROFILEStools.gacode_state(file)
5151
p.plot()
5252
5353
It will plot results in a notebook-like plot with different tabs:

docs/capabilities/optimization.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Select the location of the MITIM namelist (see :ref:`Understanding the MITIM nam
4444
.. code-block:: python
4545
4646
folder = Path('MITIM-fusion/tests/scratch/mitim_tut')
47-
namelist = Path('MITIM-fusion/templates/main.namelist.json')
47+
namelist = Path('MITIM-fusion/templates/namelist.optimization.yaml')
4848
4949
Then create your custom optimization object as a child of the parent ``STRATEGYtools.opt_evaluator`` class.
5050
You only need to modify what operations need to occur inside the ``run()`` (where operations/simulations happen) and ``scalarized_objective()`` (to define what is the target to maximize) methods.
@@ -105,7 +105,7 @@ Now we can create and launch the MITIM optimization process from the beginning (
105105

106106
.. code-block:: python
107107
108-
MITIM_BO = STRATEGYtools.MITIM_BO( opt_fun1D, cold_startYN = True )
108+
MITIM_BO = STRATEGYtools.MITIM_BO( opt_fun1D, cold_start = True )
109109
MITIM_BO.run()
110110
111111
Once finished, we can plot the results easily with:
@@ -118,7 +118,7 @@ Once finished, we can plot the results easily with:
118118
Understanding the MITIM namelist
119119
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120120

121-
Checkout file ``MITIM-fusion/templates/main.namelist.json``, which has comprehensive comments.
121+
Checkout file ``MITIM-fusion/templates/namelist.optimization.yaml``, which has comprehensive comments.
122122

123123
*Under development*
124124

docs/capabilities/tglf_capabilities.rst

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,31 @@ To generate the input files (input.tglf) to TGLF at each radial location, MITIM
6868

6969
.. code-block:: python
7070
71-
cdf = tglf.prep(folder,inputgacode=inputgacode_file,cold_start=False )
71+
_ = tglf.prep(inputgacode_file,folder,cold_start=False)
7272
73-
.. tip::
7473
75-
The ``.prep()`` method, when applied to a case that starts with an input.gacode file, launches a `TGYRO` run for a "zero" iteration to generate *input.tglf* at specific ``rho`` locations from the *input.gacode*. This method to generate input files is inspired by how the `OMFIT framework <https://omfit.io/index.html>`_ works.
74+
Now, we are ready to run TGLF. Once the ``prep()`` command has finished, one can run TGLF with different settings and assumptions.
75+
That is why, at this point, a sub-folder name for this specific run can be provided. Similarly to the ``prep()`` command, a ``cold_start`` flag can be provided.
76+
77+
The set of control inputs to TGLF (saturation rule, electromagnetic effects, basis functions, etc.) are provided following the following sequential logic:
78+
79+
1. Each code has a set of default settings, which for TGLF are specified in ``templates/input.tglf.controls``. This is the base namelist of settings that will be used if no other specification is provided.
80+
2. Then, a ``code_settings`` argument can be provided to the ``run()`` command. This argument refers to a specific set of settings that are specified in ``templates/input.tglf.models.yaml``, and that will overwrite the default settings in ``input.tglf.controls``.
81+
3. Finally, an ``extraOptions`` argument can be provided to the ``run()`` command, which is a dictionary of specific settings to change from the previous two steps.
7682

77-
Now, we are ready to run TGLF. Once the ``prep()`` command has finished, one can run TGLF with different settings and assumptions. That is why, at this point, a sub-folder name for this specific run can be provided. Similarly to the ``prep()`` command, a ``cold_start`` flag can be provided.
78-
The set of control inputs to TGLF (like saturation rule, electromagnetic effects, etc.) are provided in two ways.
79-
First, the argument ``TGLFsettings`` indicates the base case to start with.
80-
The user is referred to ``templates/input.tglf.models.json`` to understand the meaning of each setting, and ``templates/input.tglf.controls`` for the default setup.
81-
Second, the argument ``extraOptions`` can be passed as a dictionary of variables to change.
8283
For example, the following two commands will run TGLF with saturation rule number 2 with and without electromagnetic effets. After each ``run()`` command, a ``read()`` is needed, to populate the *tglf.results* dictionary with the TGLF outputs (``label`` refers to the dictionary key for each run):
8384

8485
.. code-block:: python
8586
86-
tglf.run( subFolderTGLF = 'yes_em_folder',
87-
TGLFsettings = 5,
88-
extraOptions = {},
87+
tglf.run( subfolder = 'yes_em_folder',
88+
code_settings = 'SAT2',
89+
extraOptions = {'USE_BPER':True},
8990
cold_start = False )
9091
9192
tglf.read( label = 'yes_em' )
9293
93-
tglf.run( subFolderTGLF = 'no_em_folder',
94-
TGLFsettings = 5,
94+
tglf.run( subfolder = 'no_em_folder',
95+
code_settings = 'SAT2',
9596
extraOptions = {'USE_BPER':False},
9697
cold_start = False )
9798
@@ -139,7 +140,7 @@ Similarly as in the previous section, you need to run the ``prep()`` command, bu
139140

140141
.. code-block:: python
141142
142-
cdf = tglf.prep(folder,cold_start=False)
143+
cdf = tglf.prep_using_tgyro(folder,cold_start=False)
143144
144145
.. note::
145146

@@ -168,7 +169,7 @@ If you have a input.tglf file already, you can still use this script to run it.
168169
inputtglf_file = Path('MITIM-fusion/tests/data/input.tglf')
169170
170171
tglf = TGLFtools.TGLF()
171-
tglf.prep_from_tglf( folder, inputtglf_file, input_gacode = inputgacode_file )
172+
tglf.prep_from_file( folder, inputtglf_file, input_gacode = inputgacode_file )
172173
173174
The rest of the workflow is identical, including ``.run()``, ``.read()`` and ``.plot()``.
174175

@@ -190,7 +191,7 @@ The rest of the workflow is identical, including ``.run()``, ``.read()`` and ``.
190191
inputtglf_file = Path('MITIM-fusion/tests/data/input.tglf')
191192
192193
tglf = TGLFtools.TGLF()
193-
tglf.prep_from_tglf( folder, inputtglf_file )
194+
tglf.prep_from_file( folder, inputtglf_file )
194195
tglf.read (folder = f'{folder}/', label = 'yes_em' )
195196
tglf.plot( labels = ['yes_em'] )
196197
@@ -215,26 +216,4 @@ Run 1D scans of TGLF input parameter
215216
TGLF aliases
216217
------------
217218

218-
MITIM provides a few useful aliases, including for the TGLF tools:
219-
220-
- To plot results that exist in a folder ``run1/``, with or without a suffix and with or without an input.gacode file (for normalizations):
221-
222-
.. code-block:: bash
223-
224-
mitim_plot_tglf run1/
225-
mitim_plot_tglf run1/ --suffix _0.55 --gacode input.gacode
226-
227-
228-
- To run TGLF in a folder ``run1/`` using input file ``input.tglf``, with or without an input.gacode file (for normalizations):
229-
230-
.. code-block:: bash
231-
232-
mitim_run_tglf --folder run1/ --tglf input.tglf
233-
mitim_run_tglf --folder run1/ --tglf input.tglf --gacode input.gacode
234-
235-
- To run a parameter scan in a folder ``scan1/`` using input file ``input.tglf``, with or without an input.gacode file (for normalizations):
236-
237-
.. code-block:: bash
238-
239-
mitim_run_tglf --folder scan1/ --tglf input.tglf --gacode input.gacode --scan RLTS_2
240-
219+
MITIM provides a few useful aliases, including for the TGLF tools: :ref:`Shell Scripts`

docs/capabilities/tgyro_capabilities.rst

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Create a PROFILES class from the input.gacode file:
3535

3636
.. code-block:: python
3737
38-
profiles = PROFILEStools.PROFILES_GACODE(gacode_file)
38+
profiles = PROFILEStools.gacode_state(gacode_file)
3939
4040
.. tip::
4141

@@ -83,7 +83,7 @@ Now TGYRO can be run:
8383
PredictionSet = PredictionSet,
8484
TGLFsettings = TGLFsettings,
8585
TGYRO_solver_options = solver,
86-
Physics_options = physics_options)
86+
TGYRO_physics_options = physics_options)
8787
8888
Read:
8989

@@ -120,7 +120,7 @@ Create a profiles class with the `input.gacode` file that TGYRO used to run and
120120
gacode_file = Path('MITIM-fusion/tests/data/input.gacode')
121121
folder = Path('MITIM-fusion/tests/scratch/tgyro_tut/run1')
122122
123-
profiles = PROFILEStools.PROFILES_GACODE(gacode_file)
123+
profiles = PROFILEStools.gacode_state(gacode_file)
124124
tgyro_out = TGYROtools.TGYROoutput(folder,profiles=profiles)
125125
126126
Plot results:
@@ -133,11 +133,5 @@ Plot results:
133133
TGYRO aliases
134134
-------------
135135

136-
MITIM provides a few useful aliases, including for the TGYRO tools:
137-
138-
- To plot results that exist in a folder ``run1/``:
139-
140-
.. code-block:: bash
141-
142-
mitim_plot_tgyro run1/
136+
MITIM provides a few useful aliases, including for the TGYRO tools: :ref:`Shell Scripts`
143137

docs/capabilities/transp_capabilities.rst

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,5 @@ If TRANSP has already been run and the .CDF results file already exists (``cdf_f
123123
TRANSP aliases
124124
--------------
125125

126-
MITIM provides a few useful aliases, including for the TRANSP tools:
127-
128-
- To read TRANSP results in CDF files (which stores the results in the ``cdfs`` list. First run can be plotted with ``cdfs[0].plot``):
129-
130-
.. code-block:: bash
131-
132-
mitim_read_transp 12345A01.CDF 12345A02.CDF
133-
134-
- To interact with the TRANSP globus grid:
135-
136-
.. code-block:: bash
137-
138-
# To check status of runs under username pablorf
139-
mitim_trcheck pablorf
140-
141-
# To remove from the grid CMOD run numbers 88664P01, 88664P03 from user pablorf
142-
mitim_trclean 88664P CMOD --numbers 1,3
143-
144-
# To get results file (intermediate or final) from CMOD run 152895P01 from user pablorf
145-
mitim_trlook 152895P01 CMOD
126+
MITIM provides a few useful aliases, including for the TRANSP tools: :ref:`Shell Scripts`
146127

docs/capabilities/vitals_capabilities.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ As a starting point of VITALS, you need to prepare and run TGLF for the base cas
3838
rho = 0.5
3939
4040
tglf = TGLFtools.TGLF( rhos = [ rho ] )
41-
cdf = tglf.prep( folder, inputgacode = inputgacode_file)
42-
tglf.run( subFolderTGLF = 'run_base', TGLFsettings = 5)
41+
cdf = tglf.prep( inputgacode_file, folder )
42+
tglf.run( subfolder = 'run_base', code_settings = 'SAT3')
4343
tglf.read( label = 'run_base' )
4444
4545
@@ -120,7 +120,7 @@ Once the VITALS object has been created, parameters such as the TGLF control inp
120120

121121
.. code-block:: python
122122
123-
vitals_fun.TGLFparameters['TGLFsettings'] = 5
123+
vitals_fun.TGLFparameters['code_settings'] = 'SAT3'
124124
vitals_fun.TGLFparameters['extraOptions'] = {}
125125
126126
.. note::

docs/faq.rst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Issues during MITIM installation
3030

3131
.. code-block:: console
3232
33-
pip3 install -e MITIM-fusion\[pyqt\] --no-cache
33+
pip3 install -e MITIM-fusion\[pyqt\] --no-cache-dir
3434
3535
Issues during MITIM tests
3636
-------------------------
@@ -61,9 +61,3 @@ Issues during MITIM tests
6161

6262
Make sure you that, if you have keys, you have added them to authorized_keys in both server and tunnel machines.
6363

64-
65-
66-
Issues during PORTALS simulations
67-
---------------------------------
68-
69-
Nothing here yet.

docs/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
MITIM: a toolbox for modeling tasks in plasma physics and fusion energy
22
=======================================================================
33

4-
The **MITIM** (MIT Integrated Modeling) is a versatile and user-friendly Python library designed for *plasma physics* and *fusion energy* researchers, distributed as the `MITIM-fusion <https://github.com/pabloprf/MITIM-fusion>`_ GitHub repository.
5-
Developed in 2018 by `Pablo Rodriguez-Fernandez <https://www.pablorf.com/>`_ at the MIT Plasma Science and Fusion Center, this light-weight, command-line,
4+
The **MITIM** (MIT Integrated Modeling) is a versatile and user-friendly Python library designed for plasma physics and fusion energy researchers, distributed as the `MITIM-fusion <https://github.com/pabloprf/MITIM-fusion>`_ GitHub repository.
5+
Spearheaded by `Pablo Rodriguez-Fernandez <https://www.pablorf.com/>`_ at the MIT Plasma Science and Fusion Center, this light-weight, command-line,
66
object-oriented toolbox streamlines the execution and interpretation of physics models and simplifies complex optimization tasks.
77

88
MITIM stands out for its modular nature, making it particularly useful for integrating models with optimization workflows.
@@ -28,7 +28,7 @@ Overview
2828
--------
2929

3030
Developed at the MIT Plasma Science and Fusion Center, MITIM emerged in 2023 as a progression from the PORTALS project (*Performance Optimization of Reactors via Training of Active Learning Surrogates*).
31-
This evolution marks a significant enhancement in our approach to transport and optimization in plasma physics research.
31+
This evolution marked a significant enhancement in our approach to transport and optimization in plasma physics research.
3232

3333
MITIM's core functionality revolves around the standalone execution of codes and the nuanced interpretation of results through object-oriented Python scripts.
3434
This enables researchers to seamlessly integrate these scripts into custom surrogate-based optimization frameworks,

docs/installation.rst

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ Use ``pip`` to install all the required MITIM requirements:
3636
The optional argument ``[pyqt]`` added in the intallation command above must only be used if the machine allows for graphic interfaces.
3737
If running in a computing cluster, remove that flag.
3838
The ``pyqt`` package is used to create condensed figures into a single notebook when interpreting and plotting simulation results.
39-
40-
If you wish to install all capabilities (including compatibility with `OMFIT <https://omfit.io/>`_), it is recommended that ``pip`` is run as follows:
41-
42-
.. code-block:: console
43-
44-
pip3 install -e MITIM-fusion[pyqt,omfit]
45-
4639

4740
If you were unsuccessful in the installation, check out our :ref:`Frequently Asked Questions` section.
4841

@@ -53,11 +46,11 @@ User configuration
5346
In ``MITIM-fusion/templates/``, there is a ``config_user_example.json`` with specifications of where to run certain codes and what the login requirements are.
5447
There are also options to specify the default verbose level and the default DPI for the figures in notebooks.
5548
Users need to specify their own configurations in a file that follows the same structure.
56-
There are different options to handle this config file.
49+
There are different options to handle this config file:
5750

5851
1. Create a new file named ``config_user.json`` **in the same folder** ``MITIM-fusion/templates/``. MITIM will automatically look for this file when running the code.
5952
2. Create a new file anywhere in your machine. Then, **set the environment variable** ``MITIM_CONFIG`` to the path of this file. MITIM will automatically look for this file when running the code.
60-
3. Create a new file anywhere in your machine. **Do this at the beginning of your script**:
53+
3. Create a new file anywhere in your machine. Then, **add these lines at the beginning of your script**:
6154

6255
.. code-block:: python
6356
@@ -87,29 +80,46 @@ In this example, the ``identity`` option is only required if you are running in
8780
{
8881
"preferences": {
8982
"tglf": "engaging",
83+
"neo": "local",
9084
"tgyro": "perlmutter",
9185
"verbose_level": "5",
9286
"dpi_notebook": "80"
9387
},
88+
"local": {
89+
"machine": "local",
90+
"username": "YOUR_USERNAME",
91+
"scratch": "/Users/YOUR_USERNAME/scratch/",
92+
"modules": "",
93+
"cores_per_node": 8,
94+
"gpus_per_node": 0
95+
},
9496
"engaging": {
9597
"machine": "eofe7.mit.edu",
9698
"username": "YOUR_USERNAME",
9799
"scratch": "/pool001/YOUR_USERNAME/scratch/",
100+
"modules": "",
101+
"cores_per_node": 64,
102+
"gpus_per_node": 0,
98103
"slurm": {
99104
"partition": "sched_mit_psfc",
105+
"exclusive": false,
100106
"exclude": "node584"
101107
}
102108
},
103109
"perlmutter": {
104110
"machine": "perlmutter.nersc.gov",
105111
"username": "YOUR_USERNAME",
106112
"scratch": "/pscratch/sd/p/YOUR_USERNAME/scratch/",
113+
"modules": "",
107114
"identity": "/Users/YOUR_USERNAME/.ssh/id_rsa_nersc",
115+
"cores_per_node": 32,
116+
"gpus_per_node": 4,
108117
"slurm": {
109118
"account": "YOUR_ACCOUNT",
110119
"partition": "YOUR_PARTITION",
111120
"constraint": "gpu",
112-
"mem": "4GB"
121+
"mem": "4GB",
122+
"email": "optional@email"
113123
}
114124
}
115125
}
@@ -119,20 +129,15 @@ MITIM will attempt to create SSH and SFTP connections to that machine, and will
119129

120130
.. attention::
121131

122-
Note that MITIM does not maintain or develop the simulation codes that are used within it, such as those from `GACODE <http://gafusion.github.io/doc/index.html>`_ or `TRANSP <hhttps://transp.pppl.gov/index.html>`_. It assumes that proper permissions have been obtained and that working versions of those codes exist in the machine configured to run them.
132+
Note that MITIM does not maintain or develop the simulation codes that are used within it, such as those from `GACODE <https://gacode.io/>`_ or `TRANSP <https://transp.pppl.gov/index.html>`_. It assumes that proper permissions have been obtained and that working versions of those codes exist in the machine configured to run them.
123133

124134
Please note that MITIM will try to run the codes with standard commands that the shell must understand.
125135
For example, to run the TGLF code, MITIM will want to execute the command ``tglf`` in the *eofe7.mit.edu* machine as specified in the example above.
126136
There are several ways to make sure that the shell understands the command:
127137

128-
.. dropdown:: 1. Source at shell initialization (recommended)
138+
.. dropdown:: 1. Send specific commands per code (recommended)
129139

130-
Is the commands are available upon login in that machine (e.g. in your personal ``.bashrc`` file), MITIM will be able to run them.
131-
Please note that aliases are usually not available in non-interactive shells, and it is recommended to use full paths and to avoid print (echo) statements.
132-
133-
.. dropdown:: 2. Send specific commands per code
134-
135-
Finally, you can populate the ``modules`` option per machine in your ``config_user.json`` file. For example:
140+
You can populate the ``modules`` option per machine in your ``config_user.json`` file. For example:
136141

137142
.. code-block:: console
138143
@@ -142,10 +147,13 @@ There are several ways to make sure that the shell understands the command:
142147
...
143148
}
144149
145-
146150
Note that you can the same machine listed several times in your ``config_user.json`` file, with different ``modules`` options per code.
147151
You just need to give it a different name per code.
148152

153+
.. dropdown:: 2. Source at shell initialization
154+
155+
If the commands are available upon login in that machine (e.g. in your personal ``.bashrc`` file), MITIM will be able to run them.
156+
Please note that aliases are usually not available in non-interactive shells, and it is recommended to use full paths and to avoid print (echo) statements.
149157

150158

151159
License and contributions

0 commit comments

Comments
 (0)