nGibbs 0.0.1b4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ngibbs/__init__.py +17 -0
- ngibbs/_version.py +24 -0
- ngibbs/config/README_MLIndexer.md +418 -0
- ngibbs/config/__init__.py +1 -0
- ngibbs/config/constants.py +374 -0
- ngibbs/config/ml_indexer.py +767 -0
- ngibbs/config/projections/OxToElV2.csv +16 -0
- ngibbs/config/projections/OxToElV2_ferric.csv +16 -0
- ngibbs/config/projections/PxSp_Comp_TransformV2.csv +86 -0
- ngibbs/config/projections/PxSp_Comp_TransformV2_old.csv +75 -0
- ngibbs/config/projections/compToOxV2.csv +145 -0
- ngibbs/config/projections/compToOxV2_cationcharge.xlsx +0 -0
- ngibbs/engine/API.py +1885 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/control +141 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.1 +0 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.28 +1 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.42 +1110 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.56 +1 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.56.head +17 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.57 +15 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.58 +16 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.59 +16 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.601 +1 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.61 +16 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.62 +16 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.63 +16 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.64 +16 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.65 +16 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.66 +16 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.661 +16 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.67 +16 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.68 +16 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.69 +15 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.74 +2190 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.75 +15 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.811 +1095 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.812 +1095 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.813 +1095 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.89 +1 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.97 +15 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/fort.99 +16 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/landau +0 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/log +1136 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/out +1717 -0
- ngibbs/engine/EOS_arithmetic/BENCHMARK/qout +200 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/apbo +0 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/c2c +6 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/cf +12 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/coes +0 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/cpv +0 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/cpx +14 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/fea +0 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/fee +0 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/feg +0 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/gt +16 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/il +12 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/ky +0 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/mw +12 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/nal +8 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/neph +0 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/ol +6 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/opx +10 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/plg +6 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/ppv +12 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/pv +16 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/pwo +0 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/qtz +0 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/ri +6 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/sp +10 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/st +0 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/wa +6 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/PHASE/wo +0 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/README.md +21 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/ab +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/acm +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/al +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/alpv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/an +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/anao +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/andr +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/apbo +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/appv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/capv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/cats +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/cen +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/changelog +1848 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/co +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/coes +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/cppv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/crcf +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/crpv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/di +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/en +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/esk +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/fa +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/fapv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/fea +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/fec2 +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/fecf +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/fee +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/feg +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/feil +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/fepv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/feri +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/fewa +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/fnal +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/fo +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/fppv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/fs +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/gr +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/hc +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/he +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/hem +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/hepv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/hlpv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/hmag +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/hppv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/jd +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/knor +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/ky +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/lppv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/mag +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/mgc2 +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/mgcf +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/mgil +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/mgmj +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/mgpv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/mgri +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/mgts +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/mgwa +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/mnal +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/mppv +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/nacf +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/namj +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/neph +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/nnal +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/odi +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/out +17304 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/pe +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/picr +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/pwo +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/py +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/qtz +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/smag +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/sp +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/st +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/wo +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/wu +44 -0
- ngibbs/engine/EOS_arithmetic/HeFESTo_Parameters_010123/wuls +44 -0
- ngibbs/engine/EOS_arithmetic/__init__.py +0 -0
- ngibbs/engine/EOS_arithmetic/adqref.inc +2809 -0
- ngibbs/engine/EOS_arithmetic/benchmark_test.py +267 -0
- ngibbs/engine/EOS_arithmetic/dos_tables.npz +0 -0
- ngibbs/engine/EOS_arithmetic/hefesto_vec/__init__.py +15 -0
- ngibbs/engine/EOS_arithmetic/hefesto_vec/aggregate.py +516 -0
- ngibbs/engine/EOS_arithmetic/hefesto_vec/compute.py +361 -0
- ngibbs/engine/EOS_arithmetic/hefesto_vec/constants.py +43 -0
- ngibbs/engine/EOS_arithmetic/hefesto_vec/dos_tables.py +570 -0
- ngibbs/engine/EOS_arithmetic/hefesto_vec/gamset.py +199 -0
- ngibbs/engine/EOS_arithmetic/hefesto_vec/params.py +392 -0
- ngibbs/engine/EOS_arithmetic/hefesto_vec/pressure.py +264 -0
- ngibbs/engine/EOS_arithmetic/hefesto_vec/therm_props.py +578 -0
- ngibbs/engine/EOS_arithmetic/hefesto_vec/thermal.py +545 -0
- ngibbs/engine/EOS_arithmetic/hefesto_vec/volume.py +472 -0
- ngibbs/engine/EOS_arithmetic/perf_test.py +44 -0
- ngibbs/engine/EOS_arithmetic/qr19.py +251 -0
- ngibbs/engine/NN.py +1254 -0
- ngibbs/engine/TrainedModels/HeFESTo_Adiabats/HeFESTo_adiabats_NPS.tar +0 -0
- ngibbs/engine/TrainedModels/HeFESTo_Adiabats/HeFESTo_adiabats_NPT.tar +0 -0
- ngibbs/engine/TrainedModels/HeFESTo_Adiabats/T_from_S_HeFESTo_UMadiabats.pt +0 -0
- ngibbs/engine/TrainedModels/HeFESTo_Adiabats/T_from_S_HeFESTo_adiabats.pt +0 -0
- ngibbs/engine/TrainedModels/MELTS102/102Isentropic_Cr.tar +0 -0
- ngibbs/engine/TrainedModels/MELTS102/102Isentropic_NoCr.tar +0 -0
- ngibbs/engine/TrainedModels/MELTS102/102Isothermal_Cr.tar +0 -0
- ngibbs/engine/TrainedModels/MELTS102/102Isothermal_NoCr.tar +0 -0
- ngibbs/engine/TrainedModels/MELTS102/102OpenOx_Cr.tar +0 -0
- ngibbs/engine/TrainedModels/MELTS102/102OpenOx_NoCr.tar +0 -0
- ngibbs/engine/TrainedModels/MELTS102/chosen_models.txt +3 -0
- ngibbs/engine/TrainedModels/MELTS120/120Isothermal_Cr.tar +0 -0
- ngibbs/engine/TrainedModels/MELTS120/120Isothermal_NoCr.tar +0 -0
- ngibbs/engine/TrainedModels/MELTS120/120OpenOx_Cr.tar +0 -0
- ngibbs/engine/TrainedModels/MELTS120/chosen_models.txt +3 -0
- ngibbs/engine/TrainedModels/oldMELTS102/ChosenModels.txt +3 -0
- ngibbs/engine/TrainedModels/oldMELTS102/Isentropic_Cr.tar +0 -0
- ngibbs/engine/TrainedModels/oldMELTS102/Isentropic_NoCr.tar +0 -0
- ngibbs/engine/TrainedModels/oldMELTS102/Isothermal_Cr.tar +0 -0
- ngibbs/engine/TrainedModels/oldMELTS102/Isothermal_NoCr.tar +0 -0
- ngibbs/engine/__init__.py +1 -0
- ngibbs/engine/emulator.py +1269 -0
- ngibbs/utils/__init__.py +1 -0
- ngibbs/utils/file_utils.py +1028 -0
- ngibbs/utils/math_utils.py +750 -0
- ngibbs/utils/string_utils.py +174 -0
- ngibbs-0.0.1b4.dist-info/METADATA +1507 -0
- ngibbs-0.0.1b4.dist-info/RECORD +198 -0
- ngibbs-0.0.1b4.dist-info/WHEEL +5 -0
- ngibbs-0.0.1b4.dist-info/licenses/LICENSE +637 -0
- ngibbs-0.0.1b4.dist-info/top_level.txt +1 -0
ngibbs/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#nGibbs - Neural network emulators for MELTS and HeFESTo thermodynamic modeling.
|
|
2
|
+
#Importing models here
|
|
3
|
+
|
|
4
|
+
"""try:
|
|
5
|
+
import torch
|
|
6
|
+
from .engine.API import MELTS102EmulatorCPU, HeFESToEmulatorCPU
|
|
7
|
+
if torch.cuda.is_available():
|
|
8
|
+
from .engine.API import MELTS102EmulatorGPU, HeFESToEmulatorGPU
|
|
9
|
+
|
|
10
|
+
except:
|
|
11
|
+
print('PyTorch is not installed. Please install PyTorch to use nGibbs emulators.')
|
|
12
|
+
pass"""
|
|
13
|
+
|
|
14
|
+
"""import torch
|
|
15
|
+
from .engine.API import MELTS102EmulatorCPU, HeFESToEmulatorCPU
|
|
16
|
+
if torch.cuda.is_available():
|
|
17
|
+
from .engine.API import MELTS102EmulatorGPU, HeFESToEmulatorGPU"""
|
ngibbs/_version.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '0.0.1b4'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 0, 1, 'b4')
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
# MLIndexer Documentation
|
|
2
|
+
|
|
3
|
+
The `MLIndexer` class creates ML-ready indexers and transformation matrices from MELTS component specifications. It handles the mapping between MELTS components, oxides, and elements, while managing phase compositions and building projection matrices for neural network training.
|
|
4
|
+
|
|
5
|
+
## Dimension Notation
|
|
6
|
+
|
|
7
|
+
Throughout this document, we use the following dimension notation:
|
|
8
|
+
|
|
9
|
+
- **C** = `ncomps` - Total number of components across all phases
|
|
10
|
+
- **P** = `nphases` - Total number of phases
|
|
11
|
+
- **VP** = Number of compositionally variable phases (phases with >1 component). VP = len(compositionally_variable_phases)
|
|
12
|
+
- **VC** = `ncompsVaried` - Total number of components in compositionally variable phases. This is the composition output dimension for nMELTS
|
|
13
|
+
- **E** = Number of elements (length of `Elkeys`)
|
|
14
|
+
- **O** = Number of oxides (length of `Oxides`, includes Fe2O3), always O = E + 1
|
|
15
|
+
|
|
16
|
+
## Constructor Parameters
|
|
17
|
+
|
|
18
|
+
### `components_in_phases` : Dict[str, List[str]], optional
|
|
19
|
+
Dictionary mapping phase names to their component lists. This is created and passed to ml_indexer by DatasetIndexer.
|
|
20
|
+
- **Example**: `{'olivine': ['fayalite', 'forsterite'], 'melts-liquid': ['Si', 'Ti', 'Al', ...]}`
|
|
21
|
+
|
|
22
|
+
### `Elkeys` : List[str], optional
|
|
23
|
+
List of element symbols within the system. This is passed to ml_indexer by DatasetIndexer
|
|
24
|
+
- **Default**: Extracted from `default_Elkeys` if not provided
|
|
25
|
+
- **Example**: `['Si', 'Ti', 'Al', 'Fe', 'Mg', 'Ca', 'Na', 'K', 'P', 'H', 'Cr', 'Mn', 'Ni']`
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Core Attributes
|
|
30
|
+
|
|
31
|
+
### Phase and Component Indices
|
|
32
|
+
|
|
33
|
+
#### `label_names` : List[str]
|
|
34
|
+
**Dimension**: (C,)
|
|
35
|
+
Ordered list of all component names across all phases.
|
|
36
|
+
- Components are ordered by phase (`'melts-liquid'` comes last)
|
|
37
|
+
- **Example**: `['fayalite', 'forsterite', 'diopside', 'hedenbergite', ..., 'Si', 'Ti', 'Al', ...]`
|
|
38
|
+
- *Test*:
|
|
39
|
+
- len
|
|
40
|
+
|
|
41
|
+
#### `label_indices` : Dict[str, np.ndarray]
|
|
42
|
+
**Dimension**: Phase → List of indices into (C,)
|
|
43
|
+
Maps each phase name to its component indices in `label_names`.
|
|
44
|
+
- **Type**: `np.ndarray` of dtype `int`
|
|
45
|
+
- **Example**: `{'olivine': [0, 1], 'clinopyroxene': [2, 3], 'melts-liquid': [50, 51, ..., 62]}`
|
|
46
|
+
- *Test*:
|
|
47
|
+
- Sum of all list lengths equals C
|
|
48
|
+
- max value in compiled list = C-1
|
|
49
|
+
|
|
50
|
+
#### `label_indices_comp` : Dict[str, np.ndarray]
|
|
51
|
+
**Dimension**: Phase → List of indices into (VC,)
|
|
52
|
+
Maps phase names to arrays of their component indices in the varied-composition space.
|
|
53
|
+
- Only includes compositionally variable phases
|
|
54
|
+
- **Type**: `np.ndarray` of dtype `int`
|
|
55
|
+
- **Example**: `{'olivine': array([0, 1]), 'clinopyroxene': array([2, 3])}`
|
|
56
|
+
- *Test*:
|
|
57
|
+
- Sum of all list lengths equals VC
|
|
58
|
+
- max value in compiled list = VC-1
|
|
59
|
+
|
|
60
|
+
#### `comp_map` : Dict[str, np.ndarray]
|
|
61
|
+
Identical to `label_indices_comp`, kept for backward compatibility
|
|
62
|
+
- *Test*:
|
|
63
|
+
- identical to label_indices_comp
|
|
64
|
+
|
|
65
|
+
#### `detail_label_indices` : Dict[str, Dict[str, int]]
|
|
66
|
+
**Dimension**: Phase → Component → index into (VC,)
|
|
67
|
+
Nested dictionary mapping phase and component names to indices in the compositionally-variable component space.
|
|
68
|
+
- Only includes phases with >1 component
|
|
69
|
+
- **Example**: `{'olivine': {'fayalite': 0, 'forsterite': 1}, 'clinopyroxene': {'diopside': 2, 'hedenbergite': 3}}`
|
|
70
|
+
- *Test*:
|
|
71
|
+
- each nested dictionary contains > 1 entry
|
|
72
|
+
- the amount of 1st-level entries = VP
|
|
73
|
+
- the amount of all nested entries = VC
|
|
74
|
+
- max value in compiled list = VC-1
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
### Phase Organization
|
|
78
|
+
|
|
79
|
+
#### `all_phases` : List[str]
|
|
80
|
+
**Dimension**: (P,)
|
|
81
|
+
Ordered list of all phase names.
|
|
82
|
+
- **Example**: `['olivine', 'clinopyroxene', 'plagioclase', 'spinel', 'melts-liquid']`
|
|
83
|
+
- *Test*:
|
|
84
|
+
- len
|
|
85
|
+
|
|
86
|
+
#### `compositionally_variable_phases` : List[str]
|
|
87
|
+
**Dimension**: (VP,)
|
|
88
|
+
List of phases with multiple components (solid solutions).
|
|
89
|
+
VP = len(compositionally_variable_phases)
|
|
90
|
+
- **Example**: `['olivine', 'clinopyroxene', 'plagioclase', 'melts-liquid']`
|
|
91
|
+
- Excludes phases like pure `'quartz'` or `'Apatite'`
|
|
92
|
+
- *Test*:
|
|
93
|
+
- len = VP
|
|
94
|
+
|
|
95
|
+
#### `mass_phasedict` : Dict[str, int]
|
|
96
|
+
**Dimension**: Phase → index into (P,)
|
|
97
|
+
Maps phase names to their indices in the full phase list. Used by nMELTS for indexing phase abundances
|
|
98
|
+
- **Example**: `{'olivine': 0, 'clinopyroxene': 1, 'plagioclase': 2, 'spinel': 3, 'melts-liquid': 4}`
|
|
99
|
+
- *Test*:
|
|
100
|
+
- len = P
|
|
101
|
+
|
|
102
|
+
#### `comp_phasedict` : Dict[str, int]
|
|
103
|
+
**Dimension**: Phase → index into (VP,)
|
|
104
|
+
Maps compositionally variable phase names to their indices among variable phases only.
|
|
105
|
+
- **Example**: `{'olivine': 0, 'clinopyroxene': 1, 'plagioclase': 2, 'melts-liquid': 3}`
|
|
106
|
+
- Only includes phases in `compositionally_variable_phases`
|
|
107
|
+
- *Test*:
|
|
108
|
+
- len = VP
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### Size Counters
|
|
113
|
+
|
|
114
|
+
#### `ncomps` : int
|
|
115
|
+
Total number of components across all phases (C).
|
|
116
|
+
|
|
117
|
+
#### `ncompsVaried` : int
|
|
118
|
+
Total number of components in compositionally variable phases (VC).
|
|
119
|
+
|
|
120
|
+
#### `nphases` : int
|
|
121
|
+
Total number of phases (P).
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Transformation Matrices
|
|
126
|
+
|
|
127
|
+
### Component-Oxide Transformations
|
|
128
|
+
|
|
129
|
+
#### `compToOxLoad` : np.ndarray
|
|
130
|
+
**Dimension**: (C, O)
|
|
131
|
+
**Type**: `float32`
|
|
132
|
+
Raw projection matrix from components to oxides, loaded and filtered from CSV. For non-MELTS: Identical to compToOx
|
|
133
|
+
- Maps each component to its oxide composition
|
|
134
|
+
- Includes Fe2O3 column
|
|
135
|
+
- *Test*:
|
|
136
|
+
- dtype
|
|
137
|
+
- dims
|
|
138
|
+
|
|
139
|
+
#### `PxSpTransform` : np.ndarray
|
|
140
|
+
**Dimension**: (C, C)
|
|
141
|
+
**Type**: `float32`
|
|
142
|
+
Component transformation matrix for Px-Sp all-positive remappings. For non-MELTS: the identifty matrix.
|
|
143
|
+
- Square matrix transforming component space
|
|
144
|
+
- Projects components into an all-positive space for ease of use with softmax activation function to predict chemistry.
|
|
145
|
+
- Saved to `projections_dir/PxSp_Comp_Transform_gathered.csv` during initialization
|
|
146
|
+
- *Test*:
|
|
147
|
+
- dims
|
|
148
|
+
- dtype
|
|
149
|
+
- Is Invertible
|
|
150
|
+
- The submatrix that excludes spinel (except chromite), cpx, and opx is an identity matrix (diagonal = 1, else 0)
|
|
151
|
+
|
|
152
|
+
#### `compToOx` : np.ndarray
|
|
153
|
+
**Dimension**: (C, O)
|
|
154
|
+
**Type**: `float32`
|
|
155
|
+
Final component-to-oxide projection matrix, including transformed, positive, nonzero spinel and pyroxene components
|
|
156
|
+
- Computed as: `inv(PxSpTransform) @ compToOxLoad`
|
|
157
|
+
- Maps component compositions to oxide weight fractions
|
|
158
|
+
- *Test*:
|
|
159
|
+
- dims
|
|
160
|
+
- dtype
|
|
161
|
+
- The submatrix that excludes spinel (except chromite), cpx, and opx is identical to the corresponding submatrix of compToOxLoad
|
|
162
|
+
|
|
163
|
+
#### `boolTransCompToOx` : np.ndarray or None
|
|
164
|
+
**Dimension**: (C, E)
|
|
165
|
+
**Type**: `int` (0 or 1)
|
|
166
|
+
Boolean mask indicating which oxides each component contributes to.
|
|
167
|
+
- Derived from `compToOx` by converting non-zero values to 1
|
|
168
|
+
- Fe2O3 is folded into FeO column for whole-rock compatibility (This might be problematic?)
|
|
169
|
+
- Used for masking and sparsity analysis
|
|
170
|
+
- *Test*:
|
|
171
|
+
- dims
|
|
172
|
+
- dtype
|
|
173
|
+
|
|
174
|
+
### Oxide-Element Transformations
|
|
175
|
+
|
|
176
|
+
#### `OxToEl` : np.ndarray
|
|
177
|
+
**Dimension**: (O, E) = (E+1 , E)
|
|
178
|
+
**Type**: `float32`
|
|
179
|
+
Projection matrix from oxides to elements.
|
|
180
|
+
- Maps oxide mole fractions to elemental mole fractions
|
|
181
|
+
- Includes Fe2O3 row
|
|
182
|
+
- *Test*:
|
|
183
|
+
- dims
|
|
184
|
+
- dtype
|
|
185
|
+
|
|
186
|
+
#### `ElToOx` : np.ndarray
|
|
187
|
+
**Dimension**: (E, E)
|
|
188
|
+
**Type**: `float32`
|
|
189
|
+
Inverse transformation from elements back to oxides.
|
|
190
|
+
- Computed as: `inv(OxToEl[:E, :])`
|
|
191
|
+
- Maps elemental composition to total iron oxides (FeO equivalent)
|
|
192
|
+
- does not map back to Fe2O3, FeO partitioning can be solved for in the liquid given PTfO2
|
|
193
|
+
- *Test*:
|
|
194
|
+
- dims
|
|
195
|
+
- dtype
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
### Molar Mass Matrices
|
|
199
|
+
|
|
200
|
+
#### `MM` : np.ndarray
|
|
201
|
+
**Dimension**: (O, O)
|
|
202
|
+
**Type**: `float32`
|
|
203
|
+
Diagonal matrix of oxide molar masses.
|
|
204
|
+
- `MM[i, i]` = molar mass of `Oxides[i]` in g/mol
|
|
205
|
+
- Used for mass-to-mole conversions
|
|
206
|
+
- *Test*:
|
|
207
|
+
- dims
|
|
208
|
+
- diagonal matrix
|
|
209
|
+
|
|
210
|
+
#### `Minv` : np.ndarray
|
|
211
|
+
**Dimension**: (O, O)
|
|
212
|
+
**Type**: `float32`
|
|
213
|
+
Diagonal matrix of inverse molar masses.
|
|
214
|
+
- `Minv[i, i]` = 1 / (molar mass of `Oxides[i]`)
|
|
215
|
+
- Used for mole-to-mass conversions
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
#### `Mtot` : np.ndarray
|
|
219
|
+
**Dimension**: (O, 1)
|
|
220
|
+
**Type**: `float32`
|
|
221
|
+
Column vector of oxide molar masses.
|
|
222
|
+
- Used for broadcasting operations in mass/mole calculations
|
|
223
|
+
- *Test*:
|
|
224
|
+
- dims
|
|
225
|
+
- identical to diag of MM
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## ML-Ready Mapping Matrices
|
|
229
|
+
|
|
230
|
+
### Phase-Component Mappings
|
|
231
|
+
|
|
232
|
+
#### `phaseToCompMap` : np.ndarray
|
|
233
|
+
**Dimension**: (P, C)
|
|
234
|
+
**Type**: `float32`
|
|
235
|
+
Binary matrix mapping phases to their components.
|
|
236
|
+
- `phaseToCompMap[p, c] = 1.0` if component `c` belongs to phase `p`
|
|
237
|
+
- Used to aggregate component masses/compositions to phase level
|
|
238
|
+
- For example: to multiply weights by composition to get an extensive component matrix
|
|
239
|
+
- *Test*:
|
|
240
|
+
- dims
|
|
241
|
+
- columwise sum is all ones
|
|
242
|
+
- dtype
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
#### `variedToAllComp` : np.ndarray
|
|
246
|
+
**Dimension**: (VC, C)
|
|
247
|
+
**Type**: `float32`
|
|
248
|
+
Maps varied-composition component indices to full component indices.
|
|
249
|
+
- `variedToAllComp[vc, c] = 1.0` if varied component `vc` corresponds to full component `c`
|
|
250
|
+
- Identity-like matrix for subsetting compositionally variable components
|
|
251
|
+
- Used as an indexer to pull chemically variable phase components from full component matrix
|
|
252
|
+
- *Test*:
|
|
253
|
+
- dims
|
|
254
|
+
- rowwise sum is all ones
|
|
255
|
+
- dtype
|
|
256
|
+
|
|
257
|
+
#### `compositionally_variable_binaries` : np.ndarray
|
|
258
|
+
**Dimension**: (P,)
|
|
259
|
+
**Type**: `bool` (0 or 1)
|
|
260
|
+
Binary indicator for compositionally variable phases.
|
|
261
|
+
- `compositionally_variable_binaries[p] = 1` if phase `p` has >1 component
|
|
262
|
+
- Used for masking and conditional operations, or to take VP subset of P
|
|
263
|
+
- *Test*:
|
|
264
|
+
- len
|
|
265
|
+
- dtype
|
|
266
|
+
- sum = VP
|
|
267
|
+
|
|
268
|
+
#### `compositionally_variable_subset` : np.ndarray
|
|
269
|
+
**Dimension**: (VC,)
|
|
270
|
+
**Type**: `int`
|
|
271
|
+
Indices of compositionally variable components in the full component list.
|
|
272
|
+
- Selects components belonging to variable-composition phases from (C,) arrays
|
|
273
|
+
- **Example**: `[0, 1, 2, 3, 50, 51, 52, ...]` for olivine, cpx, and liquid components
|
|
274
|
+
- Used for indexing VC subset of C. 1D alternative to variedToAllComp.T
|
|
275
|
+
- *Test*:
|
|
276
|
+
- len
|
|
277
|
+
- dtype
|
|
278
|
+
|
|
279
|
+
#### `compositional_component_subset` : np.ndarray
|
|
280
|
+
**Dimension**: (VC,)
|
|
281
|
+
**Type**: `int`
|
|
282
|
+
Copy of `compositionally_variable_subset` (maintained for backward compatibility).
|
|
283
|
+
- *Test*:
|
|
284
|
+
- identical to compositionally_variable_subset
|
|
285
|
+
|
|
286
|
+
#### `fixed_phaseToCompMap` : np.ndarray
|
|
287
|
+
**Dimension**: (1, C)
|
|
288
|
+
**Type**: `float32`
|
|
289
|
+
Aggregated mapping for all fixed-composition phases.
|
|
290
|
+
- Row vector where entry `c` is 1.0 if component `c` belongs to any fixed phase
|
|
291
|
+
- Computed as: `(~is_variable).reshape(1, -1) @ phaseToCompMap`
|
|
292
|
+
- Could be used to take 1D vector of fixed composition phases from a phase ownership matrix of shape (C, P)
|
|
293
|
+
- *Test*:
|
|
294
|
+
- dim
|
|
295
|
+
- dtype
|
|
296
|
+
- sum = P-VP
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
#### `comp_variable_IDMAT` : torch.Tensor
|
|
300
|
+
**Dimension**: (P, P)
|
|
301
|
+
**Type**: `torch.float`
|
|
302
|
+
Diagonal identity matrix for compositionally variable phases.
|
|
303
|
+
- `comp_variable_IDMAT[p, p] = 1.0` if phase `p` is compositionally variable, else 0
|
|
304
|
+
- Used to zero out pure phases
|
|
305
|
+
- *Test*:
|
|
306
|
+
- dim
|
|
307
|
+
- dtype
|
|
308
|
+
- sum = VP
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## Backward-Compatibility Structures
|
|
313
|
+
|
|
314
|
+
These attributes maintain compatibility with older code:
|
|
315
|
+
|
|
316
|
+
#### `comp_binaries` : np.ndarray
|
|
317
|
+
**Dimension**: (VP,)
|
|
318
|
+
**Type**: `int`
|
|
319
|
+
Phase indices (in `all_phases`) of compositionally variable phases.
|
|
320
|
+
- *Test*:
|
|
321
|
+
- dim
|
|
322
|
+
- dtype
|
|
323
|
+
|
|
324
|
+
#### `comp_mappings` : np.ndarray
|
|
325
|
+
**Dimension**: (VP, VC)
|
|
326
|
+
**Type**: `float32`
|
|
327
|
+
Maps compositionally variable phases to their components.
|
|
328
|
+
- `comp_mappings[vp, vc] = 1.0` if component `vc` belongs to variable phase `vp`
|
|
329
|
+
- *Test*:
|
|
330
|
+
- dim
|
|
331
|
+
- dtype
|
|
332
|
+
- columnwise sums = 1
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
## Element and Oxide Lists
|
|
336
|
+
|
|
337
|
+
#### `Elkeys` : List[str]
|
|
338
|
+
**Dimension**: (E,)
|
|
339
|
+
Element symbols for liquid composition.
|
|
340
|
+
E = len(Elkeys)
|
|
341
|
+
- **Example**: `['Si', 'Ti', 'Al', 'Fe', 'Mg', 'Ca', 'Na', 'K', 'P', 'H', 'Cr', 'Mn', 'Ni']`
|
|
342
|
+
|
|
343
|
+
#### `WRkeys` : List[str]
|
|
344
|
+
**Dimension**: (E,)
|
|
345
|
+
Whole-rock oxide names (excludes Fe2O3).
|
|
346
|
+
- **Example**: `['SiO2', 'TiO2', 'Al2O3', 'FeO', 'MgO', 'CaO', 'Na2O', 'K2O', 'P2O5', 'H2O', 'Cr2O3', 'MnO', 'NiO']`
|
|
347
|
+
- *Test*:
|
|
348
|
+
- len = E + 1
|
|
349
|
+
|
|
350
|
+
#### `Oxides` : List[str]
|
|
351
|
+
**Dimension**: (O,)
|
|
352
|
+
All oxide names including Fe2O3.
|
|
353
|
+
- **Example**: `['SiO2', 'TiO2', 'Al2O3', 'FeO', 'MgO', 'CaO', 'Na2O', 'K2O', 'P2O5', 'H2O', 'Cr2O3', 'MnO', 'NiO', 'Fe2O3']`
|
|
354
|
+
- *Test*:
|
|
355
|
+
- len = E + 1
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## Usage Example
|
|
359
|
+
|
|
360
|
+
```python
|
|
361
|
+
from src.nMELTS.config.ml_indexer import MLIndexer
|
|
362
|
+
|
|
363
|
+
# Define components for each phase
|
|
364
|
+
components_in_phases = {
|
|
365
|
+
'olivine': ['fayalite', 'forsterite'],
|
|
366
|
+
'clinopyroxene': ['diopside', 'hedenbergite'],
|
|
367
|
+
'melts-liquid': None # Will use Elkeys
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
# Create indexer
|
|
371
|
+
indexer = MLIndexer(
|
|
372
|
+
components_in_phases=components_in_phases,
|
|
373
|
+
Elkeys=['Si', 'Ti', 'Al', 'Fe', 'Mg', 'Ca', 'Na', 'K']
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
# Access attributes
|
|
377
|
+
print(f"Total components: {indexer.ncomps}")
|
|
378
|
+
print(f"Number of phases: {indexer.nphases}")
|
|
379
|
+
print(f"Variable phases: {indexer.compositionally_variable_phases}")
|
|
380
|
+
|
|
381
|
+
# Use transformation matrices
|
|
382
|
+
component_vector = np.random.rand(indexer.ncomps)
|
|
383
|
+
oxide_composition = indexer.compToOx.T @ component_vector
|
|
384
|
+
|
|
385
|
+
# Map phases to components
|
|
386
|
+
phase_masses = np.random.rand(indexer.nphases)
|
|
387
|
+
component_masses = indexer.phaseToCompMap.T @ phase_masses
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## Key Relationships
|
|
393
|
+
|
|
394
|
+
1. **Component Counts**:
|
|
395
|
+
- `len(label_names) == ncomps == C`
|
|
396
|
+
- `ncompsVaried ≤ ncomps` (only counts components in variable phases)
|
|
397
|
+
|
|
398
|
+
2. **Phase Counts**:
|
|
399
|
+
- `len(all_phases) == nphases == P`
|
|
400
|
+
- `len(compositionally_variable_phases) ≤ nphases`
|
|
401
|
+
|
|
402
|
+
3. **Matrix Shapes**:
|
|
403
|
+
- `phaseToCompMap @ component_vector` → phase aggregation (C,) → (P,)
|
|
404
|
+
- `compToOx.T @ component_vector` → oxide composition (C,) → (O,)
|
|
405
|
+
- `OxToEl.T @ oxide_vector` → element composition (O,) → (E,)
|
|
406
|
+
|
|
407
|
+
4. **Special Phase Handling**:
|
|
408
|
+
- `'melts-liquid'` always appears last in orderings
|
|
409
|
+
- `'melts-liquid'` components come from `Elkeys`, not `components_in_phases`
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## Notes
|
|
414
|
+
|
|
415
|
+
- **Thread Safety**: Not thread-safe; create separate instances for parallel processing
|
|
416
|
+
- **PyTorch**: If unavailable, `comp_variable_IDMAT` will be `None`
|
|
417
|
+
- **File Dependencies**: Requires projection CSVs in `projections_dir`
|
|
418
|
+
- **Immutability**: Attributes should be treated as read-only after initialization
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Configuration management for nMELTS."""
|