From 910ca1fe77cc2416f48a3108488ca97306c97cfa Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Thu, 1 Feb 2024 14:15:19 -0500 Subject: [PATCH] {test} Update code generation test (#412) --- framework/ccm_pyactr/testdata/empty.py.golden | 10 ++-- .../ccm_pyactr/testdata/semantic.py.golden | 19 +++++-- framework/pyactr/testdata/empty.py.golden | 22 ++++++--- framework/pyactr/testdata/semantic.py.golden | 49 +++++++++---------- framework/testdata/semantic.amod | 6 +-- .../testdata/semantic.lisp.golden | 14 +++--- util/cli/cli.go | 6 +++ 7 files changed, 73 insertions(+), 53 deletions(-) diff --git a/framework/ccm_pyactr/testdata/empty.py.golden b/framework/ccm_pyactr/testdata/empty.py.golden index 0025f94d..386ad24c 100644 --- a/framework/ccm_pyactr/testdata/empty.py.golden +++ b/framework/ccm_pyactr/testdata/empty.py.golden @@ -1,8 +1,10 @@ -# Generated by gactar test -# on 0001-01-01 @ 00:00:00 -# https://github.com/asmaloney/gactar +""" +Generated by gactar test + https://github.com/asmaloney/gactar + on 0001-01-01 @ 00:00:00 -# *** NOTE: This is a generated file. Any changes may be overwritten. +NOTE: This is a generated file. Any changes may be overwritten. +""" from python_actr import ACTR, Buffer, Memory diff --git a/framework/ccm_pyactr/testdata/semantic.py.golden b/framework/ccm_pyactr/testdata/semantic.py.golden index 176f0ee0..b8e196dd 100644 --- a/framework/ccm_pyactr/testdata/semantic.py.golden +++ b/framework/ccm_pyactr/testdata/semantic.py.golden @@ -1,14 +1,18 @@ -# Generated by gactar test -# on 0001-01-01 @ 00:00:00 -# https://github.com/asmaloney/gactar +""" +This model is based on the ccm u1_semantic.py tutorial. -# *** NOTE: This is a generated file. Any changes may be overwritten. +Generated by gactar test + https://github.com/asmaloney/gactar + on 0001-01-01 @ 00:00:00 -# This model is based on the ccm u1_semantic.py tutorial. +NOTE: This is a generated file. Any changes may be overwritten. +""" from python_actr import ACTR, Buffer, Memory from python_actr import log, log_everything +from ccm_print import CCMPrint + class ccm_semantic(ACTR): retrieval = Buffer() @@ -16,6 +20,11 @@ class ccm_semantic(ACTR): memory = Memory(retrieval) + # create a printer helper and register chunks with their slots for lookup + printer = CCMPrint() + printer.register_chunk("isMember", ["object", "category", "judgment"]) + printer.register_chunk("property", ["object", "attribute", "value"]) + def init(): # amod line 36 memory.add('property shark dangerous true') diff --git a/framework/pyactr/testdata/empty.py.golden b/framework/pyactr/testdata/empty.py.golden index 686ba956..aa282783 100644 --- a/framework/pyactr/testdata/empty.py.golden +++ b/framework/pyactr/testdata/empty.py.golden @@ -1,8 +1,10 @@ -# Generated by gactar test -# on 0001-01-01 @ 00:00:00 -# https://github.com/asmaloney/gactar +""" +Generated by gactar test + https://github.com/asmaloney/gactar + on 0001-01-01 @ 00:00:00 -# *** NOTE: This is a generated file. Any changes may be overwritten. +NOTE: This is a generated file. Any changes may be overwritten. +""" import pyactr as actr @@ -12,13 +14,19 @@ pyactr_Empty = actr.ACTRModel( memory = pyactr_Empty.decmem + +# finst defaults to 0 in pyactr, so set it to 4 which is the default in ACT-R +pyactr_Empty.retrieval.finst = 4 + goal = pyactr_Empty.set_goal('goal') # Main if __name__ == '__main__': - sim = pyactr_Empty.simulation() + sim = pyactr_Empty.simulation( gui=False ) sim.run() - if goal.test_buffer('full') is True: - print('final goal: ' + str(goal.pop())) + if goal.test_buffer('full'): + print('chunk left in goal: ' + str(goal.pop())) + if pyactr_Empty.retrieval.test_buffer('full'): + print('chunk left in retrieval: ' + str(pyactr_Empty.retrieval.pop())) diff --git a/framework/pyactr/testdata/semantic.py.golden b/framework/pyactr/testdata/semantic.py.golden index 672c4fae..716a8f07 100644 --- a/framework/pyactr/testdata/semantic.py.golden +++ b/framework/pyactr/testdata/semantic.py.golden @@ -1,10 +1,12 @@ -# Generated by gactar test -# on 0001-01-01 @ 00:00:00 -# https://github.com/asmaloney/gactar +""" +This model is based on the ccm u1_semantic.py tutorial. -# *** NOTE: This is a generated file. Any changes may be overwritten. +Generated by gactar test + https://github.com/asmaloney/gactar + on 0001-01-01 @ 00:00:00 -# This model is based on the ccm u1_semantic.py tutorial. +NOTE: This is a generated file. Any changes may be overwritten. +""" import pyactr as actr import pyactr_print @@ -14,7 +16,7 @@ pyactr_semantic = actr.ACTRModel( ) # pyactr doesn't handle general printing, so use gactar to add this capability -pyactr_print.set_model(pyactr_semantic) +pyactr_print.PrintBuffer(pyactr_semantic) # amod line 28 actr.chunktype('isMember', 'object, category, judgment') @@ -22,20 +24,11 @@ actr.chunktype('isMember', 'object, category, judgment') actr.chunktype('property', 'object, attribute, value') memory = pyactr_semantic.decmem -goal = pyactr_semantic.set_goal('goal') -# declare implicit chunks to avoid warnings -actr.chunktype('chunk', 'value') -actr.makechunk(nameofchunk='animal', typename='chunk', value='animal') -actr.makechunk(nameofchunk='bird', typename='chunk', value='bird') -actr.makechunk(nameofchunk='canary', typename='chunk', value='canary') -actr.makechunk(nameofchunk='category', typename='chunk', value='category') -actr.makechunk(nameofchunk='dangerous', typename='chunk', value='dangerous') -actr.makechunk(nameofchunk='fish', typename='chunk', value='fish') -actr.makechunk(nameofchunk='locomotion', typename='chunk', value='locomotion') -actr.makechunk(nameofchunk='shark', typename='chunk', value='shark') -actr.makechunk(nameofchunk='swimming', typename='chunk', value='swimming') -actr.makechunk(nameofchunk='true', typename='chunk', value='true') +# finst defaults to 0 in pyactr, so set it to 4 which is the default in ACT-R +pyactr_semantic.retrieval.finst = 4 + +goal = pyactr_semantic.set_goal('goal') # amod line 36 memory.add(actr.chunkstring(string=''' @@ -121,8 +114,8 @@ pyactr_semantic.productionstring(name='directVerify', string=''' =goal> isa isMember judgment "yes" - !goal> - print_text "'Yes'" + !print> + text "'Yes'" ~goal> ''') @@ -156,20 +149,22 @@ pyactr_semantic.productionstring(name='fail', string=''' isa isMember judgment "pending" ?retrieval> - state error + state error ==> =goal> isa isMember judgment "no" - !goal> - print_text "'No'" + !print> + text "'No'" ~goal> ''') # Main if __name__ == '__main__': - sim = pyactr_semantic.simulation() + sim = pyactr_semantic.simulation( gui=False ) sim.run() - if goal.test_buffer('full') is True: - print('final goal: ' + str(goal.pop())) + if goal.test_buffer('full'): + print('chunk left in goal: ' + str(goal.pop())) + if pyactr_semantic.retrieval.test_buffer('full'): + print('chunk left in retrieval: ' + str(pyactr_semantic.retrieval.pop())) diff --git a/framework/testdata/semantic.amod b/framework/testdata/semantic.amod index 68061a97..994381f5 100644 --- a/framework/testdata/semantic.amod +++ b/framework/testdata/semantic.amod @@ -23,7 +23,7 @@ gactar { trace_activations: false } -// Declare chunks and their layouts +// Declare chunk types and their layouts chunks { [isMember: object category judgment] [property: object attribute value] @@ -55,7 +55,7 @@ initialRetrieval { match { goal [isMember: ?obj * nil] } - // Steps to execute + // Statements to execute do { set goal.judgment to 'pending' recall [property: ?obj category *] @@ -88,7 +88,7 @@ chainCategory { fail { match { goal [isMember: * * 'pending'] - retrieval module error + module_state memory error } do { set goal.judgment to 'no' diff --git a/framework/vanilla_actr/testdata/semantic.lisp.golden b/framework/vanilla_actr/testdata/semantic.lisp.golden index abf367a5..6007d3f1 100644 --- a/framework/vanilla_actr/testdata/semantic.lisp.golden +++ b/framework/vanilla_actr/testdata/semantic.lisp.golden @@ -27,42 +27,42 @@ (swimming) (true) ;; amod line 36 - (fact_0 + (property_0 isa property object shark attribute dangerous value true ) ;; amod line 37 - (fact_1 + (property_1 isa property object shark attribute locomotion value swimming ) ;; amod line 38 - (fact_2 + (property_2 isa property object shark attribute category value fish ) ;; amod line 39 - (fact_3 + (property_3 isa property object fish attribute category value animal ) ;; amod line 40 - (fact_4 + (property_4 isa property object bird attribute category value animal ) ;; amod line 41 - (fact_5 + (property_5 isa property object canary attribute category @@ -143,7 +143,7 @@ isa isMember judgment "pending" ?retrieval> - state error + state error ==> =goal> isa isMember diff --git a/util/cli/cli.go b/util/cli/cli.go index eba8bb99..2f9ea525 100644 --- a/util/cli/cli.go +++ b/util/cli/cli.go @@ -50,6 +50,12 @@ func SetupPaths(envPath string) (err error) { return } + // Skip if we have already set up with this env + currentVirtEnv := os.Getenv("VIRTUAL_ENV") + if currentVirtEnv == envPath { + return nil + } + pythonVENVPath := "bin" // Python on Windows puts itself in a different place, so adjust our path accordingly