ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
CircuitFromMMap.h
Go to the documentation of this file.
1/**
2 * @file CircuitFromMMap.h
3 * @brief Build in-memory circuits from the mmap-backed persistent store.
4 *
5 * Declares two free functions that traverse the memory-mapped circuit
6 * storage starting from a given root UUID and construct the corresponding
7 * in-memory circuit representation. These functions are the primary
8 * bridge between the persistent @c MMappedCircuit and the evaluation
9 * algorithms that operate on @c BooleanCircuit or @c GenericCircuit.
10 */
11#ifndef BOOLEAN_CIRCUIT_FROM_MMAP_H
12#define BOOLEAN_CIRCUIT_FROM_MMAP_H
13
14extern "C" {
15#include "provsql_utils.h"
16}
17
18#include "BooleanCircuit.h"
19#include "GenericCircuit.h"
20
21/**
22 * @brief Build a @c BooleanCircuit from the mmap store rooted at @p token.
23 *
24 * Performs a depth-first traversal of the persistent circuit starting at
25 * @p token, translating each @c gate_type to the corresponding
26 * @c BooleanGate and copying probabilities and info integers.
27 *
28 * On return, @p gate is set to the @c gate_t identifier within the
29 * returned circuit that corresponds to @p token.
30 *
31 * @param token UUID of the root gate.
32 * @param gate Output: @c gate_t of the root within the returned circuit.
33 * @return An in-memory @c BooleanCircuit.
34 */
36
37/**
38 * @brief Build a @c BooleanCircuit from an already-loaded @c GenericCircuit.
39 *
40 * Variant of @c getBooleanCircuit() that reuses an existing
41 * @c GenericCircuit (typically obtained via @c getGenericCircuit()) and
42 * additionally exposes the @c GenericCircuit-to-@c BooleanCircuit gate
43 * mapping, so that callers can translate input-side annotations
44 * (e.g., user-supplied leaf labels) from @p gc to the constructed
45 * @c BooleanCircuit.
46 *
47 * @param gc Source generic circuit (mutated through HAVING
48 * evaluation).
49 * @param token UUID of the root gate.
50 * @param gate Output: @c gate_t of the root within the returned circuit.
51 * @param gc_to_bc Output: mapping from @c gc input/mulinput gates to the
52 * corresponding gates in the returned @c BooleanCircuit.
53 * @return An in-memory @c BooleanCircuit.
54 */
57 pg_uuid_t token,
58 gate_t &gate,
59 std::unordered_map<gate_t, gate_t> &gc_to_bc);
60
61/**
62 * @brief Build a @c GenericCircuit from the mmap store rooted at @p token.
63 *
64 * Equivalent to @c createGenericCircuit() declared in @c MMappedCircuit.h.
65 * Performs a depth-first traversal and copies all gate metadata
66 * (type, info1/info2, extra strings, probabilities) into the returned
67 * @c GenericCircuit.
68 *
69 * @param token UUID of the root gate.
70 * @return An in-memory @c GenericCircuit.
71 */
73
74/**
75 * @brief Propagate the per-gate d-DNNF certificate from @p gc to @p c.
76 *
77 * For every @c gate_plus / @c gate_times of @p gc carrying the
78 * @c DNNF_CERT_INFO mark whose BoolExpr image in @p c is an OR / AND
79 * gate (the zero/one shortcuts of @c GenericCircuit::evaluate may map a
80 * gate to a constant instead, in which case the mark is moot), set the
81 * mark on the image, so @c independentEvaluation() and
82 * @c interpretAsDD() can exploit determinism / decomposability.
83 * Requires @p gc_to_bc to cover internal gates, which
84 * @c GenericCircuit::evaluate guarantees (it memoises every visited
85 * gate).
86 *
87 * @param gc Source generic circuit.
88 * @param gc_to_bc Gate mapping produced by the BoolExpr evaluation.
89 * @param c Target Boolean circuit.
90 */
92 const GenericCircuit &gc,
93 const std::unordered_map<gate_t, gate_t> &gc_to_bc,
95
96class dDNNF;
97/**
98 * @brief Compile a query certified inversion-free to its structured d-DNNF.
99 *
100 * Builds the same structured d-DNNF the @c 'inversion-free' probability method
101 * uses (over the query-derived Prop. 4.5 order carried on the circuit's
102 * annotation markers), for the knowledge-compilation surface (DOT / NNF /
103 * stats). Throws @c CircuitException if @p token's root carries no
104 * inversion-free certificate. Defined in @c probability_evaluate.cpp.
105 */
107
108/**
109 * @brief Build a @c GenericCircuit containing the closures of two
110 * roots, with shared subgraphs unified.
111 *
112 * Loads the union of every gate reachable from @p root_token and
113 * every gate reachable from @p event_token in a single in-memory
114 * @c GenericCircuit. Because @c GenericCircuit's UUID-to-gate
115 * mapping is idempotent, a @c gate_rv (or any other gate) reachable
116 * from both roots gets exactly one @c gate_t -- the property the
117 * conditional MC sampler needs to couple the indicator's draw with
118 * the value's draw through @c Sampler's per-iteration cache.
119 *
120 * The on-load simplification passes that @c getGenericCircuit runs
121 * (@c runRangeCheck and @c foldSemiringIdentities, gated by
122 * @c provsql.simplify_on_load) are applied to the joint circuit too.
123 * Both passes are in-place: gate types may change, but UUID-to-gate_t
124 * mappings stay valid, so callers can resolve their two roots via
125 * @c getGate after the call returns.
126 *
127 * Output parameters @p root_gate and @p event_gate are the resolved
128 * @c gate_t for the two input UUIDs.
129 *
130 * @param root_token First root UUID (e.g. an RV's gate).
131 * @param event_token Second root UUID (e.g. the conditioning gate).
132 * @param root_gate Output: @c gate_t for @p root_token in the
133 * returned circuit.
134 * @param event_gate Output: @c gate_t for @p event_token in the
135 * returned circuit.
136 * @return An in-memory @c GenericCircuit.
137 */
139 pg_uuid_t root_token,
140 pg_uuid_t event_token,
141 gate_t &root_gate,
142 gate_t &event_gate);
143
144#endif /* BOOLEAN_CIRCUIT_FROM_MMAP_H */
Boolean provenance circuit with support for knowledge compilation.
void propagateDNNFCertificate(const GenericCircuit &gc, const std::unordered_map< gate_t, gate_t > &gc_to_bc, BooleanCircuit &c)
Propagate the per-gate d-DNNF certificate from gc to c.
BooleanCircuit getBooleanCircuit(pg_uuid_t token, gate_t &gate)
Build a BooleanCircuit from the mmap store rooted at token.
GenericCircuit getJointCircuit(pg_uuid_t root_token, pg_uuid_t event_token, gate_t &root_gate, gate_t &event_gate)
Build a GenericCircuit containing the closures of two roots, with shared subgraphs unified.
dDNNF buildInversionFreeDDNNF(pg_uuid_t token)
Compile a query certified inversion-free to its structured d-DNNF.
GenericCircuit getGenericCircuit(pg_uuid_t token)
Build a GenericCircuit from the mmap store rooted at token.
gate_t
Strongly-typed gate identifier.
Definition Circuit.h:49
Semiring-agnostic in-memory provenance circuit.
Boolean circuit for provenance formula evaluation.
In-memory provenance circuit with semiring-generic evaluation.
A d-DNNF circuit supporting exact probabilistic and game-theoretic evaluation.
Definition dDNNF.h:71
Core types, constants, and utilities shared across ProvSQL.
UUID structure.