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

Adding a new "IF" node that would simply return the truevalue or falsevalue based on the test condition. #11481

Merged

Conversation

reddyashish
Copy link
Contributor

@reddyashish reddyashish commented Feb 9, 2021

Purpose

Task: https://jira.autodesk.com/browse/DYN-1976

This PR is made from the original one by @aparajit-pratap : #11464.

Created a new if node that would create a AST output for the following DS code

[t, f][cond ? 0 : 1];

We will have to figure out a new name for this node so that it would be clear to the users and can be found easily.
Added a test to verify the functionality of this new node.
The current if node can be removed in the next major version if we feel it would not be needed.

If the input condition has a list of boolean values then the output will be replicated based on the test input value.

new if node

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated

Reviewers

@aparajit-pratap @QilongTang @mmisol @Amoursol @mjkkirschner

@Amoursol
Copy link
Contributor

Amoursol commented Feb 9, 2021

@reddyashish Is it possible for me to test this build? If so, please let me know how. Also, have you tested with Empty List and Null inputs?

@Amoursol Amoursol self-requested a review February 9, 2021 14:50
@reddyashish
Copy link
Contributor Author

@Amoursol Yes I have tested this with Empty lists and null values and it works as expected.
Screen Shot 2021-02-09 at 10 02 28 AM

You can pull in the changes from this branch and test it locally.

@Amoursol
Copy link
Contributor

Amoursol commented Feb 9, 2021

@Amoursol Yes I have tested this with Empty lists and null values and it works as expected.
Screen Shot 2021-02-09 at 10 02 28 AM

You can pull in the changes from this branch and test it locally.

Cool - I'll build and test! :)

@aparajit-pratap
Copy link
Contributor

@Amoursol please note that this new node does not have lacing or partial function support. It differs from the old one in that the old one did have partial function support. We did not feel it was very useful for this node as the usage of the If node as a partial function seemed ambiguous. Please let us know if you have other thoughts.

@Amoursol
Copy link
Contributor

Amoursol commented Feb 9, 2021

@Amoursol please note that this new node does not have lacing or partial function support. It differs from the old one in that the old one did have partial function support. We did not feel it was very useful for this node as the usage of the If node as a partial function seemed ambiguous. Please let us know if you have other thoughts.

@aparajit-pratap - gotcha! I need to test to see if we do need Lacing or List@Level - both were direct requests from our users when requesting feedback here: https://forum.dynamobim.com/t/request-for-feedback-if-node/45257

My concern without implementing this would be we are in the same position at a later date, but I'll test to see if the use cases in that thread are covered. The two bugs that appear to be fixed in this are definitely a step in the right direction: Empty List control and various length True/False lists not having data truncated.

@aparajit-pratap
Copy link
Contributor

If you're comparing this with the Clockwork node, I'd like to add that it is almost identical to that. Secondly, about replication and list-at-level, in order to make this node match with user expectation of its use, we needed to disable replication for the true and false inputs (2nd and 3rd resp.). The node can only replicate on the 1st input, the test condition.

@aparajit-pratap
Copy link
Contributor

From that forum thread to me it sounds like users are confused as to what Lacing or List@Level can do to help in the context of this node. Whatever output they expect from the node can be achieved without those additions.

@aparajit-pratap
Copy link
Contributor

If lacing or list-at-level support is required for this node for consistency sake, I think it might be possible to still add it, however, for partial function support, I think we might need a different approach where we create a special builtin function and call that from this node:

def if_func(cond : bool, t : var[]..[], f : var[]..[])
{
    return [Imperative]
    {
        return cond ? t : f;
    }
}

@Amoursol
Copy link
Contributor

Amoursol commented Feb 9, 2021

If lacing or list-at-level support is required for this node for consistency sake, I think it might be possible to still add it, however, for partial function support, I think we might need a different approach where we create a special builtin function and call that from this node:

def if_func(cond : bool, t : var[]..[], f : var[]..[])
{
    return [Imperative]
    {
        return cond ? t : f;
    }
}

I've been busy all day so far, going to download the build and test today/tomorrow :) Just need to see what kind of data I can emulated from a messy Revit source.

@@ -72,4 +74,44 @@ public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode
};
}
}

