0.1.28 • Published 11 months ago

publiopti v0.1.28

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

CI NPM

publiopti is a set of optimisation passes for models based on Publicodes.

:warning: The project is currently in under experimentation by the Nos Gestes Climat team. :warning:

Why?

Publicodes based projects are built by design to be fully transparent and intelligible for the most people. This means to be open-source, but especially to be as detailed as possible in the calculation.

Consequently, a severe complexity of the models start to appears. However, this complexity is only justified for the documentation not for the computation/simulation it self.

For example, considering the following rule alimentation . déchets . niveau moyen:

alimentation . déchets . niveau moyen:
  formule:
    somme:
      - omr
      - collecte separee
      - dechetterie
      - gestes
  description: |
    Ce niveau correspond à la moyenne française.

This rule allows to compute the average level of food waste produced by a French person. This value doesn't depend on any user inputs: it's the same for every simulation. Therefore, it's possible to compute the value at compile time and to simplify the model used by the browser.

Installation

npm install --dev-dependency publiopti

yarn add -D publiopti

Usage

import Engine from 'publicodes'
import { constantFolding, getRawNodes } from 'publiopti'

const optimizedRules = constantFolding(
  // A publicode engine instantiated with the rules to optimize.
  new Engine(baseRules),
  // A predicate returning true if the rule needs to be kept.
  ([ruleName, ruleNode]) => {
    return ['root', 'root . bis'].includes(ruleName) ||  ruleNode.rawNode['to keep']
  }
)

Under the hood

Currently, only one optimisation pass is available: the constant folding one.

Constant folding consists in calculating at compile time the value of an expression and replacing them in all its references. After this step, if a rule is no longer used by any other rules, it's deleted -- unless the toKeep attribute is provided.

0.1.27

11 months ago

0.1.28

11 months ago

0.1.26

11 months ago

0.1.25

1 year ago

0.1.24

1 year ago

0.1.23

1 year ago

0.1.22

1 year ago

0.1.21

1 year ago

0.1.20

1 year ago

0.1.19

1 year ago

0.1.18

1 year ago

0.1.17

1 year ago

0.1.16

1 year ago

0.1.15

1 year ago

0.1.14

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago