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

Bug in LLVM mode when executing LCA on multiple trials #3164

Open
jongkeesbj opened this issue Jan 20, 2025 · 2 comments
Open

Bug in LLVM mode when executing LCA on multiple trials #3164

jongkeesbj opened this issue Jan 20, 2025 · 2 comments

Comments

@jongkeesbj
Copy link
Collaborator

The following two calls to run, once in Python mode and once in LLVM mode, do not provide the same results on the second trial.

import psyneulink as pnl

my_lca = pnl.LCAMechanism(
    termination_measure=pnl.TimeScale.TRIAL,
    termination_threshold=2,
    execute_until_finished=True
)

comp = pnl.Composition()
comp.add_node(my_lca)

comp.run([[1], [1]], execution_mode=pnl.ExecutionMode.Python)
print(comp.results)

comp.reset(clear_results=True)

comp.run([[1], [1]], execution_mode=pnl.ExecutionMode.LLVM)
print(comp.results)
@jongkeesbj
Copy link
Collaborator Author

To start excluding possible reasons for the discrepancy between python and llvm mode, I first set up my test to have completely separate mechanisms and compositions run in each mode. This is to make sure that the bug is not related to resetting the composition between runs. However, the discrepancy remains even when running it this way.

import psyneulink as pnl

lca_python = pnl.LCAMechanism(
    termination_measure=pnl.TimeScale.TRIAL,
    termination_threshold=2,
    execute_until_finished=True
)

comp_python = pnl.Composition()
comp_python.add_node(lca_python)

print("Python: ")
comp_python.run([[1], [1]], execution_mode=pnl.ExecutionMode.Python)
print(comp_python.results)


lca_llvm = pnl.LCAMechanism(
    termination_measure=pnl.TimeScale.TRIAL,
    termination_threshold=2,
    execute_until_finished=True
)

comp_llvm = pnl.Composition()
comp_llvm.add_node(lca_llvm)

print("LLVM: ")
comp_llvm.run([[1], [1]], execution_mode=pnl.ExecutionMode.LLVM)
print(comp_llvm.results)

Next, I checked whether the issue was related to the LCA mechanism being the origin node of the composition, so I simply added a processing mechanism as origin node that projects to the LCA. The discrepancy remained.

Next, I tried changing the termination_threshold on the LCAs from 2 to 1. Now the results align again between python mode and llvm mode. This raises the possibility that the discrepancy is somehow related to termination_threshold.

import psyneulink as pnl

lca_python = pnl.LCAMechanism(
    termination_measure=pnl.TimeScale.TRIAL,
    termination_threshold=1,
    execute_until_finished=True
)

comp_python = pnl.Composition()
comp_python.add_node(lca_python)

print("Python: ")
comp_python.run([[1], [1]], execution_mode=pnl.ExecutionMode.Python)
print(comp_python.results)


lca_llvm = pnl.LCAMechanism(
    termination_measure=pnl.TimeScale.TRIAL,
    termination_threshold=1,
    execute_until_finished=True
)

comp_llvm = pnl.Composition()
comp_llvm.add_node(lca_llvm)

print("LLVM: ")
comp_llvm.run([[1], [1]], execution_mode=pnl.ExecutionMode.LLVM)
print(comp_llvm.results)

Turning the termination_threshold back to 2, I checked whether the issue is related to execute_until_finished. So I set it to false, and added a mechanism to the composition that receives input from the LCA and is scheduled to execute only when the lca is 'finished'. However, now the composition running in LLVM mode does not seem to finish. Whether that is a separate issue, or part of the problem, I do not know.

import psyneulink as pnl

lca_python = pnl.LCAMechanism(
    termination_measure=pnl.TimeScale.TRIAL,
    termination_threshold=2,
    execute_until_finished=False
)

gate_python = pnl.ProcessingMechanism()

comp_python = pnl.Composition()
comp_python.add_linear_processing_pathway([lca_python, gate_python])

comp_python.scheduler.add_condition(
    gate_python, pnl.WhenFinished(lca_python)
)

print("Python: ")
comp_python.run([[1], [1]], execution_mode=pnl.ExecutionMode.Python)
print(comp_python.results)


lca_llvm = pnl.LCAMechanism(
    termination_measure=pnl.TimeScale.TRIAL,
    termination_threshold=2,
    execute_until_finished=False
)

gate_llvm = pnl.ProcessingMechanism()

comp_llvm = pnl.Composition()
comp_llvm.add_linear_processing_pathway([lca_llvm, gate_llvm])

comp_llvm.scheduler.add_condition(
    gate_llvm, pnl.WhenFinished(lca_llvm)
)

print("LLVM: ")
comp_llvm.run([[1], [1]], execution_mode=pnl.ExecutionMode.LLVM)
print(comp_llvm.results)

@jongkeesbj
Copy link
Collaborator Author

Just to add to the last bit of code posted in my previous comment: removing the scheduler condition for comp_llvm does allow the composition to finish, but now (as expected) its results are based on only a single execution of the lca per trial. This indicates to me that there might be something wrong with the LCA's internal 'finished' flag setting to True in LLVM mode when termination_threshold is > 1.

import psyneulink as pnl

lca_python = pnl.LCAMechanism(
    termination_measure=pnl.TimeScale.TRIAL,
    termination_threshold=2,
    execute_until_finished=False
)

gate_python = pnl.ProcessingMechanism()

comp_python = pnl.Composition()
comp_python.add_linear_processing_pathway([lca_python, gate_python])

comp_python.scheduler.add_condition(
    gate_python, pnl.WhenFinished(lca_python)
)

print("Python: ")
comp_python.run([[1], [1]], execution_mode=pnl.ExecutionMode.Python)
print(comp_python.results)


lca_llvm = pnl.LCAMechanism(
    termination_measure=pnl.TimeScale.TRIAL,
    termination_threshold=2,
    execute_until_finished=False
)

gate_llvm = pnl.ProcessingMechanism()

comp_llvm = pnl.Composition()
comp_llvm.add_linear_processing_pathway([lca_llvm, gate_llvm])

# comp_llvm.scheduler.add_condition(
#     gate_llvm, pnl.WhenFinished(lca_llvm)
# )

print("LLVM: ")
comp_llvm.run([[1], [1]], execution_mode=pnl.ExecutionMode.LLVM)
print(comp_llvm.results)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant