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

Grammar usage and import #77

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions docs/code/Alhazen.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ def task_sqrt(x):
from math import cos as rcos
from math import sin as rsin

from numpy import nanmax, isnan

if __name__ == '__main__':
"""
This file contains the code under test for the example bug.
Expand Down Expand Up @@ -1645,11 +1647,11 @@ def get_all_input_specifications(dec_tree,
import random
from itertools import chain

def best_trees(forest, spec):
def best_trees(forest, spec, grammar):
samples = [tree_to_string(tree) for tree in forest]
fulfilled_fractions= []
for sample in samples:
gen_features = collect_features([sample], CALC_GRAMMAR)
gen_features = collect_features([sample], grammar)

# calculate percentage of fulfilled requirements (used to rank the sample)
fulfilled_count = 0
Expand Down Expand Up @@ -1716,7 +1718,7 @@ def generate_samples_advanced(grammar: Grammar,
done = False
starttime = time.time()
best_chosen = [fuzzer.fuzz_tree() for _ in range(100)]
done, best_chosen = best_trees(best_chosen, spec)
done, best_chosen = best_trees(best_chosen, spec, grammar)
if done:
final_samples.append(tree_to_string(best_chosen))

Expand Down Expand Up @@ -1756,7 +1758,7 @@ def generate_samples_advanced(grammar: Grammar,
curr = s[0]
except SyntaxError:
pass
done, best_chosen = best_trees(best_chosen, spec)
done, best_chosen = best_trees(best_chosen, spec, grammar)
if done:
final_samples.append(tree_to_string(best_chosen))
if not done:
Expand All @@ -1773,6 +1775,8 @@ def generate_samples_random(grammar, new_input_specifications, num):

return data

generate_samples = generate_samples_advanced

if __name__ == '__main__':
generate_samples = generate_samples_advanced

Expand Down
8 changes: 4 additions & 4 deletions notebooks/Alhazen.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2745,11 +2745,11 @@
"metadata": {},
"outputs": [],
"source": [
"def best_trees(forest, spec):\n",
"def best_trees(forest, spec, grammar):\n",
" samples = [tree_to_string(tree) for tree in forest]\n",
" fulfilled_fractions= []\n",
" for sample in samples:\n",
" gen_features = collect_features([sample], CALC_GRAMMAR)\n",
" gen_features = collect_features([sample], grammar)\n",
"\n",
" # calculate percentage of fulfilled requirements (used to rank the sample)\n",
" fulfilled_count = 0\n",
Expand Down Expand Up @@ -2823,7 +2823,7 @@
" done = False\n",
" starttime = time.time()\n",
" best_chosen = [fuzzer.fuzz_tree() for _ in range(100)]\n",
" done, best_chosen = best_trees(best_chosen, spec)\n",
" done, best_chosen = best_trees(best_chosen, spec, grammar)\n",
" if done:\n",
" final_samples.append(tree_to_string(best_chosen))\n",
"\n",
Expand Down Expand Up @@ -2863,7 +2863,7 @@
" curr = s[0]\n",
" except SyntaxError:\n",
" pass\n",
" done, best_chosen = best_trees(best_chosen, spec)\n",
" done, best_chosen = best_trees(best_chosen, spec, grammar)\n",
" if done:\n",
" final_samples.append(tree_to_string(best_chosen))\n",
" if not done:\n",
Expand Down
Loading