PrincetonUniversity / PsyNeuLink

A block modeling system for cognitive neuroscience
https://psyneulink.org
Apache License 2.0
87 stars 30 forks source link

Learning resources #2918

Open JackCaster opened 8 months ago

JackCaster commented 8 months ago

Hi, I stumbled upon this repo and I got excited by the opportunities in using it. I have no formal cognitive modelling training, so I am trying to get up and running by reading some of the examples you shared in the Scripts folder. Unfortunately, most of them do not run. Reasons include missing function, API changes, ... Can you recommend some resources (tutorials, simple implementations) to learn about Psyneulink?

jdcpni commented 8 months ago

Thanks for your interest. The Scripts does indeed have quite a few outdated scripts (there for reference / legacy, useful as part of the development process… probably should be thinned out!). The best way to get initially familiarized is to read through the Basic and Primerhttps://princetonuniversity.github.io/PsyNeuLink/BasicsAndPrimer.html# in the docshttps://princetonuniversity.github.io/PsyNeuLink/. You can also run the tutorial that can be accessed from the main PsyNeuLink landing pagehttp://psyneulink.org/, user the tutorial tabhttp://www.psyneuln.deptcpanel.princeton.edu/tutorial/. Please let us know if you have any problem accessing or interacting with these items. Best.

jdc

On Feb 22, 2024, at 4:41 AM, JackCaster @.***> wrote:

Hi, I stumbled upon this repo and I got excited by the opportunities in using it. I have no formal cognitive modelling training, so I am trying to get up and running by reading some of the examples you shared in the Scripts folder. Unfortunately, most of them do not run. Reasons include missing function, API changes, ... Can you recommend some resources (tutorials, simple implementations) to learn about Psyneulink?

— Reply to this email directly, view it on GitHubhttps://github.com/PrincetonUniversity/PsyNeuLink/issues/2918, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACSHKGFZRMNTKTBATL5TQ3LYU4HEJAVCNFSM6AAAAABDUTAPXWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGE2DQNRTGYZTANQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

JackCaster commented 8 months ago

I tried the tutorial but that seems outdated too. For example, in the section "Organizing into Processes" I get:

