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

Advanced exclusion syntax #2258

Merged
merged 17 commits into from
May 23, 2017
Merged

Conversation

dvalters
Copy link
Contributor

@dvalters dvalters commented Apr 28, 2017

Implements remaining features in issue #1960.

Exclusions can already be a simple list of points (as in PR #2244), but can now also be any valid datetime sequence.

3) Partial datetime (datetime recurrence) exclusion:

  • [[[ PT1H ! T12 ]]] Run hourly but not at 12:00 (from the ICP)
  • [[[ T-00 ! (T00, T06, T12, T18) ]]] Run hourly but not at 00:00, 06:00, 12:00, 18:00
  • [[[ PT5M ! T-15 ]]] Run 5 minutely but not at 15 minutes past the hour (from the ICP)
  • [[[ T00 ! W-1T00 ]]] Run daily at 00:00 except on Mondays

4) Sequences exclusion:

  • [[[ PT1H ! PT6H ]]] Run hourly (from the ICP) but not 6 hourly (from the ICP)
  • [[[ T-00 ! PT6H ]]] Run hourly on the hour but not 6 hourly on the hour
    • Same as [[[ T-00 ! T-00/PT6H ]]] (the T-00 context is implied for the excluded sequence)
    • Same as [[[ T-00 ! (T00, T06, T12, T18) ]]]
    • Same as [[[ PT1H ! (T00, T06, T12, T18) ]]] (ICP Dependent)
  • [[[ T12 ! T12/P15D ]]] Run daily at 12:00 except every 15th day
  • The exclusion(s) could be any valid recurrence (would we want to do this?)
    • e.g. [[[ R/^/P1H ! R5/20000101T00/P1D ]]]

Also adds an extra test suite advanced_exclusions to test-battery.

@dvalters
Copy link
Contributor Author

dvalters commented Apr 28, 2017

I need to update the user guide to reflect these changes (edit: done)

@dvalters dvalters self-assigned this Apr 28, 2017
@matthewrmshin matthewrmshin added this to the next release milestone Apr 28, 2017
if excl_off:
exclusion_point += excl_off
exclusion_points.append(exclusion_point)
except:
Copy link

Choose a reason for hiding this comment

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

  • To catch any exception use the except Exception, instead of except BaseException or just except.
  • Indicate the most specific exception type in except block.

For example:

# Bad
try:
    mapping[key]
except Exception:
    ...

# Better
try:
    mapping[key]
except KeyError:
    ...

@dvalters
Copy link
Contributor Author

dvalters commented May 8, 2017

(Some issues pointed out to fix first, so don't review/merge yet if you've not started.)

@dvalters dvalters force-pushed the advanced-exclusion-syntax branch from 33339df to 16b49bf Compare May 11, 2017 15:48
@dvalters
Copy link
Contributor Author

This has been refactored now so that the individual exclusion sequences are not separate types - they are the same class as the ISO8601Sequence type, just treated as exclusions.

