From 0eec685fec742862de9aed7ddf9e5a8289d1b928 Mon Sep 17 00:00:00 2001 From: john Date: Wed, 2 Jul 2025 11:55:09 -0400 Subject: [PATCH 1/4] Change system used in metacognition with memorize_solution --- sofai_tool/metacognition/metacognition_module.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/sofai_tool/metacognition/metacognition_module.py b/sofai_tool/metacognition/metacognition_module.py index 7c879b8..63e536d 100644 --- a/sofai_tool/metacognition/metacognition_module.py +++ b/sofai_tool/metacognition/metacognition_module.py @@ -24,11 +24,7 @@ def try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI, run_type): tested_s1 = True system1_solver.calculate_correctness(problemId) if (system1_solver.correctness >= correctness_threshold): - if run_type=='sofai': - model_of_self.memorize_solution(system1_solver,systemALL, problemId, timerSOFAI, 0) - #print(f"Solution found by System 1: {system1_solver.solution} with correctness {system1_solver.correctness}") - else: - model_of_self.memorize_solution(system1_solver,systemONE, problemId, timerSOFAI, 0) + model_of_self.memorize_solution(system1_solver,systemONE, problemId, timerSOFAI, 0) return True return False else: @@ -45,10 +41,7 @@ def try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_ system2_solver.solve(problemId,time_limit_context - (time.time() - timerSOFAI)) system2_solver.calculate_correctness(problemId) if (system2_solver.correctness >= correctness_threshold): - if run_type=='sofai': - model_of_self.memorize_solution(system2_solver,systemALL, problemId, timerSOFAI, difficulty) - else: - model_of_self.memorize_solution(system2_solver,systemTWO, problemId, timerSOFAI, difficulty) + model_of_self.memorize_solution(system2_solver,systemTWO, problemId, timerSOFAI, difficulty) return True return False else: From 7e231d2fd70b6ac889e391a0760bca6111fd266c Mon Sep 17 00:00:00 2001 From: john Date: Wed, 2 Jul 2025 12:02:49 -0400 Subject: [PATCH 2/4] Remove run_type param from try funcitons in metacognition --- .../metacognition/metacognition_module.py | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/sofai_tool/metacognition/metacognition_module.py b/sofai_tool/metacognition/metacognition_module.py index 63e536d..d43c402 100644 --- a/sofai_tool/metacognition/metacognition_module.py +++ b/sofai_tool/metacognition/metacognition_module.py @@ -18,7 +18,7 @@ tested_s1 = False tested_s2 = False -def try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI, run_type): +def try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI): global tested_s1 if not tested_s1: tested_s1 = True @@ -30,7 +30,7 @@ def try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI, run_type): else: return False -def try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,difficulty, run_type): +def try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,difficulty): global tested_s2 if not tested_s2: tested_s2 = True @@ -65,12 +65,12 @@ def metacognition(problemId, system1_solver, system2_solver, context_file, thres if run_type == "s1": timerSOFAI = time.time() system1_solver.solve(problemId) - if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI,run_type): + if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI): utilities.end_computation(problemId, timerSOFAI) return if run_type == "s2": timerSOFAI = time.time() - if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context, -1, run_type): + if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context, -1): utilities.end_computation(problemId, timerSOFAI) return @@ -92,8 +92,8 @@ def metacognition(problemId, system1_solver, system2_solver, context_file, thres M = 0 if (system1_solver.confidence * (1-M) >= T3): # print("---------------HERE 1") - if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI,run_type): - if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,-1, run_type): + if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI): + if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,-1): utilities.end_computation(problemId, timerSOFAI) return @@ -110,8 +110,8 @@ def metacognition(problemId, system1_solver, system2_solver, context_file, thres ## If we think that there is not enough time to employ System-2, we check System-1 solution even if it has low confidence value if (estimated_cost_s2 > 1): # print("---------------HERE 2") - if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI,run_type): - if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2,run_type): + if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI): + if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2): utilities.end_computation(problemId, timerSOFAI) return @@ -124,8 +124,8 @@ def metacognition(problemId, system1_solver, system2_solver, context_file, thres r_value = random.random() if (probability_s1 > r_value): # print("---------------HERE 3") - if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI,run_type): - if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2,run_type): + if not try_s1(problemId,system1_solver,correctness_threshold,timerSOFAI): + if not try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2): utilities.end_computation(problemId, timerSOFAI) return @@ -137,18 +137,18 @@ def metacognition(problemId, system1_solver, system2_solver, context_file, thres if (system1_solver.correctness >= correctness_threshold): # print("---------------HERE 4") if((1-(estimated_cost_s2 * (1-T3))) > (system1_solver.correctness*(1-M))): - if try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2,run_type): + if try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2): return #If we exit from try_s2 then no solution is found - model_of_self.memorize_solution(system1_solver,systemALL, problemId, timerSOFAI, estimated_difficulty_s2) + model_of_self.memorize_solution(system1_solver,systemONE, problemId, timerSOFAI, estimated_difficulty_s2) return ### Finally we run System-2 only if the available time is within reasonable distance w.r.t. the time we think that the System-2 is goin to take ## We arbitrary set the extra time to be 50% flexibility_perc = 50 if ((time.time() - timerSOFAI) >= (estimated_time_s2 - (float(estimated_time_s2)/100.0 * float(flexibility_perc)))): # print("---------------HERE 5") - if try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2,run_type): + if try_s2(problemId,system2_solver,correctness_threshold,timerSOFAI,time_limit_context,estimated_difficulty_s2): return utilities.end_computation(problemId, timerSOFAI) # it is going to this one at the end, means it is not going inside any if loop above!, not directly, none of the if loop conditions are getting true! From 5fe7c27c94315968c54ef29d88d0442bea16b35c Mon Sep 17 00:00:00 2001 From: john Date: Wed, 9 Jul 2025 11:58:57 -0400 Subject: [PATCH 3/4] Fixed bug where memorize_solution called createFolders with improper params --- sofai_tool/metacognition/mos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sofai_tool/metacognition/mos.py b/sofai_tool/metacognition/mos.py index a115d07..02bc0fe 100644 --- a/sofai_tool/metacognition/mos.py +++ b/sofai_tool/metacognition/mos.py @@ -55,7 +55,7 @@ def memorize_solution(solver, system, name, timerComputation, difficulty, contin try: memory_file = open(experience_file) except: - createFolders() + createFolders("experience.json", False) memory_file = open(experience_file) totalTIME = time.time()-timerComputation From e7fb8e335ff7bf31f97d158d2884077eede9e333 Mon Sep 17 00:00:00 2001 From: john Date: Wed, 9 Jul 2025 12:55:11 -0400 Subject: [PATCH 4/4] Fix Verify Installation step on README and set default correctness to 0 --- README.md | 2 +- sofai_tool/solvers/solver.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ea8903f..a119503 100755 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Follow the steps below to install the SOFAI Tool locally: 4. **Verify installation**: ```bash - python -c "import sofai; print('SOFAI Tool installed successfully!')" + python -c 'import sofai_tool; print("SOFAI Tool installed successfully!")' ``` ### Optional: Installing in Development Mode diff --git a/sofai_tool/solvers/solver.py b/sofai_tool/solvers/solver.py index 79ac962..3a4cf6d 100644 --- a/sofai_tool/solvers/solver.py +++ b/sofai_tool/solvers/solver.py @@ -1,6 +1,6 @@ class Solver: def __init__(self): - self.correctness = 0 + self.correctness = None self.confidence = None self.solution = "noSolution" self.running_time = None