Skip to content

Commit

Permalink
Fix: Place imports in individual cells (for export to .py files)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-zeller committed Jan 7, 2025
1 parent fce394b commit 5ca3842
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 209 deletions.
126 changes: 102 additions & 24 deletions notebooks/Alhazen.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,17 @@
"The calculator code is listed below."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from math import tan as rtan\n",
"from math import cos as rcos\n",
"from math import sin as rsin"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -245,11 +256,6 @@
"This file contains the code under test for the example bug.\n",
"The sqrt() method fails on x <= 0.\n",
"\"\"\"\n",
"from math import tan as rtan\n",
"from math import cos as rcos\n",
"from math import sin as rsin\n",
"\n",
"\n",
"def task_sqrt(x):\n",
" \"\"\"Computes the square root of x, using the Newton-Raphson method\"\"\"\n",
" if x <= -12 and x >= -42:\n",
Expand Down Expand Up @@ -383,8 +389,15 @@
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"\n",
"import sys"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SUBJECT = \"calculator\"\n",
"\n",
"def sample_runner(sample):\n",
Expand Down Expand Up @@ -685,8 +698,15 @@
"metadata": {},
"outputs": [],
"source": [
"from abc import ABC, abstractmethod\n",
"\n",
"from abc import ABC, abstractmethod"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Feature(ABC):\n",
" '''\n",
" The abstract base class for grammar features.\n",
Expand Down Expand Up @@ -795,8 +815,15 @@
"metadata": {},
"outputs": [],
"source": [
"from numpy import nanmax, isnan\n",
"\n",
"from numpy import nanmax, isnan"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class NumericInterpretation(Feature):\n",
" '''\n",
" This class represents numeric interpretation features of a grammar. These features\n",
Expand Down Expand Up @@ -882,8 +909,15 @@
"outputs": [],
"source": [
"from collections import defaultdict\n",
"import re\n",
"\n",
"import re"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Regex for non-terminal symbols in expansions\n",
"RE_NONTERMINAL = re.compile(r'(<[^<> ]*>)')\n",
"\n",
Expand Down Expand Up @@ -1099,8 +1133,15 @@
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"\n",
"import random"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# For this example, fix the random seed so that the produced output is deterministic\n",
"random.seed(24)\n",
"f = GrammarFuzzer(EXPR_GRAMMAR, max_nonterminals=3)\n",
Expand Down Expand Up @@ -1175,8 +1216,15 @@
"metadata": {},
"outputs": [],
"source": [
"import copy\n",
"\n",
"import copy"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def transform_grammar(sample: str,\n",
" grammar: Grammar) -> Grammar:\n",
" # copy of the grammar\n",
Expand Down Expand Up @@ -1403,8 +1451,15 @@
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"\n",
"import math"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def friendly_decision_tree(clf, feature_names,\n",
" class_names = ['NO_BUG', 'BUG'],\n",
" indent=0):\n",
Expand Down Expand Up @@ -1996,8 +2051,15 @@
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"from pathlib import Path"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class TreePath:\n",
" def __init__(self, samplefile: Optional[Path], is_bug: bool, requirements: List[TreeRequirement]):\n",
" self.__sample = samplefile\n",
Expand Down Expand Up @@ -2271,8 +2333,15 @@
"metadata": {},
"outputs": [],
"source": [
"import string\n",
"\n",
"import string"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SPEC_GRAMMAR: Grammar = {\n",
" \"<start>\":\n",
" [\"<req_list>\"],\n",
Expand Down Expand Up @@ -3218,7 +3287,16 @@
"metadata": {},
"outputs": [],
"source": [
"import inspect\n",
"import inspect"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"print(inspect.getsource(task_sqrt))"
]
},
Expand Down
Binary file modified notebooks/PICS/Alhazen-synopsis-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5ca3842

Please sign in to comment.