Skip to content

Commit b6e73c7

Browse files
committed
add run_notebooks script + fix Jupyter notebook errors
1 parent 52db752 commit b6e73c7

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

.github/workflows/install_examples.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
conda install pip pytest
2323
2424
# Install python-control dependencies
25-
conda install numpy matplotlib scipy
25+
conda install numpy matplotlib scipy jupyter
2626
conda install -c conda-forge slycot pmw
2727
2828
- name: Install with setup.py
@@ -32,3 +32,4 @@ jobs:
3232
run: |
3333
cd examples
3434
./run_examples.sh
35+
./run_notebooks.sh

examples/bode-and-nyquist-plots.ipynb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"metadata": {},
77
"outputs": [],
88
"source": [
9-
"import seaborn as sns\n",
109
"import scipy as sp\n",
1110
"import matplotlib.pyplot as plt\n",
1211
"import control as ct"
@@ -10025,9 +10024,9 @@
1002510024
],
1002610025
"metadata": {
1002710026
"kernelspec": {
10028-
"display_name": "Python (pctest)",
10027+
"display_name": "Python 3",
1002910028
"language": "python",
10030-
"name": "pctest"
10029+
"name": "python3"
1003110030
},
1003210031
"language_info": {
1003310032
"codemirror_mode": {

examples/run_notebooks.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# run_notbooks.sh - run Jupyter notebooks
3+
# RMM, 26 Jan 2021
4+
#
5+
# This script runs all of the Jupyter notebooks to make sure that there
6+
# are no errors.
7+
8+
# Keep track of files that generate errors
9+
notebook_errors=""
10+
11+
# Go through each Jupyter notebook
12+
for example in *.ipynb; do
13+
echo "Running ${example}"
14+
if ! jupyter nbconvert --to notebook --execute ${example}; then
15+
notebook_errors="${notebook_errors} ${example}"
16+
fi
17+
done
18+
19+
# Get rid of the output files
20+
rm *.nbconvert.ipynb
21+
22+
# List any files that generated errors
23+
if [ -n "${notebook_errors}" ]; then
24+
echo These examples had errors:
25+
echo "${notebook_errors}"
26+
exit 1
27+
else
28+
echo All examples ran successfully
29+
fi

examples/steering.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@
312312
" clsys = ct.StateSpace(A - B @ K, B, lateral_normalized.C, 0)\n",
313313
" \n",
314314
" # Compute the feedforward gain based on the zero frequency gain of the closed loop\n",
315-
" kf = np.real(1/clsys.evalfr(0))\n",
315+
" kf = np.real(1/clsys(0))\n",
316316
"\n",
317317
" # Scale the input by the feedforward gain\n",
318318
" clsys *= kf\n",
@@ -488,7 +488,7 @@
488488
"tau = v0 * T_curvy / b\n",
489489
"\n",
490490
"# Simulate the estimator, with a small initial error in y position\n",
491-
"t, y_est, x_est = ct.forced_response(est, tau, [delta_curvy, y_ref], [0.5, 0])\n",
491+
"t, y_est, x_est = ct.forced_response(est, tau, [delta_curvy, y_ref], [0.5, 0], return_x=True)\n",
492492
"\n",
493493
"# Configure matplotlib plots to be a bit bigger and optimize layout\n",
494494
"plt.figure(figsize=[9, 4.5])\n",
@@ -596,7 +596,7 @@
596596
" np.zeros((2,1)))\n",
597597
"\n",
598598
"# Simulate the system\n",
599-
"t, y, x = ct.forced_response(clsys, tau, y_ref, [0.4, 0, 0.0, 0])\n",
599+
"t, y, x = ct.forced_response(clsys, tau, y_ref, [0.4, 0, 0.0, 0], return_x=True)\n",
600600
"\n",
601601
"# Calcaluate the input used to generate the control response\n",
602602
"u_sfb = kf * y_ref - K @ x[0:2]\n",
@@ -1081,7 +1081,7 @@
10811081
"zc = 0.707\n",
10821082
"eigs = np.roots([1, 2*zc*wc, wc**2])\n",
10831083
"K = ct.place(A, B, eigs)\n",
1084-
"kr = np.real(1/clsys.evalfr(0))\n",
1084+
"kr = np.real(1/clsys(0))\n",
10851085
"print(\"K = \", np.squeeze(K))\n",
10861086
"\n",
10871087
"# Compute the estimator gain using eigenvalue placement\n",
@@ -1126,7 +1126,7 @@
11261126
"zc = 2.6\n",
11271127
"eigs = np.roots([1, 2*zc*wc, wc**2])\n",
11281128
"K = ct.place(A, B, eigs)\n",
1129-
"kr = np.real(1/clsys.evalfr(0))\n",
1129+
"kr = np.real(1/clsys(0))\n",
11301130
"print(\"K = \", np.squeeze(K))\n",
11311131
"\n",
11321132
"# Construct an output-based controller for the system\n",

0 commit comments

Comments
 (0)