Skip to content

Commit

Permalink
Merge pull request #36 from glotzerlab/short-circuit-all
Browse files Browse the repository at this point in the history
Employ short circuit logic in `group.include.all`.
  • Loading branch information
joaander authored Aug 21, 2024
2 parents b7f6490 + f3dc1e2 commit ecaafaf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions doc/src/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* `clean` now cleans all caches by default.
* Submit jobs with `--constraint="scratch"` by default on Delta.
* Submit jobs with `--constraint="nvme"` by default on Frontier.
* `group.include.all` now employs short circuit evaluation.
* Change `--name` option of `show cluster` to `--short`.
* `show directories` now accepts an optional `--action` argument.

Expand Down
20 changes: 10 additions & 10 deletions doc/src/workflow/action/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ groups of directories included in a given action.
## include

`action.group.include`: **array** of **tables** - Define a set of selectors, *any* of
which may be true for a directory to be included in this group.
which may be `true` for a directory to be included in this group.

Each selector is a **table** with only one of the following keys:
* `condition`: An array of three elements: The *JSON pointer*, *the operator*, and the
*operand*. The [JSON pointer](../../guide/concepts/json-pointers.md) references a
specific portion of the directory's value. The operator may be `"<"`, `"<="`,
`"=="`, `">="`, or `">"`.
* `all`: Array of conditions (see above). All conditions must be true for this selector
to be true.
`"=="`, `">="`, or `">"`. Both operands **must** have the same data type. The element
referenced by each JSON pointer must be present in the value of **every** directory.
* `all`: Array of conditions (see above). All conditions must be `true` for this selector
to be `true`. `all` is evaluated with short-circuit logic. When an element in `all`
evaluates to `false`, the JSON pointers in the remaining elements are not evaluated
and are not required to be present.

For example, select all directories where a value is in the given range:
```toml
Expand All @@ -54,18 +57,15 @@ Compare by array:
condition = ["/array", "==", [1, "string", 14.0]
```

Both operands **must** have the same data type. The element referenced by JSON pointer
must be present in the value of **every** directory.

When you omit `include`, **row** includes **all** directories in the workspace.

> Note: **Row** compares arrays *lexicographically*.

<div class="warning">
JSON Objects (also known as maps or dictionaries) are not comparable. You must use
pointers to specific keys in objects.
</div>

When you omit `include`, **row** includes **all** directories in the workspace.

## sort_by

`action.group.sort_by`: **array** of **strings** - An array of
Expand Down Expand Up @@ -122,7 +122,7 @@ would split into the groups:

When omitted, there is no maximum group size.

When `maximum_size` is set **and** `split_by_sort_key` is `true`, **row** first splits
When both `maximum_size` **and** `split_by_sort_key` are `true`, **row** first splits
by the sort key, then splits the resulting groups according to `maximum_size`.

## submit_whole
Expand Down
5 changes: 3 additions & 2 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl Project {
Error::JSONPointerNotFound(name.clone(), include.clone())
})?;

if expr::evaluate_json_comparison(comparison, actual, expected)
if !expr::evaluate_json_comparison(comparison, actual, expected)
.ok_or_else(|| {
Error::CannotCompareInclude(
actual.clone(),
Expand All @@ -220,8 +220,9 @@ impl Project {
)
})?
{
matches += 1;
break;
}
matches += 1;
}
Ok(matches == conditions.len())
}
Expand Down

0 comments on commit ecaafaf

Please sign in to comment.