Skip to main content

CompiledProgram

Struct CompiledProgram 

Source
pub struct CompiledProgram { /* private fields */ }

Implementations§

Source§

impl CompiledProgram

Source

pub fn evaluate( &self, _py: Python<'_>, return_grads: bool, samples: Option<usize>, seed: Option<u64>, confidence: f64, max_nonmonotone_iterations: usize, sampling_method: Option<String>, memory_mb: Option<u64>, allow_cpu_oracle: bool, ) -> PyResult<EvalResult>

Source

pub fn prob_var_map(&self, py: Python<'_>) -> PyResult<Vec<Py<PyAny>>>

Which probabilistic fact each CNF variable stands for.

The returned list’s length is the CNF encoder’s variable capacity, not the number of CNF variables in use and not the number of random variables in the program — a real fraction of entries are {"kind": "other"} padding (do not use len() of the result as a variable count). Entry i describes CNF variable i — the same position i that the grad_true / grad_false vectors of evaluate(return_grads=True) use (index 0 is unused padding, since CNF variables are 1-indexed).

For a "choice" entry (one Bernoulli decision of an annotated disjunction’s chain), probs[choice_index] is the disjunction’s declared, marginal probability and is display context only; prob is the conditional Bernoulli parameter actually assigned to this variable’s weight, and prob * (1 - prob) — not probs[choice_index] * (1 - probs[choice_index]) — is the correct Jacobian for grad_true / grad_false at this position.

Raises ValueError for Monte Carlo programs, and for exact programs compiled through the GPU count-lift fast path (count aggregates without evidence or annotated disjunctions), since that path never builds a CNF encoding and therefore has no variable map to report — this is not the same as the program having no probabilistic facts.

Source

pub fn evaluate_device( &self, py: Python<'_>, samples: Option<usize>, seed: Option<u64>, confidence: f64, max_nonmonotone_iterations: usize, sampling_method: Option<String>, memory_mb: Option<u64>, ) -> PyResult<McDeviceEvalResult>

Evaluate Monte Carlo programs and return device-only result counts via DLPack.

This is the primary GPU-native API surface for MC inference. It never performs device->host reads for result data (only returns device buffers).

Source

pub fn zero_grad(&self, py: Python<'_>) -> PyResult<()>

Zero gradients for all registered networks.

This should be called at the start of each training iteration to clear accumulated gradients from previous iterations.

Source

pub fn optimizer_step(&self, py: Python<'_>) -> PyResult<()>

Perform optimizer step for all registered networks.

This applies the accumulated gradients to update network parameters. Should be called after forward_backward().

Source

pub fn clip_grad_norms(&self, py: Python<'_>, max_norm: f64) -> PyResult<()>

Clip gradient norms for all registered networks.

Uses torch.nn.utils.clip_grad_norm_.

Source

pub fn evaluate_loss(&self, queries: Vec<String>) -> PyResult<f64>

Evaluate mean NLL loss over queries without updating parameters.

Useful for validation/test set evaluation.

§Arguments
  • queries - List of query strings to evaluate
§Returns

Mean NLL loss over all queries

Source

pub fn memory_stats(&self, py: Python<'_>) -> PyResult<Py<PyAny>>

Return memory diagnostics including allocated_bytes and memory_limit_bytes.

Source

pub fn rule_provenance(&self, py: Python<'_>) -> PyResult<Py<PyAny>>

Source

pub fn proof_traces(&self, py: Python<'_>) -> PyResult<Py<PyAny>>

Source

pub fn host_transfer_stats(&self, py: Python<'_>) -> PyResult<Py<PyAny>>

Source

pub fn reset_host_transfer_stats(&self)

Source

pub fn neural_hot_loop_diagnostics(&self, py: Python<'_>) -> PyResult<Py<PyAny>>

Source

pub fn cuda_graph_stats(&self, py: Python<'_>) -> PyResult<Py<PyAny>>

Trait Implementations§

Source§

impl DerefToPyAny for CompiledProgram

Source§

impl ExtractPyClassWithClone for CompiledProgram

Source§

impl<'py> IntoPyObject<'py> for CompiledProgram

Source§

type Target = CompiledProgram

The Python output type
Source§

type Output = Bound<'py, <CompiledProgram as IntoPyObject<'py>>::Target>

The smart pointer type to use. Read more
Source§

type Error = PyErr

The type returned in the event of a conversion error.
Source§

fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>

Performs the conversion.
Source§

impl PyClass for CompiledProgram

Source§

const NAME: &str = "CompiledProgram"

Name of the class. Read more
Source§

type Frozen = False

Whether the pyclass is frozen. Read more
Source§

impl PyClassImpl for CompiledProgram

Source§

const MODULE: Option<&str> = ::core::option::Option::None

Module which the class will be associated with. Read more
Source§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
Source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
Source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
Source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
Source§

const IS_IMMUTABLE_TYPE: bool = false

#[pyclass(immutable_type)]
Source§

const RAW_DOC: &'static CStr = c"\x00"

Docstring for the class provided on the struct or enum. Read more
Source§

const DOC: &'static CStr

Fully rendered class doc, including the text_signature if a constructor is defined. Read more
Source§

type Layout = <<CompiledProgram as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<CompiledProgram>

Description of how this class is laid out in memory
Source§

type BaseType = PyAny

Base class
Source§

type ThreadChecker = NoopThreadChecker

This handles following two situations: Read more
Source§

type Inventory = Pyo3MethodsInventoryForCompiledProgram

Source§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
Source§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
Source§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
Source§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
Source§

fn items_iter() -> PyClassItemsIter

Source§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

§

fn dict_offset() -> Option<PyObjectOffset>

Used to provide the dictoffset slot (equivalent to tp_dictoffset)
§

fn weaklist_offset() -> Option<PyObjectOffset>

Used to provide the weaklistoffset slot (equivalent to tp_weaklistoffset
Source§

impl PyTypeInfo for CompiledProgram

Source§

const NAME: &str = <Self as ::pyo3::PyClass>::NAME

👎Deprecated since 0.28.0:

prefer using ::type_object(py).name() to get the correct runtime value

Class name.
Source§

const MODULE: Option<&str> = <Self as ::pyo3::impl_::pyclass::PyClassImpl>::MODULE

👎Deprecated since 0.28.0:

prefer using ::type_object(py).module() to get the correct runtime value

Module name, if any.
Source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
§

fn type_object(py: Python<'_>) -> Bound<'_, PyType>

Returns the safe abstraction over the type object.
§

fn is_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type or a subclass of this type.
§

fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<'py, T> IntoPyObjectExt<'py> for T
where T: IntoPyObject<'py>,

§

fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>

Converts self into an owned Python object, dropping type information.
§

fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>

Converts self into an owned Python object, dropping type information and unbinding it from the 'py lifetime.
§

fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>

Converts self into a Python object. Read more
§

impl<T> PyErrArguments for T
where T: for<'py> IntoPyObject<'py> + Send + Sync,

§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
§

impl<T> PyTypeCheck for T
where T: PyTypeInfo,

§

fn type_check(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of Self, which may include a subtype. Read more
§

fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>

Returns the expected type as a possible argument for the isinstance and issubclass function. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Ungil for T
where T: Send,

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V