Repository navigation
Conversation
Dropped from the sidebar onto a composition's box in the main canvas, a layer looked like it was inside but stayed a separate, loose node: the saved script had no add_node for it, the composition stayed empty, and Run failed with "Inputs to Composition1 must be specified ... for each of its 0 INPUT nodes". Only dropping into the composition's own canvas (opened with the icon on its name) added layers to it, and nothing said so. A dropped layer now joins the deepest composition under the pointer, with the same code that re-parents a moved node. This follows issue #36 ("the composition will be visualised as a square that contains all the nodes inside ... if a node gets dropped outside the composition then it's not part of that anymore"). A layer dropped outside every composition stays a loose node. Test: build-a-model.spec.ts drops one layer on the box and one outside, saves, and checks the saved script's composition contains only the first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
…sition On CI's smaller screen the fixed spot fell inside the composition's box, so the layer meant to stay outside joined it. The spot is now chosen beside or below the box, wherever the canvas has room. Passes with the default window and with the window shrunk to 1024x700. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
Brings in #186's latest changes, including the appdmg retry for CI's Intel runners. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
…w lines
Adding a layer or a link to a loaded script used to mean regenerating the whole file from the
diagram (losing comments, weights and the script's own code), behind a "Rewrite the script?"
question; for the Stroop model the regenerated script didn't even build. Now Run, Update Model
and Save As write additions as a few new lines, using the script's own variables:
# Added in PsyNeuLink Viewer
TransferMechanism1 = pnl.TransferMechanism(...)
projection_... = pnl.MappingProjection(sender = TransferMechanism1, receiver = task_layer, ...)
Bidirectional_Stroop.add_node(TransferMechanism1)
Bidirectional_Stroop.add_projection(projection_...)
- Placed after the last top-level line that builds what they refer to, so before any code that
runs or plots the model; the rest of the file stays byte for byte. If a variable they need is
made inside a loop, function or if-block, nothing is written and the error is shown.
- Generated with the same code as a new script (CodeGenerator, now able to write only some
components); new variables keep clear of every name the script uses.
- Links connect layers, not the ports the app shows: for a loaded layer those are named after
its links (e.g. TASK_input_port_TASK_recurrent_projection), not PsyNeuLink's ports.
- The new script is built before the file is written; if it doesn't build, the file and the
model are left as they were. Repeating a change (e.g. after a failed run) adds nothing again.
- Components are looked up in the script's variables, which also works with PsyNeuLink 0.21.1
(where reading a projection's loggable items fails and cut the component list short).
- The app (scriptEdits.ts) still sends removed, renamed or moved items to the regenerate path,
with its question; the app currently has no way to remove, rename or move items.
Tests: Python unit tests for adding to Stroop and other scripts (pass on PsyNeuLink 0.15.3 and
0.21.1), Jest tests for which changes can be written in, and an e2e test that drops a layer on
the Stroop composition, links it both ways with a recurrent layer, runs it, and compares with
plain PsyNeuLink running the file. It replaces the e2e test of the "Rewrite?" question, which
adding a layer no longer asks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
…ix repeats and names
Follow-up to writing added layers and links into the script as new lines:
- When the new lines can't be placed (e.g. a layer they link to is set inside an if-block), the
backend's error starts with CANT_ADD_LINES and the app asks "Rewrite the script?", saying why,
then sends the same Run / Update Model / Save As again without the edits. Cancel leaves the
file untouched. Before, this was only an error with no way forward.
- New layers get a name no component in the model has. The count restarts each session, so a
reopened file could get a second "TransferMechanism1" (a bug before this change too).
- Psyneulink names in values are written as pnl.X (DDM's input_format = pnl.SCALAR): a
hand-written script may not import psyneulink's names, and DDM broke it.
- Writing an addition again (e.g. after a failed run) uses the generator's rendering of values
and leaves empty ones alone, so 'HollowMatrix' stays a string and required defaults
(ContrastiveHebbianMechanism's sizes) stay.
- A link counts as written if the projection named after it exists, not if its layers are
already linked: a second link between linked layers isn't skipped silently, PsyNeuLink's own
error ("already has an identical Projection") is shown.
- Scripts the app generated itself are regenerated with additions, as before; only hand-written
ones get new lines.
Tests: every layer type the sidebar offers, with the values captured from the app
(tests/fixtures/app_new_layers.json), added to Stroop twice; reopening the file and adding
again; a layer set inside an if-block. e2e: hand-written-scripts.spec.ts checks the question,
Cancel, and the regenerated script. Python tests pass on PsyNeuLink 0.15.3 and 0.21.1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
- hand-written-scripts.spec.ts: the script already has a TransferMechanism1, and the layer dropped in the app gets another name; agreeing to regenerate now goes through Run (the request users send most), which then runs the regenerated script. - A value the panel leaves as null again removes the argument, as before: writing an addition again no longer needs it written as None (the generator's rendering already gives 'None'). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
The every-layer-type test rebuilt the Stroop model twice per type (24 rebuilds), and the step hit its 10-minute limit on CI's Intel runner. It now adds all types in one change and repeats it once (same checks, 2 rebuilds); the step's limit is 20 minutes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
Panning and zooming were never turned off (meta-diagram 0.3.2 ignores the disableZoom and disableMoveCanvas settings), but nothing showed it: the Stroop model opened at 100% with most of it below the window, and scrolling zoomed, which on a trackpad is where people expect to pan. - Opening a model zooms out to fit it in the part of the canvas between the tool bar and the Model Hierarchy panel, no further than 50% (smaller, names can't be read): a bigger model shows its top part. It never zooms in. - Zoom controls at the bottom left: zoom out, the zoom level (click: back to 100%), zoom in, and fit the whole model. - Scrolling (mouse wheel, two fingers on a trackpad) pans; pinching, or Ctrl/⌘ + scroll, zooms around the pointer, as in Figma or Miro. Something inside the canvas that scrolls by itself (a long properties panel) still scrolls. - The view of a model is kept when the canvas is drawn again, e.g. after closing a composition. - Over an open composition there are no zoom controls and no fitting: its dialog covers the controls, and panning or zooming there also resizes the composition (handlePostUpdates). Tests: e2e/canvas-navigation.spec.ts (also passes with the window at 1024×700). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
Changes that can't be written into a hand-written script line by line (a layer dragged out of
its composition, layers or links removed, additions with no place for a line) used to
regenerate the script from the app's copy of the model. For a loaded model like the Stroop one
that lost the weights and layer sizes, turned the app's port names into real input ports, and
failed outright on recurrent layers' self-links.
Now the change is made to the live model and PsyNeuLink writes the script for it
(get_mdf_serialized + generate_script_from_mdf, model/scriptRewrite.py):
- Built afresh from the script with the values written in, the additions run in it, then layers
moved or removed (Composition.remove_node / add_node, which takes a moved layer's links in the
old composition with it) and links removed (remove_projection).
- The export keeps every layer, link, weight and setting; names are put back ("COLORS HIDDEN",
not the exporter's "COLORS_HIDDEN"), and layers outside any composition are written too.
- Before anything is written, the new script is built and compared with the live model: layers
(type, size), links and weights, and three trials run with every input at 1. If they differ,
nothing is written and the reason is shown, e.g. for learning, which the exporter leaves out.
- Built once and exported once: PsyNeuLink 0.21.1 writes a broken script for a model it has
serialized before (json_summary does), referring to input ports that don't exist.
The app (scriptEdits.ts) now sends moves and removals instead of giving up, asks before a
rewrite (the dialog says what's kept and what's lost: comments, variable names, other code), and
opens the file again afterwards so the diagram is the new file's. When added lines can't be
placed, agreeing sends the same changes again asking for a rewrite. Scripts the app generated
itself are still regenerated from the app's model.
Tests: test_script_rewrite.py (Stroop with a layer moved out: same weights and results as plain
PsyNeuLink; a second rewrite; a value with a move; learning refused; additions rewritten), on
PsyNeuLink 0.15.3 and 0.21.1; Jest for the reported changes; an e2e test dragging TASK_INPUT out
of the Stroop composition and comparing with plain PsyNeuLink.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
The box's resize handles are drawn after its name chip, and the top one is a strip along the box's top edge. Zoomed far out (CI's smaller screen, after "Fit to window"), it caught the click meant for the chip's icon, so the composition couldn't be opened. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
…er their layers - Opening a composition (the icon on its name) showed its layers where they are in the whole model, at 100%: for the Stroop model, mostly off to the right and below the dialog. It's now fitted like a model being opened (down to 50%, top first), with the zoom controls inside the dialog. Coming back keeps the main view as it was. - Links added in the app were written as e.g. "projection_6167e875cedf = pnl.MappingProjection(..., name = 'projection_6167e875cedf')", after the app's id for the link. They're now named after the layers they connect: "TASK_INPUT_to_Extra = pnl.MappingProjection(..., name = 'TASK_INPUT to Extra')". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #186 (it reuses that PR's build-a-model test). Its base should change once #186 merges.
Four changes, all about building on a model in the app and keeping its script right.
1. A layer dropped on a composition's box joins that composition
The problem
Dropping a layer from the sidebar onto a composition's box in the main canvas makes it look like it's inside the composition, but it isn't:
add_nodefor it;The only way to add layers today is to open the composition first (the icon on its name), and nothing in the app says so.
The change
A dropped layer now joins the deepest composition under the pointer. It uses the same code (
MetaGraph.updateGraph) that re-parents a node when it's moved. A layer dropped outside every composition stays a separate node.This follows issue #36 (closed), which describes compositions as boxes that contain their nodes:
Question for the team: is #36 still the intended behaviour? Since then, moving nodes on the canvas has been turned off (
disableMoveNodes: true), so I may be missing a later design decision. If "open the composition first" is the intended flow, a hint on the box would be the alternative.2. Added layers and links are written into a hand-written script as new lines
The problem
In a script loaded from a file, changed values are already written into the file one argument at a time (#186). Adding a layer or a link was different: the whole file was regenerated from the diagram. That loses what the diagram doesn't show (weights, comments, the script's own variables and code), so #186 asks "Rewrite the script?" first. For the Cohen & Huston Stroop model, the regenerated script doesn't even build.
The change
Run, Update Model and Save As now add a few lines to the script, using its own variables. Adding a layer to the Stroop model and linking it both ways with the TASK layer gives:
CodeGenerator, which can now write only some components). New variables keep clear of every name the script uses.TASK_input_port_TASK_recurrent_projection), not after PsyNeuLink's ports.iffor an option): the app asks "Rewrite the script?", says why, and Cancel leaves the file untouched.Fixed along the way:
TransferMechanism1.pnl.X: DDM'sinput_format = SCALARbroke scripts that don't dofrom psyneulink import *.Found, not fixed here
pathways=[pnl.TransferMechanism(...)]) don't appear.3. Rewriting a loaded script keeps the model
The problem
Some changes can't be written into a hand-written script line by line: a layer dragged out of its composition (select tool), layers or links removed, or added lines with no safe place to go. Those used to regenerate the whole script from the app's copy of the model. For a loaded model like the Stroop one, that copy has no weights or layer sizes and has made-up port names, so the regenerated script was a different model. For Stroop it failed outright ("already has an identical Projection") on the recurrent layers' self-links.
The change
The change is made to the live PsyNeuLink model, and PsyNeuLink writes the script for it (
get_mdf_serialized+generate_script_from_mdf, inmodel/scriptRewrite.py):Composition.remove_node/add_node) and links removed (remove_projection). A layer moved out of a composition loses its links there; that's whatremove_nodedoes.Found along the way: PsyNeuLink 0.21.1 writes a broken script when a model is exported a second time (the app reads
json_summaryon load, which counts): it connects projections to input ports the new script doesn't have. 0.15.3 is fine. The rewrite builds the model afresh and exports it once. We'll report this upstream separately.4. Moving around the canvas
Panning and zooming were never turned off: meta-diagram 0.3.2 ignores the
disableZoomanddisableMoveCanvassettings. But nothing showed it. The Stroop model opened at 100% with most of it below the window, and scrolling zoomed, which on a trackpad is where people expect to pan.handlePostUpdates, width × zoom). It looks wrong but does no harm in the tests; it needs its own look.Question for the team: what were
disableZoom,disableMoveCanvas,disableMoveNodesanddisableDeleteDefaultKey(psyneu-65) meant for? They have no effect today: the canvas pans, zooms and moves nodes (Delete does nothing, for another reason I haven't looked into).Tests
e2e/build-a-model.spec.tsdrops one layer on a composition's box and one outside it, saves, and checks that the saved script's composition contains only the first.e2e/published-models.spec.tsdrops a layer on the Stroop composition and links it both ways with the recurrent TASK layer. It then checks that the file gained only the new lines, and that running in the app matches plain PsyNeuLink running the file.e2e/hand-written-scripts.spec.tscovers the "Rewrite?" question (Cancel, and agreeing from Run). It also checks that a new layer doesn't reuse a name the script already has.src/server/tests/test_script_additions.py(18 tests) adds to Stroop and to other scripts. It uses every layer type the sidebar offers, with the values captured from the app, and writes each one twice. It also covers failures, reopening the file, and Save As. The tests pass on PsyNeuLink 0.15.3 and 0.21.1.src/client/tests/scriptEdits.test.jschecks which changes can be written into a script.src/server/tests/test_script_rewrite.py: Stroop with TASK_INPUT moved out (same weights and results as plain PsyNeuLink taking it out), a second rewrite of the rewritten script, a value change with a move, learning refused, and additions rewritten. The tests pass on PsyNeuLink 0.15.3 and 0.21.1.e2e/published-models.spec.tsalso drags TASK_INPUT out of the Stroop composition, agrees to the rewrite, and compares the new file with plain PsyNeuLink.e2e/canvas-navigation.spec.tschecks fitting on opening, scrolling and Ctrl + scroll, the zoom buttons, that the view is kept after opening a composition, and that an opened composition is fitted and can be zoomed.🤖 Generated with Claude Code