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 Build a @c GenericCircuit containing the closures of two
76 * roots, with shared subgraphs unified.
77 *
78 * Loads the union of every gate reachable from @p root_token and
79 * every gate reachable from @p event_token in a single in-memory
80 * @c GenericCircuit. Because @c GenericCircuit's UUID-to-gate
81 * mapping is idempotent, a @c gate_rv (or any other gate) reachable
82 * from both roots gets exactly one @c gate_t -- the property the
83 * conditional MC sampler needs to couple the indicator's draw with
84 * the value's draw through @c Sampler's per-iteration cache.
85 *
86 * The on-load simplification passes that @c getGenericCircuit runs
87 * (@c runRangeCheck and @c foldSemiringIdentities, gated by
88 * @c provsql.simplify_on_load) are applied to the joint circuit too.
89 * Both passes are in-place: gate types may change, but UUID-to-gate_t
90 * mappings stay valid, so callers can resolve their two roots via
91 * @c getGate after the call returns.
92 *
93 * Output parameters @p root_gate and @p event_gate are the resolved
94 * @c gate_t for the two input UUIDs.
95 *
96 * @param root_token First root UUID (e.g. an RV's gate).
97 * @param event_token Second root UUID (e.g. the conditioning gate).
98 * @param root_gate Output: @c gate_t for @p root_token in the
99 * returned circuit.
100 * @param event_gate Output: @c gate_t for @p event_token in the
101 * returned circuit.
102 * @return An in-memory @c GenericCircuit.
103 */
105 pg_uuid_t root_token,
106 pg_uuid_t event_token,
107 gate_t &root_gate,
108 gate_t &event_gate);
109
110#endif /* BOOLEAN_CIRCUIT_FROM_MMAP_H */
Boolean provenance circuit with support for knowledge compilation.
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.
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.
Core types, constants, and utilities shared across ProvSQL.
UUID structure.