Traceback (most recent call last):
  File "/workspaces/accumulate/scrapbook/psyneulink/hello-world.py", line 18, in <module>
    linear_transfer_process = pnl.Process(pathway=[linear_transfer_mechanism])
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/__init__.py", line 107, in Process
    show_warning_sys_and_proc_warning()
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/__init__.py", line 110, in show_warning_sys_and_proc_warning
    raise ComponentError(f"'System' and 'Process' are no longer supported in PsyNeuLink; "
psyneulink.core.components.component.ComponentError: 'System' and 'Process' are no longer supported in PsyNeuLink; use 'Composition' and/or 'Pathway' instead
(project) root@20ca5cf48464:/workspaces/accumulate# 

I'll try with the Primer in the doc now.

jdcpni commented 8 months ago

Thanks! We will look into that error in the tutorial.

jdc

On Feb 27, 2024, at 8:12 AM, JackCaster @.***> wrote:

I tried the tutorial but that seems outdated too. For example, in the section "Organizing into Processes" I get:

Traceback (most recent call last): File "/workspaces/accumulate/scrapbook/psyneulink/hello-world.py", line 18, in linear_transfer_process = pnl.Process(pathway=[linear_transfer_mechanism]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/init.py", line 107, in Process show_warning_sys_and_proc_warning() File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/init.py", line 110, in show_warning_sys_and_proc_warning raise ComponentError(f"'System' and 'Process' are no longer supported in PsyNeuLink; " psyneulink.core.components.component.ComponentError: 'System' and 'Process' are no longer supported in PsyNeuLink; use 'Composition' and/or 'Pathway' instead (project) @.***:/workspaces/accumulate#

I'll try with the Primer in the doc now.

— Reply to this email directly, view it on GitHubhttps://github.com/PrincetonUniversity/PsyNeuLink/issues/2918#issuecomment-1966517870, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACSHKGGQFZWFIB4RYJ7QEWTYVXLSJAVCNFSM6AAAAABDUTAPXWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRWGUYTOOBXGA. You are receiving this because you commented.Message ID: @.***>

JackCaster commented 8 months ago

I am going through the Basics and primer but got stuck at Dynamics of Execution:

# Modify consruction of decision Mechanism:
decision = DDM(name='DECISION',
               input_format=ARRAY,
               reset_stateful_function_when=AtTrialStart(),
               function=DriftDiffusionIntegrator(noise=0.5, threshold=20)
               )
Stroop_model.run(inputs={color_input:red, word_input:green, task_input:color},
                 termination_processing={TimeScale.TRIAL: WhenFinished(decision)}
                 )
print (Stroop_model.results)

but received the error:

Traceback (most recent call last):
  File "/workspaces/accumulate/scrapbook/psyneulink/hello-world.py", line 96, in <module>
    Stroop_model.run(
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 749, in wrapper
    raise e
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 742, in wrapper
    return func(*args, context=context, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/compositions/composition.py", line 11332, in run
    trial_output = self.execute(inputs=execution_stimuli,
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 749, in wrapper
    raise e
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 742, in wrapper
    return func(*args, context=context, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/compositions/composition.py", line 12102, in execute
    for next_execution_set in execution_sets:
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/scheduling/scheduler.py", line 160, in run
    yield from super().run(
  File "/opt/conda/envs/project/lib/python3.11/site-packages/graph_scheduler/scheduler.py", line 913, in run
    not termination_conds[TimeScale.ENVIRONMENT_STATE_UPDATE].is_satisfied(**is_satisfied_kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 749, in wrapper
    raise e
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 742, in wrapper
    return func(*args, context=context, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/scheduling/condition.py", line 113, in is_satisfied
    return super().is_satisfied(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/graph_scheduler/condition.py", line 1008, in is_satisfied
    return call_with_pruned_args(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/graph_scheduler/utilities.py", line 103, in call_with_pruned_args
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/graph_scheduler/condition.py", line 2249, in func
    return dependency.is_finished(execution_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 751, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/library/components/mechanisms/processing/integrator/ddm.py", line 1237, in is_finished
    abs(single_value) >= self.function._get_current_parameter_value(THRESHOLD, context)
    ^^^^^^^^^^^^^^^^^
TypeError: bad operand type for abs(): 'NoneType'

Would you be able to help?

jdcpni commented 8 months ago

Sorry for all the sticking points, but appreciate your taking the time to work through the materials. I will try to look at this later today.

jdc

On Feb 28, 2024, at 4:53 AM, JackCaster @.***> wrote:

I am going through the Basics and primer but got stuck at Dynamics of Executionhttps://princetonuniversity.github.io/PsyNeuLink/BasicsAndPrimer.html#dynamics-of-execution:

Modify consruction of decision Mechanism:

decision = DDM(name='DECISION', input_format=ARRAY, reset_stateful_function_when=AtTrialStart(), function=DriftDiffusionIntegrator(noise=0.5, threshold=20) ) Stroop_model.run(inputs={color_input:red, word_input:green, task_input:color}, termination_processing={TimeScale.TRIAL: WhenFinished(decision)} ) print (Stroop_model.results)

but received the error:

Traceback (most recent call last): File "/workspaces/accumulate/scrapbook/psyneulink/hello-world.py", line 96, in Stroop_model.run( File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 749, in wrapper raise e File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 742, in wrapper return func(*args, context=context, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/compositions/composition.py", line 11332, in run trial_output = self.execute(inputs=execution_stimuli, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 749, in wrapper raise e File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 742, in wrapper return func(args, context=context, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/compositions/composition.py", line 12102, in execute for next_execution_set in execution_sets: File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/scheduling/scheduler.py", line 160, in run yield from super().run( File "/opt/conda/envs/project/lib/python3.11/site-packages/graph_scheduler/scheduler.py", line 913, in run not termination_conds[TimeScale.ENVIRONMENT_STATE_UPDATE].is_satisfied(is_satisfied_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 749, in wrapper raise e File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 742, in wrapper return func(args, context=context, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/scheduling/condition.py", line 113, in is_satisfied return super().is_satisfied( ^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/project/lib/python3.11/site-packages/graph_scheduler/condition.py", line 1008, in is_satisfied return call_with_pruned_args( ^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/project/lib/python3.11/site-packages/graph_scheduler/utilities.py", line 103, in call_with_pruned_args return func(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/project/lib/python3.11/site-packages/graph_scheduler/condition.py", line 2249, in func return dependency.is_finished(execution_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 751, in wrapper return func(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/library/components/mechanisms/processing/integrator/ddm.py", line 1237, in is_finished abs(single_value) >= self.function._get_current_parameter_value(THRESHOLD, context) ^^^^^^^^^^^^^^^^^ TypeError: bad operand type for abs(): 'NoneType'

Would you be able to help?

— Reply to this email directly, view it on GitHubhttps://github.com/PrincetonUniversity/PsyNeuLink/issues/2918#issuecomment-1968616507, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACSHKGBJQO5LLR2U3ATR7M3YV35CZAVCNFSM6AAAAABDUTAPXWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRYGYYTMNJQG4. You are receiving this because you commented.Message ID: @.***>

kmantel commented 8 months ago

I am going through the Basics and primer but got stuck at Dynamics of Execution:

# Modify consruction of decision Mechanism:
decision = DDM(name='DECISION',
               input_format=ARRAY,
               reset_stateful_function_when=AtTrialStart(),
               function=DriftDiffusionIntegrator(noise=0.5, threshold=20)
               )
Stroop_model.run(inputs={color_input:red, word_input:green, task_input:color},
                 termination_processing={TimeScale.TRIAL: WhenFinished(decision)}
                 )
print (Stroop_model.results)

but received the error:

Traceback (most recent call last):
  File "/workspaces/accumulate/scrapbook/psyneulink/hello-world.py", line 96, in <module>
    Stroop_model.run(
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 749, in wrapper
    raise e
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 742, in wrapper
    return func(*args, context=context, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/compositions/composition.py", line 11332, in run
    trial_output = self.execute(inputs=execution_stimuli,
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 749, in wrapper
    raise e
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 742, in wrapper
    return func(*args, context=context, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/compositions/composition.py", line 12102, in execute
    for next_execution_set in execution_sets:
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/scheduling/scheduler.py", line 160, in run
    yield from super().run(
  File "/opt/conda/envs/project/lib/python3.11/site-packages/graph_scheduler/scheduler.py", line 913, in run
    not termination_conds[TimeScale.ENVIRONMENT_STATE_UPDATE].is_satisfied(**is_satisfied_kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 749, in wrapper
    raise e
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 742, in wrapper
    return func(*args, context=context, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/scheduling/condition.py", line 113, in is_satisfied
    return super().is_satisfied(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/graph_scheduler/condition.py", line 1008, in is_satisfied
    return call_with_pruned_args(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/graph_scheduler/utilities.py", line 103, in call_with_pruned_args
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/graph_scheduler/condition.py", line 2249, in func
    return dependency.is_finished(execution_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/core/globals/context.py", line 751, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/project/lib/python3.11/site-packages/psyneulink/library/components/mechanisms/processing/integrator/ddm.py", line 1237, in is_finished
    abs(single_value) >= self.function._get_current_parameter_value(THRESHOLD, context)
    ^^^^^^^^^^^^^^^^^
TypeError: bad operand type for abs(): 'NoneType'

Would you be able to help?

The blocks of code on the primer page are less like a sequence of things to run and more like chunks of a script. So

decision = DDM(name='DECISION',
               input_format=ARRAY,
               reset_stateful_function_when=AtTrialStart(),
               function=DriftDiffusionIntegrator(noise=0.5, threshold=20)
               )

should replace

decision = DDM(name='DECISION', input_format=ARRAY)

in a script which is then rerun. Otherwise, the new DDM isn't added to the composition and pathways, it's just created on its own. This is the cause of the error above.

About the tutorial - it shouldn't be outdated to the point of not functioning. I can't find "Organizing into Processes," and processes are an old construction that we haven't used for a while. I'm interested in where you found that.

The binder link is a third party service and maybe isn't working well, but locally using jupyter, the tutorial seems to be fine for me, following the steps at https://github.com/PrincetonUniversity/PsyNeuLink/?tab=readme-ov-file#tutorial.

kmantel commented 8 months ago

@JackCaster Just to make sure, check the version of psyneulink you have installed with

python -c 'import psyneulink; print(psyneulink.__version__)'.

The current master branch is at version 0.15.1.0, which is what I tested the tutorial locally with.

JackCaster commented 8 months ago

The blocks of code on the primer page are less like a sequence of things to run and more like chunks of a script. So

decision = DDM(name='DECISION',
               input_format=ARRAY,
               reset_stateful_function_when=AtTrialStart(),
               function=DriftDiffusionIntegrator(noise=0.5, threshold=20)
               )

should replace

decision = DDM(name='DECISION', input_format=ARRAY)

in a script which is then rerun. Otherwise, the new DDM isn't added to the composition and pathways, it's just created on its own. This is the cause of the error above.

I see. Would it be possible to add a sentence in the doc to make clear what you just explained?

About the tutorial - it shouldn't be outdated to the point of not functioning. I can't find "Organizing into Processes," and processes are an old construction that we haven't used for a while. I'm interested in where you found that.

I think I was looking at an old tutorial. I was looking at the one in the master branch on GH but realized it is 4 yr old image What branch should I be looking at instead?

kmantel commented 8 months ago

I see. Would it be possible to add a sentence in the doc to make clear what you just explained?

Yeah, we'll add something like this, or change it to be able to be followed in the way you expected.

I think I was looking at an old tutorial. I was looking at the one in the master branch on GH but realized it is 4 yr old image What branch should I be looking at instead?

That should be correct. It is old, but Process is even older and still shouldn't be there. Would you be able to give me some more info on what steps you followed? When I click through to tutorial/PsyNeuLink Tutorial.ipynb on master, and look at the raw file, I don't see the text pnl.Process, referencing your second comment:

I tried the tutorial but that seems outdated too. For example, in the section "Organizing into Processes" I get:

 File "/workspaces/accumulate/scrapbook/psyneulink/hello-world.py", line 18, in <module>
   linear_transfer_process = pnl.Process(pathway=[linear_transfer_mechanism])
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Did you get it by cloning the repo and then trying to run the tutorial notebook? Were you just reading it somewhere without cloning and copied code into your hello-world.py? Or something else?