if ',' in exclusions:
if (not exclusions.strip().startswith('(') or not
exclusions.strip().endswith(')')):
raise Exception("'%s': a list of exclusions must be "
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oliver-sanders you may have spaces before and after parentheses now.

@oliver-sanders
Copy link
Member

I'm afraid I've found a bug.

[[[T-00 ! 2000]]]  # This works.
[[[T-00 ! (2000, PT2H)]]]  # This doesn't!

@dvalters
Copy link
Contributor Author

OK, it will require a few changes if you want to combine points and sequences in the same exclusion list. Will have a look next week.

@dvalters
Copy link
Contributor Author

dvalters commented May 12, 2017

You should be able to combine exclusion types in this format now: T-00 ! (2000, PT2H)

[[[T-00 ! 2000]]]  # This works.
[[[T-00 ! (2000, PT2H)]]]  # <-- This should work now.

@hjoliver
Copy link
Member

This is looking really good. One question about integer cycling. By analogy with [[[PT1H ! PT6H]]] I presume [[[P1 ! P6]]] should work - but it doesn't?

@dvalters
Copy link
Contributor Author

I will see if I can get this implemented today - requires some changes for integer sequence exclusions to be valid.

@oliver-sanders
Copy link
Member

oliver-sanders commented May 15, 2017

@hjoliver The syntax is [[[R/P1!6]]] (#1928 added exclusions for integer cycling cug). Sorry hadn't read your comment properly.

@dvalters
Copy link
Contributor Author

Integer sequence exclusions now implemented.

@hjoliver hjoliver modified the milestones: soon, next release May 15, 2017
Copy link
Member

@oliver-sanders oliver-sanders left a comment

Choose a reason for hiding this comment

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

This is working for me! I've a few comments but otherwise it looks good.


try:
self.p_iso_exclusions.append(
point_parse(str(exclusion_point)))
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose of this point_parse(str(point))?

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, it is redundant - removed

@@ -281,9 +281,64 @@ def _iso_interval_nonzero(interval_string):
return bool(interval)


class ISO8601Exclusions(object):
Copy link
Member

Choose a reason for hiding this comment

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

The IntegerExclusions and ISO8601Exclusions classes look pretty much identical now. cylc.cycling.loader provides abstractions for points/sequences, would it be possible to use this to consolidate these two classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored as much as possible in latest commit

graph = wibble

# Run hourly at 15 minutes past except every 3rd hour
[[[ T-15!T-15/PT3H ]]]
Copy link
Member

Choose a reason for hiding this comment

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

I would be good to test the implicit version here too (T-15!PT3H).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the implicit case too

# Stacked sequences
[[[ T0230, PT3H!(T09,T12), T1945 ]]]
graph = dibble
[runtime]
Copy link
Member

Choose a reason for hiding this comment

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

It would also be a good idea to add a test here with some arbitrary white-space around parenthesis to test for the parsing problem we had earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some arbitrary whitespace to one of these suite tests. (This is tested in the unit tests already - under the integer ones - which all use the same parse method to strip the whitespace/parentheses.

graph = bar
[[[ P1 !(P2,6,8) ]]]
graph = qux
[runtime]
Copy link
Member

Choose a reason for hiding this comment

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

Could we add a test for implicit start/end context for integer cycling as well e.g. R/1/P2!P3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

@hjoliver
Copy link
Member

(this is generally looking good to me, just waiting for Oliver's points to be addressed before a final review)

@dvalters dvalters force-pushed the advanced-exclusion-syntax branch from 05157aa to 6a443b4 Compare May 19, 2017 16:31
@dvalters
Copy link
Contributor Author

dvalters commented May 19, 2017

Will finish adding the remaining extra tests next week.

Added extra tests now.

@dvalters dvalters force-pushed the advanced-exclusion-syntax branch from 6a443b4 to c8dba9e Compare May 19, 2017 17:08
Copy link
Member

@oliver-sanders oliver-sanders left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Member

@hjoliver hjoliver left a comment

Choose a reason for hiding this comment

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

Very nice.

@hjoliver hjoliver merged commit 1e078fe into cylc:master May 23, 2017
Copy link

@duboviy duboviy left a comment

Choose a reason for hiding this comment

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

It would be better to use here custom type of Exception instead of general Exception itself.

if ',' in exclusions:
if (not exclusions.strip().startswith('(') or not
exclusions.strip().endswith(')')):
raise Exception("'%s': a list of exclusions must be "
Copy link

@duboviy duboviy Aug 6, 2017

Choose a reason for hiding this comment

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

Same as mentioned above

expression3 = "T01/PT1H! PT8H, (T06, T09)"
expression4 = "T01/PT1H! T03, T06, T09"

self.assertRaises(Exception, parse_exclusion, expression1)
Copy link

Choose a reason for hiding this comment

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

Same as mentioned above

@hjoliver
Copy link
Member

hjoliver commented Aug 6, 2017

@duboviy - fair point, in general. Would you like to raise a Pull Request, or are you just "observing from afar"?

@duboviy
Copy link

duboviy commented Aug 9, 2017

@hjoliver just observing from afar

@matthewrmshin
Copy link
Contributor

Hi @duboviy Thanks for sending us your insight from afar 🔭 . Please rest assure that we are fixing these issues - as opportunities arise.

@duboviy
Copy link

duboviy commented Aug 9, 2017

@matthewrmshin great, thanks!

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