Flatten Enum members to bare values on the serialize path#800
Open
elinscott wants to merge 2 commits into
Open
Flatten Enum members to bare values on the serialize path#800elinscott wants to merge 2 commits into
elinscott wants to merge 2 commits into
Conversation
node-graph's socket spec records structured_type extras for enum-typed sockets so coerce_inputs_from_spec can rebuild the member before a task body runs - the declared contract is that the serialized form is the bare value. The AiiDA adapter never honoured it: raw Enum instances reached aiida-pythonjob's general_serializer, which has no serializer for them and failed the whole submission. Flatten enums (recursively, including dict keys/values and list items) before serialize_ports. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
node-graph's socket spec records structured_type extras for enum-typed sockets so coerce_inputs_from_spec can rebuild the member before a task body runs - the declared contract is that the serialized form is the bare value. The AiiDA adapter never honoured it: raw Enum instances reached aiida-pythonjob's general_serializer, which has no serializer for them and failed the whole submission. Flatten enums (recursively, including dict keys/values and list items) before serialize_ports. Add unit tests in tests/test_serializer.py covering _flatten_enums (bare/IntEnum/str-Enum members, dict keys and values, list/tuple, mixed nesting, enum-free passthrough, wrapt-proxied members) plus one end-to-end serialize_ports check that an enum-valued entry serializes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
node_graphdeclares that an enum-typed socket's serialized form is the bare member value:socket_specrecordsstructured_typeextras precisely socoerce_inputs_from_speccan rebuild theEnummember before a task body runs.The AiiDA serialization adapter never honoured that contract on the write path: a raw
Enuminstance (or a dict/list containing one, e.g. a parameters dict with an enum-valued entry) flows straight intoserialize_ports, which hands it to aiida-pythonjob'sgeneral_serializer— which has no serializer for enums — and the whole submission fails at submit time with an opaque serialization error.Change
A small
_flatten_enumshelper replacesEnummembers with their.value, recursively through dicts (keys and values), lists and tuples, and is applied in bothAiidaSerializationAdapter.serializeandAiidaSerializationAdapter.serialize_portsimmediately afterresolve_tagged_values. Theisinstance(value, Enum)check also matches wrapt proxies (TaggedValue) wrapping enum members, so tagged graph inputs are handled by the same path.Round-trip is preserved: the read side (
coerce_inputs_from_specin node-graph) rebuilds the member from the bare value using the recordedstructured_type, so task bodies still receive theEnumthey declared.Testing
New unit tests in
tests/test_serializer.pyExercised end-to-end by the downstream Koopmans package, whose workgraphs pass enum-valued settings (e.g. functional and spin-treatment enums) through
@task.graphinputs: before the change every such submission failed ingeneral_serializer; after it, the graphs submit and the bodies receive rebuilt members.