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

[HOTFIX] Constraints Any semantics should preserve false #373

Merged
merged 2 commits into from
Oct 13, 2022

Conversation

mattdailis
Copy link
Collaborator

@mattdailis mattdailis commented Oct 13, 2022

  • Tickets addressed: N/A
  • Review: By commit
  • Merge strategy: Merge (no squash)

Description

This case was discovered by @camargo in preparation for a demo. A constraint similar to the following was never returning violations:

export default (): Constraint => {
  return Constraint.ForEachActivity(ActivityType.grandchild, 
    instance => Discrete.Resource("/flag").equal("B").if(instance.window()));
}

As a reminder, the x.if(y) is syntactic sugar for Any(not y, x).

I stepped through the debugger and found that the Any node was converting false into null in the following case:

(Assume that /flag is never equal to "B")

  1. Instance.window produces three intervals: (Duration.MIN, start time, FALSE), (start time, end time, TRUE), and (end time, Duration.MAX, FALSE) (I'm being imprecise with my 'clusivity because it's irrelevant to my point)
  2. The Invert correctly swaps TRUE with FALSE and vice versa above, resulting in (Duration.MIN, start time, TRUE), (start time, end time, FALSE), and (end time, Duration.MAX, TRUE)
  3. We get up to the Any node, and we immediately OR these three intervals with the empty Windows object (which is null everywhere). This drops the FALSE interval, losing the crucial information we needed to check this constraint.
  4. We emerge from Any with (Duration.MIN, start time, TRUE), (end time, Duration.MAX, TRUE) and we say that there are no violations, since there are no FALSE intervals.

The change I'm proposing is that the Any node should start with the interval FOREVER, FALSE (the identity value for "OR"). This seems reasonable to me, but I'd like feedback from people who have spent more time thinking about this @JoelCourtney @Twisol .

Verification

I updated testOr to check that a false interval in both left and right should be preserved by Any(left, right). This test fails until the next commit, after which it passes.

Documentation

Do we have documentation for how nullable windows behave?

Future work

None

@mattdailis mattdailis self-assigned this Oct 13, 2022
@mattdailis mattdailis requested a review from a team as a code owner October 13, 2022 18:41
@mattdailis mattdailis temporarily deployed to e2e-test October 13, 2022 18:41 Inactive
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Automatically approved due to detection of the following labels: hotfix

@Twisol
Copy link
Contributor

Twisol commented Oct 13, 2022

The change I'm proposing is that the Any node should start with the interval FOREVER, FALSE (the identity value for "OR").

You're definitely right. As an edge case, consider Any over the empty list of constraints. Producing NULL makes no sense, because we definitely know that no constraint in the list (all zero of them) is true -- there is nothing that could change, no missing input we lack to give a more precise answer.

@JoelCourtney
Copy link
Contributor

JoelCourtney commented Oct 13, 2022

I have these changes in my branch for gaps in external profiles. There's a couple erroneous and calls that should be select too. Its this commit

@JoelCourtney
Copy link
Contributor

What I mean to say is, if you could take all of those changes and use them in this PR, that would be great. Then I can drop that commit from my branch, cuz it should've been a separate PR to begin with, like this. Thanks!

@mattdailis
Copy link
Collaborator Author

mattdailis commented Oct 13, 2022

What I mean to say is, if you could take all of those changes and use them in this PR, that would be great. Then I can drop that commit from my branch, cuz it should've been a separate PR to begin with, like this. Thanks!

Thanks for the quick review 👍 I'm super down to pull your changes. I tried cherry-picking that commit, and it's failing my "false pass through" test case. It seems like select drops the false as well, and replaces it with null - so maybe Any should use and, not select? Or am I misunderstanding select?

EDIT: Nevermind! It was a mistake on my end. Comment below.

@mattdailis mattdailis force-pushed the hotfix/any-semantics-preserve-false branch from 9ab38e9 to ca6038e Compare October 13, 2022 19:47
@mattdailis mattdailis temporarily deployed to e2e-test October 13, 2022 19:47 Inactive
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Automatically approved due to detection of the following labels: hotfix

@mattdailis
Copy link
Collaborator Author

Force push replaces new Windows(Segment.of(Interval.FOREVER, false)); with new Windows(false).

@mattdailis
Copy link
Collaborator Author

Nevermind! I had neglected to extend the bounds of the simulation results. select was doing its job just fine 👍

mattdailis and others added 2 commits October 13, 2022 13:05
If an interval is associated with false in all inputs to Any, it
should continue to be associated with false in the result.
@mattdailis mattdailis force-pushed the hotfix/any-semantics-preserve-false branch from ca6038e to c921246 Compare October 13, 2022 20:09
@mattdailis mattdailis temporarily deployed to e2e-test October 13, 2022 20:09 Inactive
@mattdailis
Copy link
Collaborator Author

What I mean to say is, if you could take all of those changes and use them in this PR, that would be great. Then I can drop that commit from my branch, cuz it should've been a separate PR to begin with, like this. Thanks!

Done 👍

Copy link
Contributor

@JoelCourtney JoelCourtney left a comment

Choose a reason for hiding this comment

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

Awesome! This brings up a bit of future work, where I'd like to stop using select(bounds) so aggressively after every operation, because it will lose any information that should get shiftBy'ed into the plan bounds.

i.e. don't do an activity for an hour after a certain resource condition that occurred before plan start. But that's a different task.

@mattdailis mattdailis merged commit f0e8070 into develop Oct 13, 2022
@mattdailis mattdailis deleted the hotfix/any-semantics-preserve-false branch October 13, 2022 21:07
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.

3 participants