Skip to content

Commit

Permalink
Cleanup before release
Browse files Browse the repository at this point in the history
  • Loading branch information
c-randall committed Nov 11, 2024
1 parent 65b203e commit 47c3457
Show file tree
Hide file tree
Showing 16 changed files with 166 additions and 132 deletions.
67 changes: 42 additions & 25 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.13'

Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.13'

Expand All @@ -131,38 +131,55 @@ jobs:

- name: Build distributions
run: python -m build

- name: Test binary installation
run: |
pip uninstall thevenin
pip cache purge
python -m pip install --upgrade pip
pip install dist/*.whl -v
pip install pytest
pytest ./tests
- name: Test source installation
run: |
pip uninstall thevenin
pip cache purge
python -m pip install --upgrade pip
pip install dist/*.tar.gz -v
pip install pytest
pytest ./tests

- name: Upload
uses: actions/upload-artifact@v4
with:
name: builds
path: dist/*

test:
name: (test ${{ matrix.python-version }}, ${{ matrix.os }})
needs: build
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: [macos-13, macos-latest, windows-latest, ubuntu-latest]
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']

defaults:
run:
shell: bash -l {0}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist/
pattern: builds*
merge-multiple: true

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install thevenin
run: pip install dist/*.whl -v

- name: Pytest
run: |
pip install pytest
pytest ./tests
pypi-publish:
name: Upload to PyPI
needs: build
needs: test
runs-on: ubuntu-latest

steps:
Expand Down
12 changes: 6 additions & 6 deletions docs/jupyter_execute/examples/dict_inputs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"metadata": {},
"outputs": [],
"source": [
"import thevenin\n",
"import numpy as np"
"import numpy as np\n",
"import thevenin as thev"
]
},
{
Expand Down Expand Up @@ -121,7 +121,7 @@
"metadata": {},
"source": [
"## Construct a Model\n",
"The model is constructed below using all necessary keyword arguments. You can see a list of these parameters using ``help(thevenin.Model)``."
"The model is constructed below using all necessary keyword arguments. You can see a list of these parameters using ``help(thev.Model)``."
]
},
{
Expand All @@ -146,7 +146,7 @@
" 'C1': C1_func,\n",
"}\n",
"\n",
"model = thevenin.Model(params)"
"model = thev.Model(params)"
]
},
{
Expand All @@ -156,7 +156,7 @@
"## Build an Experiment\n",
"Experiments are built using the `Experiment` class. An experiment starts out empty and is then constructed by adding a series of current-, voltage-, or power-controlled steps. Each step requires knowing the control mode/units, the control value, a relative time span, and limiting criteria (optional). Control values can be specified as either constants or dynamic profiles with sinatures like `f(t: float) -> float` where `t` is the relative time of the new step, in seconds. The experiment below discharges at a nominal C/5 rate for up to 5 hours. A limit is set such that if the voltage hits 3 V then the next step is triggered early. Afterward, the battery rests for 10 min before charging at C/5 for 5 hours or until 4.2 V is reached. The final step is a 1 hour voltage hold at 4.2 V.\n",
"\n",
"Note that the time span for each step is constructed as `(t_max: float, dt: float)` which is used to determine the time array as `tspan = np.arange(0., t_max + dt, dt)`. You can also construct a time array given `(t_max: float, Nt: int)` by using an integer instead of a float in the second position. In this case, `tspan = np.linspace(0., t_max, Nt)`. To learn more about building an experiment, including which limits are allowed and/or how to adjust solver settings on a per-step basis, see the documentation `help(thevenin.Experiment)`."
"Note that the time span for each step is constructed as `(t_max: float, dt: float)` which is used to determine the time array as `tspan = np.arange(0., t_max + dt, dt)`. You can also construct a time array given `(t_max: float, Nt: int)` by using an integer instead of a float in the second position. In this case, `tspan = np.linspace(0., t_max, Nt)`. To learn more about building an experiment, including which limits are allowed and/or how to adjust solver settings on a per-step basis, see the documentation `help(thev.Experiment)`."
]
},
{
Expand All @@ -165,7 +165,7 @@
"metadata": {},
"outputs": [],
"source": [
"expr = thevenin.Experiment()\n",
"expr = thev.Experiment()\n",
"expr.add_step('current_A', 15., (5.*3600., 60.), limits=('voltage_V', 3.))\n",
"expr.add_step('current_A', 0., (600., 5.))\n",
"expr.add_step('current_A', -15., (5.*3600., 60.), limits=('voltage_V', 4.2))\n",
Expand Down
16 changes: 8 additions & 8 deletions docs/jupyter_execute/examples/ramping.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
"metadata": {},
"outputs": [],
"source": [
"import thevenin\n",
"import thevenin as thev\n",
"import matplotlib.pyplot as plt\n",
"\n",
"def voltage_ramp(t: float) -> float:\n",
" return 3.5 + 5e-3*t\n",
"\n",
"expr = thevenin.Experiment()\n",
"expr = thev.Experiment()\n",
"expr.add_step('current_A', 75., (3600., 60.), limits=('voltage_V', 3.5))\n",
"expr.add_step('voltage_V', voltage_ramp, (600., 10.), limits=('voltage_V', 4.2))"
]
Expand All @@ -58,9 +58,9 @@
"metadata": {},
"outputs": [],
"source": [
"voltage_ramp = thevenin.loadfns.Ramp(5e-3, 3.5)\n",
"voltage_ramp = thev.loadfns.Ramp(5e-3, 3.5)\n",
"\n",
"expr = thevenin.Experiment()\n",
"expr = thev.Experiment()\n",
"expr.add_step('current_A', 75., (3600., 60.), limits=('voltage_V', 3.5))\n",
"expr.add_step('voltage_V', voltage_ramp, (600., 10.), limits=('voltage_V', 4.2))"
]
Expand Down Expand Up @@ -98,7 +98,7 @@
}
],
"source": [
"model = thevenin.Model()\n",
"model = thev.Model()\n",
"\n",
"soln = model.run(expr)\n",
"soln.plot('time_min', 'voltage_V')"
Expand Down Expand Up @@ -147,9 +147,9 @@
}
],
"source": [
"dynamic_load = thevenin.loadfns.Ramp2Constant(20*75/1e-3, 20*75)\n",
"dynamic_load = thev.loadfns.Ramp2Constant(20*75/1e-3, 20*75)\n",
"\n",
"expr = thevenin.Experiment()\n",
"expr = thev.Experiment()\n",
"expr.add_step('current_A', dynamic_load, (180., 0.5), limits=('voltage_V', 3.))\n",
"\n",
"soln = model.run(expr)\n",
Expand Down Expand Up @@ -184,7 +184,7 @@
}
],
"source": [
"expr = thevenin.Experiment()\n",
"expr = thev.Experiment()\n",
"expr.add_step('current_A', 75*20, (180., 75), limits=('voltage_V', 3.))\n",
"\n",
"soln2 = model.run(expr)\n",
Expand Down
12 changes: 6 additions & 6 deletions docs/jupyter_execute/examples/step_functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@
}
],
"source": [
"import thevenin\n",
"import thevenin as thev\n",
"import numpy as np\n",
"\n",
"model = thevenin.Model()\n",
"model = thev.Model()\n",
"\n",
"# Fake hour-by-hour load data\n",
"time_s = 3600.*np.array([0., 1., 2., 3., 4., 5.])\n",
Expand All @@ -75,7 +75,7 @@
"# Interpolating the data\n",
"interp = lambda t: np.interp(t, time_s, current_A)\n",
"\n",
"expr = thevenin.Experiment(max_step=60.)\n",
"expr = thev.Experiment(max_step=60.)\n",
"expr.add_step('current_A', interp, (3600*6, 60.))\n",
"\n",
"soln = model.run(expr)\n",
Expand Down Expand Up @@ -120,7 +120,7 @@
],
"source": [
"# Looping over constant steps\n",
"expr = thevenin.Experiment(max_step=60.)\n",
"expr = thev.Experiment(max_step=60.)\n",
"for amps in current_A:\n",
" expr.add_step('current_A', amps, (3600, 60.))\n",
"\n",
Expand Down Expand Up @@ -167,9 +167,9 @@
],
"source": [
"# Stabilize the solver with ramped steps\n",
"demand = thevenin.loadfns.RampedSteps(time_s, current_A, 1e-3)\n",
"demand = thev.loadfns.RampedSteps(time_s, current_A, 1e-3)\n",
"\n",
"expr = thevenin.Experiment(max_step=60.)\n",
"expr = thev.Experiment(max_step=60.)\n",
"expr.add_step('current_A', demand, (3600*6, 60.))\n",
"\n",
"soln = model.run(expr)\n",
Expand Down
14 changes: 7 additions & 7 deletions docs/jupyter_execute/examples/yaml_inputs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
"metadata": {},
"outputs": [],
"source": [
"import thevenin\n",
"import numpy as np"
"import numpy as np\n",
"import thevenin as thev"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Construct a Model\n",
"The model class can be constructed using either a '.yaml' file or a dictionary that specifies all keyword arguments shown in the documentation (`help(thevenin.Model)`). A default '.yaml' file is read in when no input is provided. This is simply for convenience to help users get up and going as quickly as possible. However, you should learn how to write your own '.yaml' file or dictionary input if you would like to use this package to its fullest extent. \n",
"The model class can be constructed using either a '.yaml' file or a dictionary that specifies all keyword arguments shown in the documentation (`help(thev.Model)`). A default '.yaml' file is read in when no input is provided. This is simply for convenience to help users get up and going as quickly as possible. However, you should learn how to write your own '.yaml' file or dictionary input if you would like to use this package to its fullest extent. \n",
"\n",
"The '.yaml' format is very similar to building a dictionary in Python. Use the default 'params.yaml' file given below as a template for your own files. Note that the open circuit voltage `ocv` and circuit elements (`R0`, `R1`, and `C1`) must be input as a `Callable` with the correct inputs in the correct order, i.e., `f(soc: float) -> float` for `ocv` and `f(soc: float, T_cell: float) -> float` for all RC elements. The inputs represent the state of charge (`soc`, -) and cell temperature (`T_cell`, K). Resistor and capacitor outputs should be in Ohm and F, respectively. Since '.yaml' files do not natively support python functions, this package uses a custom `!eval` constructor to interpret functional parameters. The `!eval` constructor should be followed by a pipe `|` so that the interpreter does not get confused by the colon in the `lambda` expression. `np` expressions and basic math are also supported when using the `!eval` constructor.\n",
"\n",
Expand Down Expand Up @@ -69,7 +69,7 @@
}
],
"source": [
"model = thevenin.Model()"
"model = thev.Model()"
]
},
{
Expand All @@ -81,7 +81,7 @@
"## Build an Experiment\n",
"Experiments are built using the `Experiment` class. An experiment starts out empty and is then constructed by adding a series of current-, voltage-, or power-controlled steps. Each step requires knowing the control mode/units, the control value, a relative time span, and limiting criteria (optional). Control values can be specified as either constants or dynamic profiles with sinatures like `f(t: float) -> float` where `t` is the relative time of the new step, in seconds. The experiment below discharges at a nominal 1C rate for up to 1 hour. A limit is set such that if the voltage hits 3 V then the next step is triggered early. Afterward, the battery rests for 10 min before charging at 1C for 1 hours or until 4.3 V is reached. The remaining three steps perform a voltage hold at 4.3 V for 10 min, a constant power profile of 200 W for 1 hour or until 3.8 V is reached, and a sinusoidal voltage load for 10 min centered around 3.8 V.\n",
"\n",
"Note that the time span for each step is constructed as `(t_max: float, dt: float)` which is used to determine the time array as `tspan = np.arange(0., t_max + dt, dt)`. You can also construct a time array given `(t_max: float, Nt: int)` by using an integer instead of a float in the second position. In this case, `tspan = np.linspace(0., t_max, Nt)`. To learn more about building an experiment, including which limits are allowed and/or how to adjust solver settings on a per-step basis, see the documentation `help(thevenin.Experiment)`."
"Note that the time span for each step is constructed as `(t_max: float, dt: float)` which is used to determine the time array as `tspan = np.arange(0., t_max + dt, dt)`. You can also construct a time array given `(t_max: float, Nt: int)` by using an integer instead of a float in the second position. In this case, `tspan = np.linspace(0., t_max, Nt)`. To learn more about building an experiment, including which limits are allowed and/or how to adjust solver settings on a per-step basis, see the documentation `help(thev.Experiment)`."
]
},
{
Expand All @@ -92,7 +92,7 @@
"source": [
"dynamic_load = lambda t: 10e-3*np.sin(2.*np.pi*t / 120.) + 3.8\n",
"\n",
"expr = thevenin.Experiment(max_step=10.)\n",
"expr = thev.Experiment(max_step=10.)\n",
"expr.add_step('current_A', 75., (3600., 1.), limits=('voltage_V', 3.))\n",
"expr.add_step('current_A', 0., (600., 1.))\n",
"expr.add_step('current_A', -75., (3600., 1.), limits=('voltage_V', 4.3))\n",
Expand Down Expand Up @@ -203,7 +203,7 @@
],
"source": [
"# Stitch the step solutions together\n",
"cycle_soln = thevenin.CycleSolution(*solns)\n",
"cycle_soln = thev.CycleSolution(*solns)\n",
"cycle_soln.plot('time_h', 'voltage_V')\n",
"\n",
"# Pull steps 1--3 (inclusive)\n",
Expand Down
12 changes: 6 additions & 6 deletions docs/jupyter_execute/user_guide/basic_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
}
],
"source": [
"import thevenin\n",
"import thevenin as thev\n",
"\n",
"model = thevenin.Model()\n",
"model = thev.Model()\n",
"print(model)"
]
},
Expand Down Expand Up @@ -93,7 +93,7 @@
"metadata": {},
"outputs": [],
"source": [
"expr = thevenin.Experiment()\n",
"expr = thev.Experiment()\n",
"expr.add_step('current_A', 75., (4000., 60.), limits=('voltage_V', 3.))\n",
"expr.add_step('current_A', 0., (600., 60.))"
]
Expand Down Expand Up @@ -161,7 +161,7 @@
"output_type": "stream",
"text": [
"success = [True, True]\n",
"0.006 s\n"
"0.041 s\n"
]
}
],
Expand All @@ -187,7 +187,7 @@
"output_type": "stream",
"text": [
"CycleSolution(\n",
" solvetime=0.006 s,\n",
" solvetime=0.041 s,\n",
" success=[True, True],\n",
" status=[2, 1],\n",
" nfev=[232, 39],\n",
Expand Down Expand Up @@ -245,7 +245,7 @@
"soln_0 = soln.get_steps(0)\n",
"soln_1 = soln.get_steps(1)\n",
"\n",
"soln = thevenin.CycleSolution(soln_0, soln_1)"
"soln = thev.CycleSolution(soln_0, soln_1)"
]
}
],
Expand Down
Loading

0 comments on commit 47c3457

Please sign in to comment.