Skip to content

Commit 4c776cc

Browse files
authored
Merge pull request #63 from pabloprf/development
Release of working version of MITIM 3.0.0
2 parents f1ba2c1 + b19ecec commit 4c776cc

File tree

166 files changed

+10455
-8179
lines changed

Some content is hidden

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

166 files changed

+10455
-8179
lines changed

docs/capabilities/optimization.rst

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ For this tutorial we will need the following modules:
3636
3737
import torch
3838
import numpy as np
39+
from pathlib import Path
3940
from mitim_tools.opt_tools import STRATEGYtools
4041
4142
Select the location of the MITIM namelist (see :ref:`Understanding the MITIM namelist` to understand how to construct the namelist file) and the folder to work on:
4243

4344
.. code-block:: python
4445
45-
folder = 'MITIM-fusion/tests/scratch/mitim_tut/'
46-
namelist = 'MITIM-fusion/templates/main.namelist.json'
46+
folder = Path('MITIM-fusion/tests/scratch/mitim_tut')
47+
namelist = Path('MITIM-fusion/templates/main.namelist.json')
4748
4849
Then create your custom optimization object as a child of the parent ``STRATEGYtools.opt_evaluator`` class.
4950
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.
@@ -58,11 +59,11 @@ In this example, we are using ``x**2`` as our function with a 2% evaluation erro
5859
# ----------------------------------------
5960
6061
# Problem description (rest of problem parameters are taken from namelist)
61-
self.optimization_options["dvs"] = ["x"]
62-
self.optimization_options["dvs_min"] = [0.0]
63-
self.optimization_options["dvs_max"] = [20.0]
62+
self.optimization_options["problem_options"]["dvs"] = ["x"]
63+
self.optimization_options["problem_options"]["dvs_min"] = [0.0]
64+
self.optimization_options["problem_options"]["dvs_max"] = [20.0]
6465
65-
self.optimization_options["ofs"] = ["z", "zval"]
66+
self.optimization_options["problem_options"]["ofs"] = ["z", "zval"]
6667
self.name_objectives = ["zval_match"]
6768
6869
def run(self, paramsfile, resultsfile):
@@ -80,7 +81,7 @@ In this example, we are using ``x**2`` as our function with a 2% evaluation erro
8081
self.write(dictOFs, resultsfile)
8182
8283
def scalarized_objective(self, Y):
83-
ofs_ordered_names = np.array(self.optimization_options["ofs"])
84+
ofs_ordered_names = np.array(self.optimization_options["problem_options"]["ofs"])
8485
8586
of = Y[..., ofs_ordered_names == "z"]
8687
cal = Y[..., ofs_ordered_names == "zval"]
@@ -100,12 +101,12 @@ Then, create an object from the previously defined class:
100101

101102
Note that at this point, you can pass any parameter that you want, just changing the ``__init__()`` method as appropriate.
102103

103-
Now we can create and launch the MITIM optimization process from the beginning (i.e. ``restart = True``):
104+
Now we can create and launch the MITIM optimization process from the beginning (i.e. ``cold_start = True``):
104105

105106
.. code-block:: python
106107
107-
PRF_BO = STRATEGYtools.PRF_BO( opt_fun1D, restartYN = True )
108-
PRF_BO.run()
108+
MITIM_BO = STRATEGYtools.MITIM_BO( opt_fun1D, cold_startYN = True )
109+
MITIM_BO.run()
109110
110111
Once finished, we can plot the results easily with:
111112

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Shell Scripts
2+
====
3+
To run available shell scripts, go to your temineral, type the name of the script, and any required arguments. For the plotting scripts, usually the
4+
path to the folder in which the run was done is required. To see more information about the script including required arguments:
5+
6+
.. code-block:: bash
7+
8+
script_name --help
9+
10+
The following shell scripts are available in the MITIM-fusion repository:
11+
12+
**Plotting tools**
13+
14+
- mitim_plot_gacode
15+
- mitim_plot_tgyro
16+
- mitim_plot_tglf
17+
- mitim_plot_cgyro
18+
- mitim_plot_eq
19+
- mitim_plot_transp
20+
- mitim_plot_opt
21+
- mitim_plot_portals
22+
- mitim_plot_maestro
23+
24+
**TRANSP**
25+
26+
- mitim_trcheck
27+
- mitim_trcheck_p
28+
- mitim_trclean
29+
- mitim_trlook
30+
- mitim_run_transp
31+
32+
**Miscellaneous**
33+
34+
- mitim_run_tglf
35+
- mitim_slurm
36+
- mitim_compare_nml
37+
- mitim_scp

