Skip to content

Commit 101b2a8

Browse files
committed
Use short aliases for SocketSpecSelect and SocketSpecMeta
1 parent 4e49e16 commit 101b2a8

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

docs/gallery/howto/autogen/annotate_inputs_outputs.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,12 @@ def AddMultiplyFinal(
316316
# %%
317317
# Note how the outputs of the various tasks are exposed (linked) to the graph, making accessible via the graph node.
318318
#
319-
# Reshaping specifications with ``SocketSpecSelect``
319+
# Reshaping specifications with ``select``
320320
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
321321
#
322322
# Often, you'll want to reuse parts of a specification while modifying it.
323323
# For example, you might want to exclude a field that is provided by another source or rename fields for clarity.
324-
# This can be done declaratively using ``SocketSpecSelect``.
324+
# This can be done declaratively using ``select``.
325325
#
326326
# The main parameters are:
327327
#
@@ -332,12 +332,12 @@ def AddMultiplyFinal(
332332
#
333333
# .. Important::
334334
#
335-
# To apply a ``SocketSpecSelect``, you must place it in the metadata list of ``t.Annotated[<type>, ...]`` alongside the specification you are modifying.
335+
# To apply a ``select``, you must place it in the metadata list of ``t.Annotated[<type>, ...]`` alongside the specification you are modifying.
336336
#
337337
# Let's see an example where we build a graph that runs a task twice. We want a shared ``structure`` input at the graph level,
338338
# so we must *exclude* it from the nested input specifications for each task call.
339339

340-
from aiida_workgraph.socket_spec import SocketSpecMeta, SocketSpecSelect
340+
from aiida_workgraph.socket_spec import meta, select
341341

342342

343343
@task
@@ -363,10 +363,10 @@ def UseExclude(
363363
dict,
364364
namespace(
365365
consume_complex1=t.Annotated[
366-
consume_complex.inputs, SocketSpecSelect(exclude="data.pw.structure")
366+
dict, consume_complex.inputs, select(exclude="data.pw.structure")
367367
],
368368
consume_complex2=t.Annotated[
369-
consume_complex.inputs, SocketSpecSelect(exclude="data.pw.structure")
369+
dict, consume_complex.inputs, select(exclude="data.pw.structure")
370370
],
371371
),
372372
],
@@ -401,21 +401,21 @@ def UseExclude(
401401
# Modifying specification metadata
402402
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
403403
#
404-
# You can also set namespace-level metadata declaratively using ``SocketSpecMeta``, for example,
404+
# You can also set namespace-level metadata declaratively using ``meta``, for example,
405405
# to mark a reused specification as optional.
406406
#
407-
# - ``SocketSpecMeta(required=False)``: Makes the input optional.
408-
# - ``SocketSpecMeta(is_metadata=True)``: Marks the input as metadata-only.
407+
# - ``meta(required=False)``: Makes the input optional.
408+
# - ``meta(is_metadata=True)``: Marks the input as metadata-only.
409409
#
410-
# It is attached alongside ``SocketSpecSelect`` in the same ``Annotated`` metadata list.
410+
# It is attached alongside ``select`` in the same ``Annotated`` metadata list.
411411

412412

413413
@task.graph
414414
def UseMeta(
415415
data: t.Annotated[
416416
dict,
417417
consume_complex.inputs, # Reuse the original spec
418-
SocketSpecMeta(required=False), # Make the entire 'data' input optional
418+
meta(required=False), # Make the entire 'data' input optional
419419
]
420420
):
421421
if data:
@@ -435,7 +435,7 @@ def UseMeta(
435435
# - Annotate inputs to specify input structures.
436436
# - Employ ``dynamic`` for tasks with a variable number of outputs.
437437
# - Reuse ``.inputs`` and ``.outputs`` specifications at the graph level to build modular and robust workflows.
438-
# - Use ``SocketSpecSelect`` inside ``Annotated`` to reshape reused specifications (e.g., ``include``/``exclude`` with dotted paths, ``rename``, `prefix`).
439-
# - Use ``SocketSpecMeta`` to modify metadata of a specification, such as making it optional.
438+
# - Use ``select`` inside ``Annotated`` to reshape reused specifications (e.g., ``include``/``exclude`` with dotted paths, ``rename``, `prefix`).
439+
# - Use ``meta`` to modify metadata of a specification, such as making it optional.
440440
#
441441
# These tools are fundamental to building reproducible and verifiable scientific workflows with complete data provenance.

src/aiida_workgraph/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .utils.flow_control import if_, while_, map_
77
from .manager import get_current_graph, If, Map, While, Zone
88
from . import socket_spec as spec
9-
from .socket_spec import namespace, dynamic
9+
from .socket_spec import namespace, dynamic, select, meta
1010
from .collection import group
1111

1212
__version__ = "0.7.1"
@@ -28,5 +28,7 @@
2828
"spec",
2929
"namespace",
3030
"dynamic",
31+
"select",
32+
"meta",
3133
"group",
3234
]

src/aiida_workgraph/socket_spec.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
SocketSpec,
88
BaseSocketSpecAPI,
99
BaseSpecInferAPI,
10+
select,
11+
meta,
1012
)
1113
from aiida_workgraph.orm.mapping import type_mapping
1214
from aiida.engine import Process
@@ -25,6 +27,8 @@
2527
"infer_specs_from_callable",
2628
"from_aiida_process",
2729
"SocketSpecSelect",
30+
"select",
31+
"meta",
2832
]
2933

3034

0 commit comments

Comments
 (0)