Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
teqp_fork_old
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sven Michael Pohl
teqp_fork_old
Commits
a5a256a2
Commit
a5a256a2
authored
2 years ago
by
Ian Bell
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/source/conf.py
+2
-1
2 additions, 1 deletion
doc/source/conf.py
doc/source/models/multifluid.ipynb
+4
-1
4 additions, 1 deletion
doc/source/models/multifluid.ipynb
with
6 additions
and
2 deletions
doc/source/conf.py
+
2
−
1
View file @
a5a256a2
...
...
@@ -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 ---------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
doc/source/models/multifluid.ipynb
+
4
−
1
View file @
a5a256a2
...
...
@@ -298,7 +298,10 @@
"iopub.status.busy": "2022-07-06T18:40:42.996338Z",
"iopub.status.idle": "2022-07-06T18:40:43.423368Z",
"shell.execute_reply": "2022-07-06T18:40:43.422895Z"
}
},
"tags": [
"raises-exception"
]
},
"outputs": [
{
...
...
%% 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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment