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

Dataclass parsing #111

Closed
samwaseda opened this issue Jan 29, 2025 · 2 comments · Fixed by #114
Closed

Dataclass parsing #111

samwaseda opened this issue Jan 29, 2025 · 2 comments · Fixed by #114

Comments

@samwaseda
Copy link
Member

At the latest pyiron meeting I had claimed that data classes can be parsed automatically, but afterwards I realized that it was only partly true. Currently the plan is for the user to be able to write something like:

@semantikon_class
@dataclass
class Input:
    temperature: u(float, units="kelvin")
    number_of_steps: int

@semantikon_class
@dataclass
class Output:
    energy: u(float, units="electron_volt")
    volume: u(float, units="angstrom**3")

@Workflow.wrap.as_function_node
def run_md(inp: Input) -> Output:
    out = Output(energy=1., volume=2.)
    return out

And temperature and number_of_steps should be stored as subclasses of Input. More in the PR (to come)

@samwaseda
Copy link
Member Author

This is my note for me to see what should come out. No need for anyone to understand

class Class1:
    var_2: float

class_1 = Class1(var_2=1.0)
flowchart TB;
    node_1 --> node_1.outputs.var_1;
    node_1.outputs.var_1 --> node_2.inputs.var_1;
    node_2.inputs.var_1 --> node_2;
    node_2.inputs.var_1 -- hasValue --> node_1.outputs.var_1.value;
    node_1.outputs.var_1 -- hasValue --> node_1.outputs.var_1.value;
    node_1 --> node_1.outputs.class_1;
    node_1.outputs.class_1 --> node_2.inputs.class_1;
    node_2.inputs.class_1--> node_2;
    node_2.inputs.class_1 -- hasValue --> node_1.outputs.class_1.value;
    node_1.outputs.class_1 -- hasValue --> node_1.outputs.class_1.value;
    node_1.outputs.class_1.var_2.value -- subClassOf --> node_1.outputs.class_1.value;
    node_2.inputs.class_1 -- hasValue --> node_1.outputs.class_1.var_2.value;
    node_1.outputs.class_1 -- hasValue --> node_1.outputs.class_1.var_2.value;
Loading

@samwaseda
Copy link
Member Author

EDIT: With this PR I realized that what I had claimed was not wrong in the end, and you don't need dependence on semantikon_class in contrast to what's presented above (but you can also use it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant