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

ISSUE-433: Behavior of rules sharing conditions within :or is incorrect #434

Merged
merged 3 commits into from
Sep 30, 2019

Conversation

EthanEChristian
Copy link
Contributor

For #433, i think this is the most straight forward approach.

cc. @WilliamParker @mrrodriguez

prev (get m node)]
;; appending parents to allow for identical conditions that do not share the same
;; parents, see Issue 433 for more information
node-with-parents (assoc node :parents (get backward-edges id))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm trying to rationalize this.

If we had a case like:

a   b
| |
c
| |
d e

where c was a common condition with, a and b as parents and d and e as children, it isn't safe to reuse the same c to propagate to the children d and e in all cases. Instead c needs to propagate to d, eg. only when it is receiving propagation from it's parent a, and similarly, perhaps e should only be propagated to when we are going from b > c > e.

I think this makes sense. c can't be shared in the propagation - or even working memory structure, due to propagation semantics - when it is coming from 2 logically separate parent paths.

So far I'm onboard with this change.

Copy link

@curtman16 curtman16 left a comment

Choose a reason for hiding this comment

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

LGTM

@EthanEChristian
Copy link
Contributor Author

The initial approach added 1 second onto the compilation performance test. This test was running in 2.3 seconds, so the addition of another second is probably not acceptable.

With the new changes the time is pretty much unchanged.

src/main/clojure/clara/rules/compiler.clj Outdated Show resolved Hide resolved
src/main/clojure/clara/rules/compiler.clj Outdated Show resolved Hide resolved
src/main/clojure/clara/rules/compiler.clj Show resolved Hide resolved
Copy link
Collaborator

@mrrodriguez mrrodriguez left a comment

Choose a reason for hiding this comment

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

Copy link
Collaborator

@mrrodriguez mrrodriguez left a comment

Choose a reason for hiding this comment

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

🔁

src/main/clojure/clara/rules/compiler.clj Outdated Show resolved Hide resolved
src/main/clojure/clara/rules/compiler.clj Outdated Show resolved Hide resolved
Copy link
Collaborator

@WilliamParker WilliamParker left a comment

Choose a reason for hiding this comment

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

I'm fairly confident this doesn't create regressions and solves the issue at hand. It has the downside of effectively preventing node sharing across productions but I don't see any straightforward way of solving the issue otherwise. In the somewhat longer term we should probably have a namespace with more extensive testing of node sharing both for correctness as here and that nodes are in fact shared in specific circumstances - I don't think we have the latter at present. I can probably work on that in the next few weeks unless someone else wants to, in the meantime +1 to merge of this and we can discuss a release if that would be useful.

node-id (or (when-let [common-nodes (get node->ids node)]
;; We need to validate that the node we intend on sharing shares the same parents as the
;; current node we are creating. See Issue 433 for more information
(some #(when (= (get backward-edges %)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The (set parent-ids) call could be at the time of the creation of the function object rather than each time it is called. Probably not a significant issue but I haven't tested it.

@@ -194,3 +194,31 @@
(is (has-fact? (:cold @side-effect-holder) (->Temperature -10 "MCI") ))

(is (has-fact? (:subzero @side-effect-holder) (->Temperature -10 "MCI")))))


Copy link
Collaborator

Choose a reason for hiding this comment

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

We could probably use a more extensive namespace for testing node sharing, both for when it is done and in scenarios like this, but this is an OK home to this test for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I presume this test fails without the change? On mobile at the moment so I can't test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, the e-query assertion fails prior to the changes in the PR

Copy link
Collaborator

@mrrodriguez mrrodriguez left a comment

Choose a reason for hiding this comment

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

🔄

@EthanEChristian EthanEChristian merged commit 0a76659 into oracle-samples:master Sep 30, 2019
@EthanEChristian EthanEChristian deleted the Issue433 branch September 30, 2019 13:33
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.

4 participants