Python ↔ MATLAB¶
ddma has two interfaces on one C++ core. Every feature exists in both, and the MATLAB results are tested against Python reference results in CI (matlab/tests/run_tests.m, reference data written by matlab/tests/make_reference.py; run under Octave on every push).
Python uses classes; MATLAB uses functions on structs (S = ddma.bd_update(S, ...)). The table maps one to the other.
Models¶
Python |
MATLAB |
Tested against Python |
|---|---|---|
|
|
exact |
|
|
exact (single, rounded outward) |
|
|
exact |
|
|
exact |
|
|
exact |
|
|
exact |
|
|
exact |
|
concatenate the data: |
— |
|
|
≤ 1e-15 (all five methods, |
|
|
≤ 1e-9 |
|
|
≤ 1e-9 |
|
|
≤ 1e-9 |
|
|
same LP optimum on the same pairs |
|
|
exact |
The data of bd_fit are Z = [X U] and Y = X' - g(X, U), as for ddma.fit (ddma.transitions_to_data); the known part g goes to ddma.abstraction as g_bounds.
Abstractions and synthesis¶
Python |
MATLAB |
Tested against Python |
|---|---|---|
|
|
exact transitions (C++ kernel on all threads by default; |
|
|
same winning set and inputs |
|
|
exact (mask, transitions) |
|
|
exact |
|
|
exact |
|
|
exact |
|
|
same inputs |
|
|
same trajectory |
|
|
exact |
Reinforcement learning¶
Python |
MATLAB |
Tested against Python |
|---|---|---|
|
|
same safe actions (300 random states) |
|
|
same dynamics and reward |
Assumption monitor¶
Python |
MATLAB |
Tested against Python |
|---|---|---|
|
|
same counts, worst pair, conflicts, needed changes |
|
|
— |
|
|
— |
|
|
same slope intervals |
|
|
same violations, levels, gaps (≤ 1e-12), witnesses and |
|
|
same violations |
|
|
— |
|
|
≤ 1e-12 |
|
|
same widened bounds |
|
|
same quarantine flags |
|
|
same verdict |
|
|
— |
|
|
same fallback |
pair checks in C++ ( |
MEX |
MEX = |
Tests: matlab/tests/run_monitor_tests.m (reference written by matlab/tests/make_reference_monitor.py).
Safe envelopes (no grid)¶
Python |
MATLAB |
Tested against Python |
|---|---|---|
|
|
same corners and (corner, input) pairs |
|
|
same boxes, input boxes and pairs |
returned objects |
structs with the same fields |
— |
|
|
same on 2,000 states |
|
|
same inputs |
|
|
equal |
Tests: matlab/tests/run_invariance_tests.m (reference written by matlab/tests/make_reference_invariance.py).
Threads¶
Python |
MATLAB |
Tested |
|---|---|---|
|
|
same bits for 1, 2 and all threads ( |
|
|
— |
|
|
— |
See PERFORMANCE.md.
Partitions and plots¶
Python |
MATLAB |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Helpers¶
MATLAB needs a few small functions that Python gets from NumPy or keeps internal:
Python |
MATLAB |
|---|---|
|
|
|
|
|
|
|
|
internal: successor-box test of the synthesis |
|
internal: certified LP bound of the |
|
Examples¶
Python ( |
MATLAB ( |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tutorial 4 of the docs ( |
|
The examples use random data, so the two languages draw different samples and print slightly different numbers; on the same data the results are equal (tested).
Differences that remain¶
Paper reproductions (
reproductions/) are Python scripts;matlab/examples/paper_figures.mredraws the paper figures in MATLAB.LP final steps (
'lin_mono','lin_growth') andestimate_derivative_boundsneedlinprog(Optimization Toolbox) in MATLAB; Octave hasglpkbuilt in. The LP bounds are certified by weak duality in both languages, so they are sound whatever the solver.RL training in MATLAB needs the Reinforcement Learning Toolbox; ddma’s filter functions do not, and the MATLAB example runs without it.
Compiled kernels: Python builds them on install; MATLAB with
build_mex(plain MATLAB code is used otherwise, with the same results). Both use threads (OpenMP) when the compiler supports it; the plain MATLAB code runs on one thread.