Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contribution to OLI documentation efforts #1259

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
7742355
add credential manager to oli api
Sep 21, 2023
9cfbdd0
fix incorrect call from credential manager
Sep 21, 2023
7471305
run black
Sep 21, 2023
7011019
Update watertap/core/util/tests/test_credential_manager.py
veccp Sep 21, 2023
aff3272
fix cryptography module import
Sep 21, 2023
c28fbb1
Merge local with remote changes
Sep 21, 2023
9cd776a
run black on setup.py
Sep 21, 2023
1a70b7e
add missing get_login_status args
Sep 21, 2023
5edba7e
Improving credential manager testing
Sep 27, 2023
147ef3a
Helper functions for OLI/MCAS
Sep 27, 2023
80ea0c9
Run black
Sep 27, 2023
a696a6a
Add test for MCAS flowsheet method
Sep 27, 2023
80be656
watertap_to_oli tests
Oct 2, 2023
2e89e43
run black
Oct 3, 2023
e50caff
Merge in code demo and required changes
Oct 25, 2023
01bfc15
Merge branch 'watertap-main'
Oct 25, 2023
47edd73
Add OLI API tests, minor fixes
Oct 25, 2023
409e41e
Fix temp OLIApi client tests
Oct 27, 2023
e571a44
Improved formatting and documentation
Nov 1, 2023
22f4aac
Merge branch 'main' into main
adam-a-a Nov 7, 2023
e0d2b8c
add missing __init__.py file
Nov 8, 2023
9df4f69
initial revisions to OLI flash calcs
Nov 14, 2023
e582b6e
WIP - isothermal flash composition surveys
Nov 15, 2023
07b839e
move all features to Flash class
Nov 17, 2023
af45ecc
isothermal composition survey methods
Nov 21, 2023
7edc181
update examples
Nov 22, 2023
2c68595
move tutorials
Nov 28, 2023
b70819f
flash tests and documentation
Nov 30, 2023
d0fb36b
extract properties revisions
Dec 1, 2023
141d4b6
Merge remote-tracking branch 'upstream/main' into flash_calcs
bknueven Dec 1, 2023
e8e167e
remove water_analysis
bknueven Dec 1, 2023
4c17ab1
remove duplicate example notebook
bknueven Dec 1, 2023
596ada7
Merge pull request #1 from bknueven/flash_calcs
veccp Dec 1, 2023
e4c307e
revised extract_properties
Dec 2, 2023
3a351cb
flash calcs tutorial
Dec 4, 2023
c934aba
flash calcs tests
Dec 5, 2023
afa7cdd
black
Dec 5, 2023
6e5f5c8
Merge branch 'watertap-org:main' into flash_calcs
veccp Dec 5, 2023
0ab6681
unused import fixes
Dec 6, 2023
9227fa5
Merge branch 'flash_calcs' of github.com:veccp/watertap into flash_calcs
Dec 6, 2023
823f4e0
notebook test fix
Dec 6, 2023
133d0af
trying to fix RTD error
bknueven Dec 6, 2023
cd5a28b
remove cryptography from setup.py dev
veccp Dec 7, 2023
b27d9e8
minor flash fixes
Dec 8, 2023
f5562d5
Merge branch 'flash_calcs' of github.com:veccp/watertap into flash_calcs
Dec 8, 2023
a53bdfe
linting fix + documentation
Dec 8, 2023
b6bdd62
Merge branch 'main' into flash_calcs
bknueven Dec 13, 2023
7e28ac5
update test_flash.py
Dec 14, 2023
006cd78
replace some prints with logging
Dec 14, 2023
533117a
black
Dec 14, 2023
5087521
Merge branch 'main' into flash_calcs
OOAmusat Dec 15, 2023
4be8f6a
allow OLI access key expiry specification
Dec 18, 2023
5e9eff0
Merge branch 'flash_calcs' of github.com:veccp/watertap into flash_calcs
Dec 18, 2023
c051541
use datetime for OLI key timestamp
Dec 18, 2023
d98472c
black
Dec 18, 2023
2fd8b26
notebook and access key fixes
Dec 18, 2023
49bdbe5
notebook fix
Dec 18, 2023
d6c0ecc
notebook and flash fixes
Dec 20, 2023
4e2073c
access key generator fix
Dec 21, 2023
7318325
credential management notes
Dec 21, 2023
7c0d684
2 new oli-related tutorials
Dec 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
323 changes: 323 additions & 0 deletions tutorials/incorporating_oli_calculations.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,323 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"scrolled": true,
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"\n",
"# Incorporating OLI Calculations with WaterTAP\n",
"\n",
"#### Contact: Paul Vecchiarelli ([email protected])\n",
"\n",
"This tutorial will demonstrate basic usage of OLI Cloud calls using our custom API tools."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Rationale\n",
"\n",
" - Simulations for realistic water sources are mathematically complex: \n",
" > $ Interactions \\ge Cations * Anions$\n",
" - OLI improves WaterTAP approximations and offloads computational resources"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Required OLI API Inputs\n",
"\n",
"\n",
" - State variables (solute concentrations, temperature, pressure), which can beextracted from a state block\n",
" \n",
" - Login credentials\n",
" \n",
" - A chemistry (*.dbs) file\n",
" - establishes state variables, phases, etc. to be considered in flash calls"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"# used to specify state/convert variables\n",
"from pyomo.environ import units as pyunits\n",
"\n",
"# used to build survey lists\n",
"from numpy import linspace\n",
"\n",
"# used to execute OLI Cloud functions\n",
"from watertap.tools.oli_api.flash import Flash\n",
"from watertap.tools.oli_api.credentials import CredentialManager\n",
"from watertap.tools.oli_api.client import OLIApi"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# 1. Specify State Variables.\n",
"\n",
"- This data is used to construct inputs to OLI Cloud"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"source_water = {\n",
" \"temperature\": 298.15,\n",
" \"pressure\": 101325,\n",
" \"components\": {\n",
" \"Cl_-\": 870,\n",
" \"Na_+\": 739,\n",
" \"SO4_2-\": 1011,\n",
" \"Mg_2+\": 90,\n",
" \"Ca_2+\": 258,\n",
" \"K_+\": 9,\n",
" \"HCO3_-\": 385,\n",
" \"SiO2\": 30,\n",
" },\n",
" \"units\": {\n",
" \"temperature\": pyunits.K,\n",
" \"pressure\": pyunits.Pa,\n",
" \"components\": pyunits.mg / pyunits.L,\n",
" },\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# 2. Initialize Flash Instance.\n",
"\n",
" - We will run most of our methods with this class"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f = Flash()"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# 3. Get Survey Parameters.\n",
"\n",
" - In this example, we will generate a temperature sweep survey"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true,
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"survey_conditions = {\n",
" \"Temperature\": linspace(273, 373, 6),\n",
" \"SO4_2-\": linspace(1e2, 1e3, 10),\n",
" \"Ca_2+\": linspace(1e2, 1e3, 10),\n",
"}\n",
"\n",
"survey = f.build_survey(\n",
" survey_conditions,\n",
" get_oli_names=True,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# 4. Login to OLI Cloud.\n",
"\n",
"- The following code demonstrates an OLI Cloud login:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"try:\n",
" credential_manager = CredentialManager(\n",
" username=\"\",\n",
" password=\"\",\n",
" root_url=\"\",\n",
" auth_url=\"\",\n",
" access_keys=[],\n",
" )\n",
"except (OSError, ConnectionError) as e:\n",
" print(e)\n",
" credential_manager = None"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# 5. Create *.dbs File and 6. Get Output"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"if credential_manager:\n",
" with OLIApi(credential_manager) as oliapi:\n",
" dbs_file_id = oliapi.get_dbs_file_id(\n",
" chemistry_source=source_water[\"components\"],\n",
" phases=[\"liquid1\", \"solid\"],\n",
" model_name=\"tutorial_model\",\n",
" )\n",
"\n",
" water_analysis_base_case = f.build_flash_calculation_input(\n",
" flash_method=\"wateranalysis\",\n",
" state_vars=source_water, \n",
" )\n",
"\n",
" water_analysis_composition_survey = f.run_flash(\n",
" flash_method=\"wateranalysis\",\n",
" oliapi_instance=oliapi,\n",
" dbs_file_id=dbs_file_id,\n",
" initial_input=water_analysis_base_case,\n",
" survey=survey,\n",
" file_name=\"wateranalysis_composition_survey_temperature\",\n",
" )"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# 7. Extract Filtered Output\n",
"\n",
" - OLI's output is robust, so WaterTAP enables printing selected results:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"properties = [\n",
" \"prescalingTendencies\",\n",
" \"entropy\",\n",
" \"gibbsFreeEnergy\",\n",
" \"selfDiffusivities\",\n",
" \"molecularConcentration\",\n",
" \"kValuesMBased\",\n",
"]\n",
"\n",
"if credential_manager:\n",
" extracted_properties = f.extract_properties(\n",
" water_analysis_composition_survey,\n",
" properties,\n",
" filter_zero=True,\n",
" file_name=\"properties\",\n",
" )"
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.16"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading
Loading