Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[minor] Make Function IO info available at the class level #266

Merged
merged 12 commits into from
Apr 11, 2024

Conversation

liamhuber
Copy link
Member

@liamhuber liamhuber commented Mar 27, 2024

This will be useful for building nodes that take other node classes as input and want to build their own corresponding IO based on that class's IO without having to instantiate it first. It also borders on necessary for the long-term goal of being able to suggest nodes to users based on ontological (or regular...) type hints ala ironflow.

Example:

from pyiron_workflow import Workflow

@Workflow.wrap_as.function_node("xplus1", "xminus1")
def PlusMinusBound0(x: int) -> tuple[int, int | None]:
    return x + 1, None if x - 1 < 0 else x - 1

print(PlusMinusBound0.preview_output_channels())
>>> {'xplus1': int, 'xminus1': int | None}

print(PlusMinusBound0.preview_input_channels())
>>> {'x': (<class 'int'>, NOT_DATA)}

Tasks:

  • Make output info available
  • Make input info available
  • Update docs/notebooks as needed (I don't see a need to update the notebooks -- until there is a better use case in, e.g. for loops or whatever, even node developers don't need to care about this functionality)

Non-goals:

  • The same treatment for Macro, which makes sense but is left to another PR
  • Anything like this for Workflow, which doesn't make sense since its IO is dynamic anyhow

Minor bump as the signature for AbstractFunction has changed.

So channel labels and type hints (and later any ontological hints) can be viewed without ever instantiating a node. That means `output_labels` is no longer available at the class instance level, but only when defining a new class!
Copy link

Binder 👈 Launch a binder notebook on branch pyiron/pyiron_workflow/class_channel_specs

Copy link

codacy-production bot commented Mar 27, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.05% (target: -1.00%) 98.46%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (52497d6) 3411 2991 87.69%
Head commit (98d4570) 3418 (+7) 2999 (+8) 87.74% (+0.05%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#266) 65 64 98.46%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

You may notice some variations in coverage metrics with the latest Coverage engine update. For more details, visit the documentation

@liamhuber
Copy link
Member Author

Windows unit tests failed with

graphviz.backend.execute.CalledProcessError: Command '[WindowsPath('dot'), '-Kdot', '-Tpdf', '-O', 'start_graph']' returned non-zero exit status 1. [stderr: b'Warning: Could not load "C:\\Miniconda3\\envs\\my-env\\Library\\bin\\gvplugin_pango.dll" - It was found, so perhaps one of its dependents was not.  Try ldd.\r\nWarning: Could not load "C:\\Miniconda3\\envs\\my-env\\Library\\bin\\gvplugin_pango.dll" - It was found, so perhaps one of its dependents was not.  Try ldd.\r\nFormat: "pdf" not recognized. Use one of: bmp canon cmap cmapx cmapx_np dot dot_json emf emfplus eps fig gd gd2 gif gv imap imap_np ismap jpe jpeg jpg json json0 metafile mp pdf pic plain plain-ext png pov ps ps2 svg tif tiff tk webp xdot xdot1.2 xdot1.4 xdot_json\r\n']

Doesn't look directly related to these changes, but I might need to go back and pin graphviz to some other version.

@liamhuber liamhuber added the format_black trigger the Black formatting bot label Mar 27, 2024
@liamhuber liamhuber changed the title [WIP] Make Function IO info available at the class level [minor] Make Function IO info available at the class level Mar 27, 2024
@liamhuber
Copy link
Member Author

Yyyep.

======================================================================
ERROR: test_draw (test_node.TestNode.test_draw)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Miniconda3\envs\my-env\Lib\site-packages\graphviz\backend\execute.py", line 88, in run_check
    proc.check_returncode()
  File "C:\Miniconda3\envs\my-env\Lib\subprocess.py", line 502, in check_returncode
    raise CalledProcessError(self.returncode, self.args, self.stdout,
subprocess.CalledProcessError: Command '[WindowsPath('dot'), '-Kdot', '-Tpdf', '-O', 'start_graph']' returned non-zero exit status 1.

@liamhuber liamhuber requested a review from samwaseda March 27, 2024 19:50
@liamhuber liamhuber marked this pull request as ready for review March 27, 2024 19:51
@liamhuber
Copy link
Member Author

Windows error needs to be fixed, but it's from graphviz and unrelated to these changes.

@liamhuber liamhuber mentioned this pull request Mar 28, 2024
11 tasks
Base automatically changed from io_info_as_classmethod to main April 11, 2024 20:13
@liamhuber liamhuber merged commit cf3a208 into main Apr 11, 2024
14 of 15 checks passed
@liamhuber liamhuber deleted the class_channel_specs branch April 11, 2024 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
format_black trigger the Black formatting bot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants