hpcflow.sdk.core.rule.Rule#

class hpcflow.sdk.core.rule.Rule(check_exists=None, check_missing=None, path=None, condition=None, cast=None, doc=None)#

Bases: JSONLike

Class to represent a testable condition on an element iteration or run.

Exactly one of check_exists, check_missing and condition must be provided.

Parameters:
  • check_exists (str) – If set, check this attribute exists.

  • check_missing (str) – If set, check this attribute does not exist.

  • path (str) – Where to look up the attribute to check. If not specified, determined by context.

  • condition (ConditionLike) – A general condition to check (or kwargs used to generate one).

  • cast (str) – If set, a cast to apply prior to running the general check.

  • doc (str) – Optional descriptive text.

Methods

from_json_like

Make an instance of this class from JSON (or YAML) data.

test

Test if the rule evaluates to true or false for a given run, or element iteration and action combination.

to_dict

Serialize this object as a dictionary.

to_json_like

Serialize this object as an object structure that can be trivially converted to JSON.

Attributes

condition

A general condition for this rule to check.

check_exists

If set, this rule checks this attribute exists.

check_missing

If set, this rule checks this attribute does not exist.

path

Where to look up the attribute to check (if not determined by context).

cast

If set, a cast to apply prior to running the general check.

doc

Optional descriptive text.

cast#

If set, a cast to apply prior to running the general check.

check_exists#

If set, this rule checks this attribute exists.

check_missing#

If set, this rule checks this attribute does not exist.

condition#

A general condition for this rule to check.

doc#

Optional descriptive text.

classmethod from_json_like(json_like, shared_data=None)#

Make an instance of this class from JSON (or YAML) data.

Parameters:
  • json_like (str | Mapping[str, JSONed] | Sequence[Mapping[str, JSONed]] | None) – The data to deserialise.

  • shared_data (Mapping[str, ObjectList[JSONable]] | None) – Shared context data.

Return type:

The deserialised object.

path#

Where to look up the attribute to check (if not determined by context).

test(element_like, action=None)#

Test if the rule evaluates to true or false for a given run, or element iteration and action combination.

Parameters:
Return type:

bool

to_dict()#

Serialize this object as a dictionary.

Return type:

dict[str, Any]

to_json_like(dct=None, shared_data=None, exclude=(), path=None)#

Serialize this object as an object structure that can be trivially converted to JSON. Note that YAML can also be produced from the result of this method; it just requires a different final serialization step.

Parameters:
  • dct (dict[str, JSONable] | None) –

  • shared_data (_JSONDeserState) –

  • exclude (Container[str | None]) –

  • path (list | None) –

Return type:

tuple[JSONDocument, _JSONDeserState]