feat(py): expose quantitative semantics

This commit is contained in:
Anand Balakrishnan 2023-05-03 16:38:35 -07:00
parent bfb59c1008
commit 9f674bd385
No known key found for this signature in database

View file

@ -1,7 +1,7 @@
use std::collections::HashMap;
use argus_core::signals::{AnySignal, Signal};
use argus_semantics::{BooleanSemantics, Semantics, Trace};
use argus_semantics::{BooleanSemantics, QuantitativeSemantics, Semantics, Trace};
use pyo3::exceptions::PyTypeError;
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyString};
@ -87,10 +87,16 @@ fn eval_bool_semantics(expr: &PyBoolExpr, trace: &PyTrace) -> PyResult<Py<BoolSi
let sig = BooleanSemantics::eval(&expr.0, trace, ()).map_err(PyArgusError::from)?;
Python::with_gil(|py| Py::new(py, (BoolSignal::from(sig), BoolSignal::super_type())))
}
#[pyfunction]
fn eval_robust_semantics(expr: &PyBoolExpr, trace: &PyTrace) -> PyResult<Py<FloatSignal>> {
let sig = QuantitativeSemantics::eval(&expr.0, trace, ()).map_err(PyArgusError::from)?;
Python::with_gil(|py| Py::new(py, (FloatSignal::from(sig), FloatSignal::super_type())))
}
pub fn init(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<PyTrace>()?;
m.add_function(wrap_pyfunction!(eval_bool_semantics, m)?)?;
m.add_function(wrap_pyfunction!(eval_robust_semantics, m)?)?;
Ok(())
}