Skip to content

Commit

Permalink
Merge pull request #263 from MilesCranmer/optional-precompilation
Browse files Browse the repository at this point in the history
Make precompilation optional
  • Loading branch information
MilesCranmer committed Feb 9, 2023
2 parents 67c22c7 + 09c365a commit e579e27
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 50 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/CI.yml
Expand Up @@ -83,7 +83,6 @@ jobs:
shell: bash -l {0}
strategy:
matrix:
julia-version: ['1.7.1']
python-version: ['3.9']
os: ['ubuntu-latest']

Expand All @@ -108,7 +107,7 @@ jobs:
- name: "Cache Julia"
uses: julia-actions/cache@v1
with:
cache-name: ${{ matrix.os }}-conda-${{ matrix.julia-version }}-${{ matrix.python-version }}
cache-name: ${{ matrix.os }}-conda-${{ matrix.python-version }}
cache-packages: false
- name: "Install PySR"
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI_Windows.yml
Expand Up @@ -29,7 +29,7 @@ jobs:
shell: bash
strategy:
matrix:
julia-version: ['1.6', '1.8.2']
julia-version: ['1.8.2']
python-version: ['3.9']
os: [windows-latest]

Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/pypi_deploy.yml
Expand Up @@ -9,12 +9,6 @@ jobs:
pypi:
runs-on: ubuntu-latest
steps:
- name: Wait for tests to pass
uses: lewagon/wait-on-check-action@v1.2.0
with:
ref: ${{ github.ref }}
check-name: 'Linux'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: "Checkout"
uses: actions/checkout@v3
- name: "Set up Python"
Expand Down
71 changes: 35 additions & 36 deletions examples/pysr_demo.ipynb
Expand Up @@ -109,11 +109,11 @@
"source": [
"from julia import Julia\n",
"\n",
"julia = Julia(compiled_modules=False, threads='auto', optimize=3)\n",
"julia = Julia(compiled_modules=False, threads='auto')\n",
"from julia import Main\n",
"from julia.tools import redirect_output_streams\n",
"\n",
"redirect_output_streams()\n"
"redirect_output_streams()"
]
},
{
Expand All @@ -137,7 +137,8 @@
"source": [
"import pysr\n",
"\n",
"pysr.install()\n"
"# We don't precompile in colab because compiled modules are incompatible static Python libraries:\n",
"pysr.install(precompile=False)"
]
},
{
Expand All @@ -157,7 +158,7 @@
"from torch.nn import functional as F\n",
"from torch.utils.data import DataLoader, TensorDataset\n",
"import pytorch_lightning as pl\n",
"from sklearn.model_selection import train_test_split\n"
"from sklearn.model_selection import train_test_split"
]
},
{
Expand Down Expand Up @@ -191,7 +192,7 @@
"# Dataset\n",
"np.random.seed(0)\n",
"X = 2 * np.random.randn(100, 5)\n",
"y = 2.5382 * np.cos(X[:, 3]) + X[:, 0] ** 2 - 2\n"
"y = 2.5382 * np.cos(X[:, 3]) + X[:, 0] ** 2 - 2"
]
},
{
Expand All @@ -215,7 +216,7 @@
" populations=30,\n",
" procs=4,\n",
" model_selection=\"best\",\n",
")\n"
")"
]
},
{
Expand Down Expand Up @@ -246,7 +247,7 @@
" **default_pysr_params\n",
")\n",
"\n",
"model.fit(X, y)\n"
"model.fit(X, y)"
]
},
{
Expand All @@ -266,7 +267,7 @@
},
"outputs": [],
"source": [
"model\n"
"model"
]
},
{
Expand All @@ -286,7 +287,7 @@
},
"outputs": [],
"source": [
"model.sympy()\n"
"model.sympy()"
]
},
{
Expand All @@ -306,7 +307,7 @@
},
"outputs": [],
"source": [
"model.sympy(2)\n"
"model.sympy(2)"
]
},
{
Expand Down Expand Up @@ -335,7 +336,7 @@
},
"outputs": [],
"source": [
"model.latex()\n"
"model.latex()"
]
},
{
Expand All @@ -361,7 +362,7 @@
"ypredict_simpler = model.predict(X, 2)\n",
"\n",
"print(\"Default selection MSE:\", np.power(ypredict - y, 2).mean())\n",
"print(\"Manual selection MSE for index 2:\", np.power(ypredict_simpler - y, 2).mean())\n"
"print(\"Manual selection MSE for index 2:\", np.power(ypredict_simpler - y, 2).mean())"
]
},
{
Expand Down Expand Up @@ -395,7 +396,7 @@
},
"outputs": [],
"source": [
"y = X[:, 0] ** 4 - 2\n"
"y = X[:, 0] ** 4 - 2"
]
},
{
Expand Down Expand Up @@ -425,7 +426,7 @@
" unary_operators=[\"cos\", \"exp\", \"sin\", \"quart(x) = x^4\"],\n",
" extra_sympy_mappings={\"quart\": lambda x: x**4},\n",
")\n",
"model.fit(X, y)\n"
"model.fit(X, y)"
]
},
{
Expand All @@ -436,7 +437,7 @@
},
"outputs": [],
"source": [
"model.sympy()\n"
"model.sympy()"
]
},
{
Expand Down Expand Up @@ -538,7 +539,7 @@
"X = 2 * np.random.rand(N, 5)\n",
"sigma = np.random.rand(N) * (5 - 0.1) + 0.1\n",
"eps = sigma * np.random.randn(N)\n",
"y = 5 * np.cos(3.5 * X[:, 0]) - 1.3 + eps\n"
"y = 5 * np.cos(3.5 * X[:, 0]) - 1.3 + eps"
]
},
{
Expand All @@ -560,7 +561,7 @@
"source": [
"plt.scatter(X[:, 0], y, alpha=0.2)\n",
"plt.xlabel(\"$x_0$\")\n",
"plt.ylabel(\"$y$\")\n"
"plt.ylabel(\"$y$\")"
]
},
{
Expand All @@ -580,7 +581,7 @@
},
"outputs": [],
"source": [
"weights = 1 / sigma ** 2\n"
"weights = 1 / sigma ** 2"
]
},
{
Expand All @@ -591,7 +592,7 @@
},
"outputs": [],
"source": [
"weights[:5]\n"
"weights[:5]"
]
},
{
Expand Down Expand Up @@ -619,7 +620,7 @@
" binary_operators=[\"plus\", \"mult\"],\n",
" unary_operators=[\"cos\"],\n",
")\n",
"model.fit(X, y, weights=weights)\n"
"model.fit(X, y, weights=weights)"
]
},
{
Expand All @@ -639,7 +640,7 @@
},
"outputs": [],
"source": [
"model\n"
"model"
]
},
{
Expand All @@ -662,7 +663,7 @@
"best_idx = model.equations_.query(\n",
" f\"loss < {2 * model.equations_.loss.min()}\"\n",
").score.idxmax()\n",
"model.sympy(best_idx)\n"
"model.sympy(best_idx)"
]
},
{
Expand Down Expand Up @@ -693,7 +694,7 @@
"source": [
"plt.scatter(X[:, 0], y, alpha=0.1)\n",
"y_prediction = model.predict(X, index=best_idx)\n",
"plt.scatter(X[:, 0], y_prediction)\n"
"plt.scatter(X[:, 0], y_prediction)"
]
},
{
Expand All @@ -719,7 +720,7 @@
"outputs": [],
"source": [
"X = 2 * np.random.randn(100, 5)\n",
"y = 1 / X[:, [0, 1, 2]]\n"
"y = 1 / X[:, [0, 1, 2]]"
]
},
{
Expand Down Expand Up @@ -1024,7 +1025,7 @@
"y_i = X[..., 0] ** 2 + 6 * np.cos(2 * X[..., 2])\n",
"y = np.sum(y_i, axis=1) / y_i.shape[1]\n",
"z = y**2\n",
"X.shape, y.shape\n"
"X.shape, y.shape"
]
},
{
Expand Down Expand Up @@ -1117,7 +1118,7 @@
" ),\n",
" \"interval\": \"step\",\n",
" }\n",
" return [optimizer], [scheduler]\n"
" return [optimizer], [scheduler]"
]
},
{
Expand Down Expand Up @@ -1152,7 +1153,7 @@
"train_set = TensorDataset(X_train, z_train)\n",
"train = DataLoader(train_set, batch_size=128, num_workers=2)\n",
"test_set = TensorDataset(X_test, z_test)\n",
"test = DataLoader(test_set, batch_size=256, num_workers=2)\n"
"test = DataLoader(test_set, batch_size=256, num_workers=2)"
]
},
{
Expand Down Expand Up @@ -1184,7 +1185,7 @@
"pl.seed_everything(0)\n",
"model = SumNet()\n",
"model.total_steps = total_steps\n",
"model.max_lr = 1e-2\n"
"model.max_lr = 1e-2"
]
},
{
Expand All @@ -1204,7 +1205,7 @@
},
"outputs": [],
"source": [
"trainer = pl.Trainer(max_steps=total_steps, gpus=1, benchmark=True)\n"
"trainer = pl.Trainer(max_steps=total_steps, gpus=1, benchmark=True)"
]
},
{
Expand All @@ -1224,7 +1225,7 @@
},
"outputs": [],
"source": [
"trainer.fit(model, train_dataloaders=train, val_dataloaders=test)\n"
"trainer.fit(model, train_dataloaders=train, val_dataloaders=test)"
]
},
{
Expand Down Expand Up @@ -1254,7 +1255,7 @@
"y_for_pysr = torch.sum(y_i_for_pysr, dim=1) / y_i_for_pysr.shape[1]\n",
"z_for_pysr = zt[idx] # Use true values.\n",
"\n",
"X_for_pysr.shape, y_i_for_pysr.shape\n"
"X_for_pysr.shape, y_i_for_pysr.shape"
]
},
{
Expand Down Expand Up @@ -1287,7 +1288,7 @@
" binary_operators=[\"plus\", \"sub\", \"mult\"],\n",
" unary_operators=[\"cos\", \"square\", \"neg\"],\n",
")\n",
"model.fit(X=tmpX[idx2], y=tmpy[idx2])\n"
"model.fit(X=tmpX[idx2], y=tmpy[idx2])"
]
},
{
Expand Down Expand Up @@ -1319,7 +1320,7 @@
},
"outputs": [],
"source": [
"model\n"
"model"
]
},
{
Expand Down Expand Up @@ -1375,9 +1376,7 @@
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "Python (main_ipynb)",
"language": "python",
"name": "main_ipynb"
"language": "python"
},
"language_info": {
"name": "python",
Expand Down

0 comments on commit e579e27

Please sign in to comment.