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

{test} Update code generation tests #412

Merged
merged 1 commit into from
Feb 1, 2024
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
10 changes: 6 additions & 4 deletions framework/ccm_pyactr/testdata/empty.py.golden
Original file line number Diff line number Diff line change
@@ -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

Expand Down
19 changes: 14 additions & 5 deletions framework/ccm_pyactr/testdata/semantic.py.golden
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
# 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()
goal = Buffer()

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')
Expand Down
22 changes: 15 additions & 7 deletions framework/pyactr/testdata/empty.py.golden
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()))
49 changes: 22 additions & 27 deletions framework/pyactr/testdata/semantic.py.golden
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,28 +16,19 @@ 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')
# amod line 29
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='''
Expand Down Expand Up @@ -121,8 +114,8 @@ pyactr_semantic.productionstring(name='directVerify', string='''
=goal>
isa isMember
judgment "yes"
!goal>
print_text "'Yes'"
!print>
text "'Yes'"
~goal>
''')

Expand Down Expand Up @@ -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()))
6 changes: 3 additions & 3 deletions framework/testdata/semantic.amod
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 *]
Expand Down Expand Up @@ -88,7 +88,7 @@ chainCategory {
fail {
match {
goal [isMember: * * 'pending']
retrieval module error
module_state memory error
}
do {
set goal.judgment to 'no'
Expand Down
14 changes: 7 additions & 7 deletions framework/vanilla_actr/testdata/semantic.lisp.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -143,7 +143,7 @@
isa isMember
judgment "pending"
?retrieval>
state error
state error
==>
=goal>
isa isMember
Expand Down
6 changes: 6 additions & 0 deletions util/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading