Skip to content
Snippets Groups Projects
Commit a5a256a2 authored by Ian Bell's avatar Ian Bell
Browse files

Turn off global allowing of exceptions, granularly enable them on a per-cell basis

parent 8aa9ca75
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,8 @@ subprocess.check_output(f'jupyter nbconvert --version', shell=True)
for path, dirs, files in os.walk('.'):
for file in files:
if file.endswith('.ipynb') and '.ipynb_checkpoints' not in path:
subprocess.check_output(f'jupyter nbconvert --ExecutePreprocessor.allow_errors=True --to notebook --output {file} --execute {file}', shell=True, cwd=path)
subprocess.check_output(f'jupyter nbconvert --to notebook --output {file} --execute {file}', shell=True, cwd=path)
# --ExecutePreprocessor.allow_errors=True (this allows you to allow errors globally, but a raises-exception cell tag is better)
# -- General configuration ---------------------------------------------------
......
%% Cell type:markdown id: tags:
# Multi-fluid EOS
Peering into the innards of teqp
%% Cell type:code id: tags:
``` python
import timeit, json
import pandas
import numpy as np
import teqp
teqp.__version__
```
%% Output
'0.9.2'
%% Cell type:markdown id: tags:
## Pure fluid loading
%% Cell type:code id: tags:
``` python
# By default teqp looks for fluids relative to the set of fluids in ROOT/dev/fluids
# The name (case-sensitive) should match the .json file, without the json extension.
%timeit model = teqp.build_multifluid_model(["Methane", "Ethane"], teqp.get_datapath())
```
%% Output
12.9 ms ± 4.32 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)
%% Cell type:code id: tags:
``` python
# And if you provide valid aliases, alias lookup will be used to resolve the name
# But beware, this is rather a lot slower than the above because all fluid files need to be read
# in to build the alias map
%timeit model = teqp.build_multifluid_model(["n-C1H4", "n-C3H8"], teqp.get_datapath())
```
%% Output
120 ms ± 19.9 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
%% Cell type:markdown id: tags:
So, how to make it faster? Only do it once and cache
%% Cell type:code id: tags:
``` python
# Here is the set of possible aliases to absolute paths of files
# Building this map takes a little while (somewhat faster in C++) due to all the file reads
# If you know your files will not change, good idea to build this alias map yourself.
%timeit aliasmap = teqp.build_alias_map(teqp.get_datapath())
aliasmap = teqp.build_alias_map(teqp.get_datapath())
```
%% Output
85.4 ms ± 12.3 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
%% Cell type:code id: tags:
``` python
# Then load the absolute paths from the alias map,
# which will guarantee that you hit exactly what you were looking for,
# resolving aliases as needed
identifiers = [aliasmap[n] for n in ["Neon", "Hydrogen"]]
%timeit model = teqp.build_multifluid_model(identifiers, teqp.get_datapath())
```
%% Output
9.9 ms ± 164 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%% Cell type:markdown id: tags:
At some point soon teqp will support in-memory loading of JSON data for the pure components, without requiring reads from the operating system
%% Cell type:code id: tags:
``` python
# And you can also load the JSON that teqp is loading for the pure fluids
pureJSON = teqp.collect_component_json(['NEON','HYDROGEN'], teqp.get_datapath())
```
%% Cell type:markdown id: tags:
## Mixture model loading
%% Cell type:code id: tags:
``` python
# Load the default JSON for the binary interaction parameters
BIP = json.load(open(teqp.get_datapath()+'/dev/mixtures/mixture_binary_pairs.json'))
```
%% Cell type:code id: tags:
``` python
# You can obtain interaction parameters either by pairs of names, where name is the name that teqp uses, the ["INFO"]["NAME"] field
params, swap_needed = teqp.get_BIPdep(BIP, ['Methane','Ethane'])
params
```
%% Output
{'BibTeX': 'Kunz-JCED-2012',
'CAS1': '74-82-8',
'CAS2': '74-84-0',
'F': 1.0,
'Name1': 'Methane',
'Name2': 'Ethane',
'betaT': 0.996336508,
'betaV': 0.997547866,
'function': 'Methane-Ethane',
'gammaT': 1.049707697,
'gammaV': 1.006617867}
%% Cell type:code id: tags:
``` python
# Or also by CAS#
params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','74-84-0'])
params
```
%% Output
{'BibTeX': 'Kunz-JCED-2012',
'CAS1': '74-82-8',
'CAS2': '74-84-0',
'F': 1.0,
'Name1': 'Methane',
'Name2': 'Ethane',
'betaT': 0.996336508,
'betaV': 0.997547866,
'function': 'Methane-Ethane',
'gammaT': 1.049707697,
'gammaV': 1.006617867}
%% Cell type:code id: tags:
%% Cell type:code id: tags:raises-exception
``` python
# But mixing is not allowed
params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','Ethane'])
params
```
%% Output
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [10], in <cell line: 2>()
1 # But mixing is not allowed
----> 2 params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','Ethane'])
3 params
ValueError: Can't match the binary pair for: 74-82-8/Ethane
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment