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

Add script for converting code from 3 to 4. #5778

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions scripts/pymc3_to_4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

if [ -z "$1" ]
then
echo "Script to automatically convert code (*.py and *.ipynb) from PyMC3 to 4.0. Use with care."
echo "Usage: pymc3_to_4.sh <path>"
exit 1
fi

declare -a replace_strings=(
"s/az.from_pymc3/pm.to_inference_data/g"
"s/arviz.from_pymc3/pm.to_inference_data/g"
"s/pymc3/pymc/g"
"s/PyMC3/PyMC/g"
"s/from theano import tensor as tt/import aesara.tensor as at/g"
"s/import theano\.tensor as tt/import aesara.tensor as at/g"
"s/tt\./at./g"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very dangerous. It will replace any tt. with at., regardless of where in the line, tt is found. It should somehow have a lookbehind that checks if tt was not preceded by a letter, underscore or a dot. From the little I know of sed, I think that it doesn't support look around conditions (see here)

"s/aet/at/g"
"s/studenat/studentt/g"
"s/theano/aesara/g"
"s/Theano/Aesara/g"
"s/pm\.sample()/pm.sample(return_inferencedata=False)/g"
"s/, return_inferencedata\=True//g"
"s/return_inferencedata\=True, //g"
"s/return_inferencedata\=True//g"
)

for replace in "${replace_strings[@]}"; do
find $1 -name "*.ipynb" -type f -exec sed -i -e "$replace" {} \;
find $1 -name "*.py" -type f -exec sed -i -e "$replace" {} \;
done