Skip to content

Resolve "Devise a simple mathematical expression parser for DAG transformations"

This MR:

  • adds the expression operation, which evaluates a symbolic math expression using sympy
  • adds operation-specific syntax parsers to the DAG syntax parser
  • adds an expression-operation parser that automatically uses DAGTags for unspecified symbols

Subsequently, it makes the following syntax possible:

transform:
  - mean: [[1, 2, 3]]    # something more complicated, typically
    tag: a
  - np.array: [[2,3,4]]  # something more complicated, typically
    tag: b
  - operation: some_other_complicated_operation
    args: [foo, bar]
    tag: c
  - float: 2.5
  - expression: (a + b)**c - 1.23 * exp(prev)
    tag: result

... where a, b, c are converted to DAGTag(..) and prev is converted to DAGNode(-1) (equivalent of !dag_prev). Of course, in real use cases, all DAG references will be more complicated expressions than the ones given here.

Anything to double-check?

  • Should the convert_xor transformation be given by default?
    • If yes: Does not allow XOR operations using the ^ operator; ^ will behave the same as **.
    • If not: Allows XOR operations, but could be confusing because one can only use ** for powers. (We chose this option!)
  • Documentation sufficient?
  • There are a number of pitfalls with using the symbolic expression parser... is this whole feature too complicated perhaps? Nope, fine. It's a bit of an advanced feature anyway.

Can this MR be accepted?

  • Implementation ready
  • Tests added or adjusted
  • Documentation extended or updated
  • Code quality

Related issues

Closes #149 (closed)

Edited by Utopia Developers

Merge request reports