Skip to content

Commit

Permalink
small ΔQ update
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuhn committed Oct 1, 2024
1 parent 088d46d commit f8aec9d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
35 changes: 35 additions & 0 deletions Logbook.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# Leios logbook

## 2024-10-01

Report on ΔQ work in Rust so far (Roland):

- implemented MVP in the sense of being able to create ΔQ expressions as per the “Mind your outcomes” paper and evaluate them
- added a recursion operator that is purely syntactical: recursive unfolding of a named expression with a given depth limit
- project uses yew/trunk to render the HTML/CSS frontend, which uses WASM (tools were chosen for convenience, not minimalism)
- ΔQ evaluation currently done in server process, but could also be moved into the web part (should use web worker to stay responsive)

Implementation notes:

- CDF is represented as a list of f32 tuples, with a size limit of 1000 (tunable) after which the step function will be simplified (i.e. approximated)
- this simplification can be done in over- or under-approximation mode; running both and showing the difference will illustrate the error range
- tuples are pruned in increasing order of their distance to the right neighbour, with two complications:
1. distances are binned to some precision to avoid dominating the selection by floating-point precision limits
2. the algorithm pulls pruning candidates from a heap but skips every second one of the same distance; this yields more even pruning along the x axis
- the EvaluationContext holds all named expressions and allows resolving names, but also tracks the current recursion allowance for each name
(recursion with allowance isn’t allowed while already recursing on that name; allowing this results in infinite loop)

Comments raised while presenting this to the team today:

- syntax should stay closer to the original paper (I deviated in order to allow normal people to type in expressions with their keyboard)
- this could be done by having aliases and supporting the entry of special glyphs with a palette on the web page
- showing recursion as exponentiation is surprising, Andre expected exponentiation to be just some form of repeated multiplication (but unclear which operation that would be)
- recursion as template unfolding was understood as some fix point representation by Duncan, but currently that is not how it is implemented
- treating the propagation of messages across a network graph isn’t faithfully modelled, but it could be if recursion was actually some kind of fix point operation
- it would be great to have an operator that expresses “only broadcast the first copy of the message I receive”, which would allow pruning the infinite evaluation tree
- this is unclear to me because ΔQ speaks in CDFs which aren’t concrete in this way, so pruning wouldn’t apply to CDFs but to some execution of the modelled process
- Pi asked how this work relates to the Rust-based network graph simulator, which has at least two answers:
- compute CDFs that are used by the simulator using ΔQ
- use simulation results (CDFs) as inputs for further ΔQ modelling, e.g. on a higher level
- on the website we’ll need something that can quickly answer high-level questions, running a simulation would probably not be feasible but ΔQ should be
- it occurred to me that if we can get a load profile from a ΔQ model, we can then use queueing theory to compute the effect on latencies to get a better approximation of overall system behaviour
- these two steps can be run alternatingly to see if there is a fix point for the result — and if the computation diverges, that tells us that the network graph would die from overload

## 2024-09-30

Catching-up on Leios ΔQ work:
Expand Down
11 changes: 11 additions & 0 deletions delta_q/models.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This file contains several formulas that may or may not model some systems described in some papers.

1 -- TR1 wrong Cardano model

hop := CDF[(0.012, 0.333), (0.069, 0.666), (0.268, 1)] ->- CDF[(0.024, 0.333), (0.143, 0.666), (0.531, 1)]
prop := hop 1<>99 hop ->- hop 5<>94 hop ->- hop ->- hop 34<>60 hop ->- hop ->- hop ->- hop 59<>1 hop ->- hop ->- hop ->- hop ->- hop

2 -- TR1 used Cardano model

hop := CDF[(0.012, 0.333), (0.069, 0.666), (0.268, 1)] ->- CDF[(0.012, 0.333), (0.069, 0.666), (0.268, 1)] ->- CDF[(0.012, 0.333), (0.069, 0.666), (0.268, 1)] ->- CDF[(0.024, 0.333), (0.143, 0.666), (0.531, 1)]
prop := hop 0.6<>99.4 hop ->- hop 8.58<>90.82 hop ->- hop ->- hop 65.86<>24.96 hop ->- hop ->- hop ->- hop
2 changes: 1 addition & 1 deletion delta_q/src/cdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl<'a> Iterator for CDFIterator<'a> {
} else if self.last {
self.last = false;
let (x, y) = self.prev;
Some((x * 1.2, y))
Some(((x * 1.2).max(0.1), y))
} else {
None
}
Expand Down
16 changes: 7 additions & 9 deletions delta_q/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,11 @@ fn cdf(input: &mut &str) -> PResult<DeltaQ> {
cut_err(
separated::<_, _, (), _, _, _, _>(
0..,
cut_err(
(ws, '(', ws, num, ws, ',', ws, num, ws, ')')
.context(StrContext::Label("CDF literal"))
.context(StrContext::Expected(StrContextValue::Description(
"CDF[(<num>, <num>), ...]",
))),
),
(ws, '(', ws, num, ws, ',', ws, num, ws, ')')
.context(StrContext::Label("CDF literal"))
.context(StrContext::Expected(StrContextValue::Description(
"CDF[(<num>, <num>), ...]",
))),
(ws, ','),
)
.take()
Expand Down Expand Up @@ -165,8 +163,8 @@ enum Op {
impl Op {
fn bp(&self) -> (u8, u8) {
match self {
Op::Seq => (1, 2),
Op::Choice { .. } => (3, 4),
Op::Choice { .. } => (2, 1),
Op::Seq => (3, 4),
}
}
}
9 changes: 7 additions & 2 deletions delta_q/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ fn branch(props: &BranchProps) -> Html {

pub fn cdf_to_svg(cdf: &CDF) -> Html {
let mut canvas = Canvas::new(310.0, 110.0);
let x_scale = 300.0 / cdf.width();
let width = cdf.width();
let x_scale = 300.0 / (width * 1.2).max(1.1);
canvas.polyline(Polyline {
color: Some(Color::black()),
stroke_width: 1.0,
Expand All @@ -415,7 +416,11 @@ pub fn cdf_to_svg(cdf: &CDF) -> Html {
y: (1.0 - y) * 100.0 + 1.0,
},
Point {
x: x2 * x_scale + 10.0,
x: if x2 > width {
310.0
} else {
x2 * x_scale + 10.0
},
y: (1.0 - y) * 100.0 + 1.0,
},
]
Expand Down

0 comments on commit f8aec9d

Please sign in to comment.