Add element_names: per-element semantic labels on ports (slice 1: core) - #3624
Open
jonhanke-nam wants to merge 5 commits into
Open
Add element_names: per-element semantic labels on ports (slice 1: core)#3624jonhanke-nam wants to merge 5 commits into
jonhanke-nam wants to merge 5 commits into
Conversation
…hand Add an optional `element_names` label list to InputPort/OutputPort and a Mechanism-level shorthand that applies to the default input+output ports. Stored as a static, read-only structural Parameter (stateful=False, loggable=False, read_only=True, structural=True), mirroring InputPort's existing default_input/shadow_inputs. Length is validated against the port's value size at construction (PortError on mismatch). Excluded from LLVM compilation via the _get_compilation_params blacklist, alongside the other non-computational structural params (default_input, shadow_inputs). Purely additive: element_names defaults to None and does not participate in execution. Distinct from input_labels/output_labels (symbolic-name -> value-vector maps). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
11 tests covering the additive default (None), per-port labels, the Mechanism shorthand, per-port override of the shorthand, list-copy semantics, falsy-as-unset, and length-mismatch PortError. Ports are exercised as owned (inside a Mechanism), consistent with how every other port Parameter is populated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Open
4 tasks
Comment on lines
+1812
to
+1814
| from psyneulink.core.components.ports.port import ( | ||
| _validate_element_names_length, | ||
| ) |
|
This PR causes the following changes to the html docs (ubuntu-latest-3.11): See CI logs for the full diff. |
…erialization The Mechanism shorthand set only the override value, so shorthand-labeled ports read back correctly via port.element_names but serialized as None to MDF (which reads the parameter default). Set both the default and the override so the shorthand behaves identically to an explicit per-port element_names everywhere -- reads, MDF export, and future round-trip. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
This PR causes the following changes to the html docs (ubuntu-latest-3.11): See CI logs for the full diff. |
element_names is a registered Parameter, so it serializes into a port's MDF model automatically. Lock in the export behavior: explicit per-port labels (input + output), the Mechanism shorthand, and the unset case (serializes as None, consistent with the sibling structural params). Full script round-trip is a tracked follow-up. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
This PR causes the following changes to the html docs (ubuntu-latest-3.11): See CI logs for the full diff. |
The 'notorch' CI config doesn't install modeci_mdf, so as_mdf_model() raises
ModuleNotFoundError. Guard the module with pytest.importorskip('modeci_mdf'),
matching tests/mdf/test_mdf.py.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jonhanke-nam
marked this pull request as ready for review
August 19, 2026 22:55
Collaborator
Author
|
Ready for review. Full CI is green (build matrix across Python 3.10–3.14 × macOS/Ubuntu/Windows incl. LLVM/benchmark/notorch, docs, CodeQL, coverage). Any red/gray marks in the checks list are cancelled |
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.
Adds an optional, purely-additive
element_nameslabel list toInputPort/OutputPort(with aMechanism-level shorthand): one semantic label per element of a port's value vector. Opt-in,Noneby default, and does not participate in execution.5 files, +107 on devel.Motivation: downstream inspection/introspection tools want to show what each element of a node's value means (e.g. which unit is "red" vs "green") instead of a numeric index. This has been stabilized against a real consumer (the PsyNeuView model viewer), which reads the labels via the
_debuggerNODE_EXECUTIONsnapshot. Kept deliberately small and additive; this is the first of a few focused slices (see design discussion below).Design
Parameter—Parameter(None, stateful=False, loggable=False, read_only=True, structural=True)— mirroringInputPort.default_input/shadow_inputs. Chosen (over a plain attribute) to match how PsyNeuLink already carries construction-time port metadata, so it flows through the Parameters machinery uniformly.Mechanismshorthand applies the list to the default (first) input port and default output port, but only when those ports don't already carry their ownelement_names(per-port labels always win). It sets the read-only Parameter viaparameters.element_names.set(..., override=True).PortError.Scope & behavior
input_labels/output_labels(those map symbolic names → whole value vectors; this maps element index → label).element_namesis populated once the port is instantiated into aMechanism— exactly likedefault_inputand every other port Parameter (a standalone/deferred port raisesParameterNoValueErrorfor it, same as the others). This is the one intentional behavior refinement vs. an eager-attribute approach; called out so it's not a surprise._get_compilation_paramsblacklist, alongside the other non-computational structural params (default_input,shadow_inputs,internal_only).Backward compatibility
None, no execution participation. If this perturbed execution or component structure, the existing test matrix would fail — it passes unchanged locally (ports incl.LLVMRun,test_parameters, and the MDF round-trip suite all green).element_namesfrom compilation like the sibling structural params. No other changes to compiled structures.Tests
tests/misc/test_element_names.py— 11 tests: additive default (None), per-port labels, the Mechanism shorthand, per-port override of the shorthand, list-copy semantics, falsy-as-unset, and length-mismatchPortError. Ports are exercised as owned (inside aMechanism).Files changed
ports/inputport.py,ports/outputport.py— theelement_namesParameter + constructor argports/port.py— length validation helper + call site inPort_Base.__init__mechanisms/mechanism.py— the Mechanism-level shorthandcomponents/component.py— LLVM compilation blacklist entrytests/misc/test_element_names.py— the testsDesign discussion and the remaining slices (propagation, MDF round-trip, debugger surface) are tracked here: jonhanke-nam/PsyNeuLink#23. This is the first focused submission alongside the
jonhanke-devfeature preview (#3558). Opening as a draft for a first look before review.