[NodeName("NewIf")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to rename it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to decide on the final name for this node. I have just added this name as a draft. Since, the old "IF" node still exists in the Dynamo library, we will need a different name for the node.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean to ask if we can keep the same name for the new node while deprecating the old one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reddyashish @QilongTang I'm still not sure about this. To give an example, I introduced a new IntegerSlider64Bit NodeModel class but could keep the same name Integer Slider for the node. I think we may be able to do something similar here so that new If nodes have new behaviour but the same name. We might just have to figure out a way for old If nodes to continue to deserialize as the old NodeModel class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aparajit-pratap what about if the old IF node actually has its name migrated to "replicating if" or "legacy if" and the new node becomes "If"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reddyashish I think you're getting confused. The old node will be hidden from the library.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reddyashish - AFAIK @aparajit-pratap is correct that the use of the [obsolete] attribute should hide the node - it's possible you need to use [NodeObsolete] for that though - I know there is some discrepancy between zero touch and nodeModel nodes though - so watch out for that.

Maybe a good first step is to decide what should happen?

  1. should the original node be hidden, but still load when in an existing graph to stay backward compatible?
  2. If a user places a new node what should it be called?
  3. Is there any way to tell the difference between the old and new nodes in the same graph? (I assume the old ones will be in error state because of the obsolete attr - if it's working right?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, from a user perspective they want the following

@reddyashish - AFAIK @aparajit-pratap is correct that the use of the [obsolete] attribute should hide the node - it's possible you need to use [NodeObsolete] for that though - I know there is some discrepancy between zero touch and nodeModel nodes though - so watch out for that.

Maybe a good first step is to decide what should happen?

  1. should the original node be hidden, but still load when in an existing graph to stay backward compatible?
  2. If a user places a new node what should it be called?
  3. Is there any way to tell the difference between the old and new nodes in the same graph? (I assume the old ones will be in error state because of the obsolete attr - if it's working right?)

@mjkkirschner IMHO, from a user perspective:

  1. Yes this should happen
  2. It should simply be called "If" but reference the updated, new node.
  3. Is the error message obvious if we do this? Or will it simply say it's missing something? Ideally, users would understand that they need to replace that node. Would Copy + Paste of that node into the same place do the trick?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code to hide the old "If" node from the library and rename the new one to have the same name. When the users open an old graph with the if node, it will behave like the old one(conditional if). Any new "If" node that will be placed will build on the new functionality. The [NodeObsolete] attribute can only be used for a method or a property and the [obsolete] attribute will throw a warning when the old "if" class is used in any of the code. It wouldn't throw an error on the Dynamo side. Do we want to throw an error or warning for the old "if" nodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing with Sol, we will be showing a warning message on the "If" node when an old graph is opened..

Screen Shot 2021-02-16 at 10 52 22 AM

@Amoursol
Copy link
Contributor

Amoursol commented Feb 10, 2021

@reddyashish Can we get a build of Dynamo including the NewIf node? That way we get get some feedback from users prior to merge.

@QilongTang
Copy link
Contributor

@reddyashish Can we get a build of Dynamo including the NewIf node? That way we get get some feedback from users prior to merge.

We can get a branch build out of this work for sure. Is this PR in a good state? If yes, we can merge into a feature branch and start from there

@reddyashish
Copy link
Contributor Author

reddyashish commented Feb 11, 2021

@Amoursol Yes, we can get the branch build like Aaron suggested. I have added tests and this PR is pending review. Just need to figure out a proper name for this name.

@Amoursol
Copy link
Contributor

@Amoursol Yes, we can get the branch build like Aaron suggested. I have added tests and this PR is pending review. Just need to figure out a proper name for this name.

We can also crowd-source that name from the Forum with a testable build 😄 Can you let me know when you have a Branch build up?

Copy link
Contributor

@QilongTang QilongTang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one comment

@reddyashish
Copy link
Contributor Author

Just waiting for the self-serve to confirm no regressions.

@aparajit-pratap
Copy link
Contributor

⚠️
I don't think we have got input from @Amoursol about 3 things for this node:

  1. partial function support
  2. Lacing
  3. list-at-level
    These would need more work. Also if we need partial function support, we might not be able to go with the approach in this PR ⚠️

@Amoursol
Copy link
Contributor

⚠️
I don't think we have got input from @Amoursol about 3 things for this node:

  1. partial function support
  2. Lacing
  3. list-at-level
    These would need more work. Also if we need partial function support, we might not be able to go with the approach in this PR ⚠️

Can we please get a working build to let users test against? We can put that into the forum thread and get direct feedback before merging the PR, as noted above in a previous comment :)

@reddyashish
Copy link
Contributor Author

@aparajit-pratap @Amoursol To get a build, we will need to merge it to a feature branch atleast. We will not be merging this to master yet as will do that after the feedback. What do you guys think?

@reddyashish reddyashish changed the base branch from master to RefactoredIfNode February 16, 2021 17:36
@reddyashish
Copy link
Contributor Author

Changed the base to point to a new branch "RefactoredIfNode".

@Amoursol
Copy link
Contributor

Changed the base to point to a new branch "RefactoredIfNode".

Awesome. Are you able to create a Sandbox build for users to test please @reddyashish?

@QilongTang
Copy link
Contributor

@reddyashish Go for it. Let me know if you have any question in terms of creating branch build after merging into feature branch

@aparajit-pratap
Copy link
Contributor

@aparajit-pratap @Amoursol To get a build, we will need to merge it to a feature branch atleast. We will not be merging this to master yet as will do that after the feedback. What do you guys think?

Ok, I thought this was ready to be merged into master. If this is going into a feature branch for some user testing, then that sounds good.

@reddyashish reddyashish merged commit 218867e into DynamoDS:RefactoredIfNode Feb 16, 2021
@reddyashish reddyashish mentioned this pull request Jun 2, 2021
8 tasks
reddyashish added a commit that referenced this pull request Jun 8, 2021
* Adding a new "IF" node that would simply return the truevalue or falsevalue based on the test condition.  (#11481)

* attempt1 at creating partially applied function

* change implementation of If NodeModel node

* Move the functionality to a new if node that will be renamed.

* Update IfTest.cs

* Hiding the old If node and renaming to the new one to have the same  name.

* Throw a warning message when the old node is opened.

* add comments.

* Update the warning message and move it to the resources file.

* Fix failing test

Co-authored-by: Aparajit Pratap <[email protected]>

* Add list level and lacing functionality to the new "If" node. (#11598)

* Add lacing feature to the "If" node.

* Addressing comments

* additional comments

* Move code into a private function.

* Add tests for the new IF node.

* Update one of the If tests.

* Update the test.

* Add the If node icon to the new node.

* Changes to the Icon image

* Update the IconUrl

Co-authored-by: Aparajit Pratap <[email protected]>
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 this pull request may close these issues.

5 participants