docs/capabilities/standalone.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ Standalone Capabilities
77
tglf_capabilities
88
tgyro_capabilities
99
transp_capabilities
10-
misc_capabilities
10+
misc_capabilities
11+
shell_scripts

docs/capabilities/tglf_capabilities.rst

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,33 @@ For this tutorial we will need the following modules:
4848

4949
.. code-block:: python
5050
51+
from pathlib import Path
5152
from mitim_tools.gacode_tools import TGLFtools
5253
5354
Select the location of the input.gacode file to start the simulation from. You should also select the folder where the simulation will be run:
5455

5556
.. code-block:: python
5657
57-
inputgacode_file = 'MITIM-fusion/tests/data/input.gacode'
58-
folder = 'MITIM-fusion/tests/scratch/tglf_tut/'
58+
inputgacode_file = Path('MITIM-fusion/tests/data/input.gacode')
59+
folder = Path('MITIM-fusion/tests/scratch/tglf_tut')
5960
6061
The TGLF class can be initialized by providing the radial location (in square root of normalized toroidal flux, ``rho``) to run. Note that the values are given as a list, and several radial locations can be run at once:
6162

6263
.. code-block:: python
6364
6465
tglf = TGLFtools.TGLF(rhos=[0.5, 0.7])
6566
66-
To generate the input files (input.tglf) to TGLF at each radial location, MITIM needs to run a few commands to correctly map the quantities in the input.gacode file to the ones required by TGLF. This is done automatically with the ``prep()`` command. Note that MITIM has a *only-run-if-needed* philosophy and if it finds that the input files to TGLF already exist in the working folder, the preparation method will not run any command, unless a ``restart = True`` argument is provided.
67+
To generate the input files (input.tglf) to TGLF at each radial location, MITIM needs to run a few commands to correctly map the quantities in the input.gacode file to the ones required by TGLF. This is done automatically with the ``prep()`` command. Note that MITIM has a *only-run-if-needed* philosophy and if it finds that the input files to TGLF already exist in the working folder, the preparation method will not run any command, unless a ``cold_start = True`` argument is provided.
6768

6869
.. code-block:: python
6970
70-
cdf = tglf.prep(folder,inputgacode=inputgacode_file,restart=False )
71+
cdf = tglf.prep(folder,inputgacode=inputgacode_file,cold_start=False )
7172
7273
.. tip::
7374

7475
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.
7576

76-
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 ``restart`` flag can be provided.
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.
7778
The set of control inputs to TGLF (like saturation rule, electromagnetic effects, etc.) are provided in two ways.
7879
First, the argument ``TGLFsettings`` indicates the base case to start with.
7980
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.
@@ -82,17 +83,17 @@ For example, the following two commands will run TGLF with saturation rule numbe
8283

8384
.. code-block:: python
8485
85-
tglf.run( subFolderTGLF = 'yes_em_folder/',
86+
tglf.run( subFolderTGLF = 'yes_em_folder',
8687
TGLFsettings = 5,
8788
extraOptions = {},
88-
restart = False )
89+
cold_start = False )
8990
9091
tglf.read( label = 'yes_em' )
9192
92-
tglf.run( subFolderTGLF = 'no_em_folder/',
93+
tglf.run( subFolderTGLF = 'no_em_folder',
9394
TGLFsettings = 5,
9495
extraOptions = {'USE_BPER':False},
95-
restart = False )
96+
cold_start = False )
9697
9798
tglf.read( label = 'no_em' )
9899
@@ -123,10 +124,11 @@ If instead of an input.gacode, you have a TRANSP .CDF file (``cdf_file``) and wa
123124

