summaryrefslogtreecommitdiff
path: root/modeling/test_compile.py
diff options
context:
space:
mode:
authorNiclas Dobbertin <niclas.dobbertin@mailbox.org>2024-09-05 20:23:08 +0200
committerNiclas Dobbertin <niclas.dobbertin@mailbox.org>2024-09-05 20:23:08 +0200
commitbf2f74d43a02ef01c794292bf10fa5e5652447f4 (patch)
treef364d889c4d97b406aaeb67b040439ce1d4f27eb /modeling/test_compile.py
parentbfbf4f384c39aa42aa5e0d4ddd31f074447ed41f (diff)
test prod compile
Diffstat (limited to 'modeling/test_compile.py')
-rw-r--r--modeling/test_compile.py122
1 files changed, 122 insertions, 0 deletions
diff --git a/modeling/test_compile.py b/modeling/test_compile.py
new file mode 100644
index 0000000..b1e825f
--- /dev/null
+++ b/modeling/test_compile.py
@@ -0,0 +1,122 @@
+#!/usr/bin/env python3
+
+import pyactr as actr
+import prod_numbers
+
+Model = actr.ACTRModel()
+DM = Model.decmem
+goal = Model.goal
+imaginal = Model.set_goal(name="imaginal", delay=0.2)
+
+_ = prod_numbers.number(Model)
+
+def get_digit(number, n):
+ return number // 10**n % 10
+
+actr.chunktype("number", ("number", "next", "ones", "tens", "hundreds"))
+actr.chunktype(
+ "math_goal",
+ (
+ "task",
+ "result1",
+ "result2",
+ "op",
+ "nextop",
+ "nextnextop",
+ "arg1",
+ "arg1_idx",
+ "arg2",
+ "arg2_idx",
+ "result",
+ "expand_slot",
+ "hundreds1",
+ "tens1",
+ "ones1",
+ "hundreds2",
+ "tens2",
+ "ones2",
+ ),
+)
+actr.chunktype(
+ "math_op",
+ (
+ "op",
+ "arg1",
+ "arg2",
+ "result",
+ ),
+)
+
+# Add numbers 0-999 to decmem
+for i in range(0, 1000):
+ DM.add(
+ actr.makechunk(
+ f"number{str(i)}",
+ "number",
+ number=i,
+ next=i + 1,
+ ones=get_digit(i, 0),
+ tens=get_digit(i, 1),
+ hundreds=get_digit(i, 2),
+ )
+ )
+
+
+Model.productionstring(
+ name="continue_with_next_op",
+ string="""
+ =g>
+ isa math_goal
+ op done
+ nextop ~None
+ nextop =nextop
+ nextnextop =nextnextop
+ ==>
+ =g>
+ isa math_goal
+ op =nextop
+ nextop =nextnextop
+ nextnextop None
+ """,
+)
+
+Model.productionstring(
+ name="reset",
+ string="""
+ =g>
+ isa math_goal
+ op reset
+ ==>
+ =g>
+ isa math_goal
+ op expand
+ nextop reset
+ """
+)
+
+goal.add(
+ actr.makechunk(
+ "",
+ "math_goal",
+ op="expand",
+ nextop="reset",
+ expand_slot=None,
+ ones1=1,
+ tens1=2,
+ hundreds1=3,
+ ones2=4,
+ tens2=5,
+ hundreds2=6,
+ )
+)
+Model.model_parameters["activation_trace"] = True
+Model.model_parameters["instantaneous_noise"] = .2
+Model.model_parameters["utility_alpha"] = 0.5
+Model.model_parameters["utility_noise"] = 0.5
+Model.model_parameters["production_compilation"] = True
+Model.model_parameters["utility_learning"] = True
+
+sim = Model.simulation(
+ gui=False,
+)
+sim.run(max_time=2)