124125
.. code-block:: python
125126
127+
from pathlib import Path
126128
from mitim_tools.gacode_tools import TGLFtools
127129
128-
cdf_file = 'MITIM-fusion/tests/data/12345.CDF'
129-
folder = 'MITIM-fusion/tests/scratch/tglf_tut/'
130+
cdf_file = Path('MITIM-fusion/tests/data/12345.CDF')
131+
folder = Path('MITIM-fusion/tests/scratch/tglf_tut')
130132
131133
tglf = TGLFtools.TGLF( cdf = cdf_file,
132134
rhos = [0.5,0.7],
@@ -137,7 +139,7 @@ Similarly as in the previous section, you need to run the ``prep()`` command, bu
137139

138140
.. code-block:: python
139141
140-
cdf = tglf.prep(folder,restart=False)
142+
cdf = tglf.prep(folder,cold_start=False)
141143
142144
.. note::
143145

@@ -158,11 +160,12 @@ If you have a input.tglf file already, you can still use this script to run it.
158160

159161
.. code-block:: python
160162
163+
from pathlib import Path
161164
from mitim_tools.gacode_tools import TGLFtools
162165
163-
inputgacode_file = 'MITIM-fusion/tests/data/input.gacode'
164-
folder = 'MITIM-fusion/tests/scratch/tglf_tut/'
165-
inputtglf_file = 'MITIM-fusion/tests/data/input.tglf'
166+
inputgacode_file = Path('MITIM-fusion/tests/data/input.gacode')
167+
folder = Path('MITIM-fusion/tests/scratch/tglf_tut')
168+
inputtglf_file = Path('MITIM-fusion/tests/data/input.tglf')
166169
167170
tglf = TGLFtools.TGLF()
168171
tglf.prep_from_tglf( folder, inputtglf_file, input_gacode = inputgacode_file )
@@ -180,10 +183,11 @@ The rest of the workflow is identical, including ``.run()``, ``.read()`` and ``.
180183

181184
.. code-block:: python
182185
186+
from pathlib import Path
183187
from mitim_tools.gacode_tools import TGLFtools
184188
185-
folder = 'MITIM-fusion/tests/scratch/tglf_tut/yes_em_folder/'
186-
inputtglf_file = 'MITIM-fusion/tests/data/input.tglf'
189+
folder = Path('MITIM-fusion/tests/scratch/tglf_tut/yes_em_folder')
190+
inputtglf_file = Path('MITIM-fusion/tests/data/input.tglf')
187191
188192
tglf = TGLFtools.TGLF()
189193
tglf.prep_from_tglf( folder, inputtglf_file )

docs/capabilities/tgyro_capabilities.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ For this tutorial we will need the following modules:
2121

2222
.. code-block:: python
2323
24+
from pathlib import Path
2425
from mitim_tools.gacode_tools import TGYROtools,PROFILEStools
2526
2627
Select the location of the input.gacode file to start the simulation from. You should also select the folder where the simulation will be run:
2728

2829
.. code-block:: python
2930
30-
gacode_file = 'MITIM-fusion/tests/data/input.gacode'
31-
folder = 'MITIM-fusion/tests/scratch/tgyro_tut/'
31+
gacode_file = Path('MITIM-fusion/tests/data/input.gacode')
32+
folder = Path('MITIM-fusion/tests/scratch/tgyro_tut')
3233
3334
Create a PROFILES class from the input.gacode file:
3435

@@ -76,7 +77,7 @@ Now TGYRO can be run:
7677

7778
.. code-block:: python
7879
79-
tgyro.run( subFolderTGYRO = 'run1/',
80+
tgyro.run( subFolderTGYRO = 'run1',
8081
iterations = iterations,
8182
special_radii = rhos,
8283
PredictionSet = PredictionSet,
@@ -113,10 +114,11 @@ Create a profiles class with the `input.gacode` file that TGYRO used to run and
113114

114115
.. code-block:: python
115116
117+
from pathlib import Path
116118
from mitim_tools.gacode_tools import TGYROtools,PROFILEStools
117119
118-
gacode_file = 'MITIM-fusion/tests/data/input.gacode'
119-
folder = 'MITIM-fusion/tests/scratch/tgyro_tut/run1/'
120+
gacode_file = Path('MITIM-fusion/tests/data/input.gacode')
121+
folder = Path('MITIM-fusion/tests/scratch/tgyro_tut/run1')
120122
121123
profiles = PROFILEStools.PROFILES_GACODE(gacode_file)
122124
tgyro_out = TGYROtools.TGYROoutput(folder,profiles=profiles)

docs/capabilities/transp_capabilities.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,33 @@ For this tutorial we will need the following modules:
2222
.. code-block:: python
2323
2424
import os
25+
from pathlib import Path
2526
from mitim_tools.transp_tools import TRANSPtools
2627
2728
TRANSP runs are very personal and specific to each tokamak and plasma, as diagnostic availability strongly varies and namelist settings are not standarized.
2829
For this reason, this workflow assumes that a folder exists with all the plasma information (UFILES) and namelist required to run TRANSP:
2930

3031
.. code-block:: python
3132
32-
folder_original = 'MITIM-fusion/tests/data/FolderTRANSP/'
33-
folder = "MITIM-fusion/tests/scratch/transp_tut/"
34-
os.system(f'rm -r {folder}')
35-
os.system(f'cp -r {folder_original} {folder}')
33+
folder_original = Path("MITIM-fusion/tests/data/FolderTRANSP/")
34+
folder = Path("MITIM-fusion/tests/scratch/transp_tut/")
35+
os.system(f"rm -r {folder}")
36+
os.system(f"cp -r {folder_original} {folder}")
3637
3738
First, one would initialize the TRANSP class with the given folder and the tokamak name:
3839

3940
.. code-block:: python
4041
41-
tokamak = 'CMOD'
42+
tokamak = "CMOD"
4243
transp = TRANSPtools.TRANSP( folder, tokamak )
4344
4445
Then, select a shotnumber and run name, such that the TRANSP simulation will have the complete name `shotnumber+runname`, and the MPI settings for the TRANSP run:
4546

4647
.. code-block:: python
4748
48-
shotnumber = '12345'
49-
runname = 'X01'
50-
mpisettings = { 'trmpi': 1, 'toricmpi': 64, 'ptrmpi': 1 }
49+
shotnumber = "12345"
50+
runname = "X01"
51+
mpisettings = { "trmpi": 1, "toricmpi": 64, "ptrmpi": 1 }
5152
5253
transp.defineRunParameters( shotnumber+runname, shotnumber, mpisettings = mpisettings )
5354

docs/capabilities/vitals_capabilities.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ For this tutorial we will need the following modules and the folder to run VITAL
2323
.. code-block:: python
2424
2525
import numpy as np
26-
26+
from pathlib import Path
2727
from mitim_tools.gacode_tools import TGLFtools
2828
from mitim_modules.vitals import VITALSmain
2929
from mitim_tools.opt_tools import STRATEGYtools
3030
31-
folder = 'MITIM-fusion/tests/scratch/vitals_tut/'
31+
folder = Path('MITIM-fusion/tests/scratch/vitals_tut')
3232
3333
As a starting point of VITALS, you need to prepare and run TGLF for the base case (please follow the :ref:`TGLF` tutorial for more details):
3434

3535
.. code-block:: python
3636
37-
inputgacode_file = 'MITIM-fusion/tests/data/input.gacode'
37+
inputgacode_file = Path('MITIM-fusion/tests/data/input.gacode')
3838
rho = 0.5
3939
4040
tglf = TGLFtools.TGLF( rhos = [ rho ] )
4141
cdf = tglf.prep( folder, inputgacode = inputgacode_file)
42-
tglf.run( subFolderTGLF = 'run_base/', TGLFsettings = 5)
42+
tglf.run( subFolderTGLF = 'run_base', TGLFsettings = 5)
4343
tglf.read( label = 'run_base' )
4444
4545
@@ -84,7 +84,7 @@ At this point, the TGLF class is ready to go into VITALS. One can give the ``tgl
8484

8585
.. code-block:: python
8686
87-
tglf_file = folder + 'tglf_base.pkl'
87+
tglf_file = folder / 'tglf_base.pkl'
8888
tglf.save_pkl(tglf_file)
8989
9090
@@ -114,7 +114,7 @@ Then, as it the case for all optimization problems in MITIM, you must create a f
114114
115115
# Option 2: Use a curated VITALS namelist and only modify some requested values
116116
vitals_fun = VITALSmain.vitals( folder )
117-
vitals_fun.optimization_options['BO_iterations'] = 5
117+
vitals_fun.optimization_options['convergence_options']['maximum_iterations'] = 5
118118
119119
Once the VITALS object has been created, parameters such as the TGLF control inputs can be chosen:
120120

@@ -137,16 +137,16 @@ We are now ready to prepare the VITALS class. Here we have two options:
137137
# Option 2. Pass the tglf pickled file
138138
vitals_fun.prep( tglf_file, rho, ofs, dvs, dvs_min, dvs_max, classLoaded = False )
139139
140-
Now we can create and launch the MITIM optimization process from the beginning (i.e. ``restart = True``):
140+
Now we can create and launch the MITIM optimization process from the beginning (i.e. ``cold_start = True``):
141141

142142
.. code-block:: python
143143
144-
mitim_bo = STRATEGYtools.PRF_BO(vitals_fun, restartYN = True )
144+
mitim_bo = STRATEGYtools.MITIM_BO(vitals_fun, cold_start = True )
145145
mitim_bo.run()
146146
147147
.. note::
148148

149-
If the user wants to run VITALS as a slurm job in a cluster, it is recommended that the keyword argument ``askQuestions = False`` is passed to ``PRF_BO()``.
149+
If the user wants to run VITALS as a slurm job in a cluster, it is recommended that the keyword argument ``askQuestions = False`` is passed to ``MITIM_BO()``.
150150

151151
3. VITALS Interpretation
152152
------------------------

docs/installation.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,18 @@ There are different options to handle this config file.
6868
from mitim_tools import config_manager
6969
config_manager.set(file_location)
7070
71-
Apart from machine configurations, ``preferences`` in ``config_user.json`` also includes a ``verbose_level`` flag, which indicates the amount of messages that are printed to the terminal when running MITIM.
72-
For debugging purposes, it is recommended a maximum verbose level of ``5``.
73-
For production runs, a minimum verbose level of ``1`` is recommended so that you only get important messages.
71+
Apart from machine configurations, ``preferences`` in ``config_user.json`` also includes a ``verbose_level`` flag, which indicates the amount of messages that are printed to the terminal when running MITIM:
72+
73+
.. code-block:: console
74+
75+
5: everything (normal prints + information prints + warning prints + questions + optimization progress)
76+
4: information prints + warning prints + questions + optimization progress
77+
3: information prints + warning prints + questions
78+
2: warning prints + questions
79+
1: warning prints
80+
0: nothing
81+
82+
7483
``preferences`` also allows a ``dpi_notebook`` value (in percent from standard), which should be adjusted for each user's screen configuration if the MITIM notebook figures are too small or too large.
7584

7685
This is an example of a ``config_user.json`` file that specifies that TGLF should be run in the *eofe7.mit.edu* machine and TGYRO in the *perlmutter.nersc.gov* machine.

0 commit comments

Comments
 (0)