graph
graph
¤
BottomNode
¤
Bases: LogicalCircuitNode
The bottom node representing False in the logic circuit.
Source code in cirkit/templates/logic/graph.py
25 26 | |
ConjunctionNode
¤
Bases: LogicalCircuitNode
A conjunction in the logical circuit.
Source code in cirkit/templates/logic/graph.py
67 68 | |
DisjunctionNode
¤
Bases: LogicalCircuitNode
A conjunction in the logical circuit.
Source code in cirkit/templates/logic/graph.py
71 72 | |
LiteralNode
¤
Bases: LogicalInputNode
A literal in the logical circuit.
Source code in cirkit/templates/logic/graph.py
59 60 | |
LogicalCircuit
¤
Bases: RootedDiAcyclicGraph[LogicalCircuitNode]
Source code in cirkit/templates/logic/graph.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
inputs
property
¤
num_variables
cached
property
¤
outputs
property
¤
__init__(nodes, in_nodes, outputs)
¤
A Logical circuit represented as a rooted acyclic graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
Sequence[LogicalCircuitNode]
|
The list of nodes in the logic graph. |
required |
in_nodes
|
dict[LogicalCircuitNode, Sequence[LogicalCircuitNode]]
|
A dictionary containing the list of inputs to each layer. |
required |
outputs
|
Sequence[LogicalCircuitNode]
|
The output layers of the circuit. |
required |
Source code in cirkit/templates/logic/graph.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
build_circuit(literal_input_factory=None, negated_literal_input_factory=None, weight_factory=None, num_channels=1, enforce_smoothness=True)
¤
Construct a symbolic circuit from a logic circuit graph. If input factories for literals and their negation are not provided the it falls back to a categorical input layer with two categories parametrized by the constant vector [0, 1] for a literal and [1, 0] for its negation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
literal_input_factory
|
InputLayerFactory
|
A factory that builds an input layer for literals. |
None
|
negated_literal_input_factory
|
InputLayerFactory
|
A factory that builds an input layer for negated literals. |
None
|
weight_factory
|
ParameterFactory | None
|
The factory to construct the weight of sum layers. It can be None, or a parameter factory, i.e., a map from a shape to a symbolic parameter. If None is used, the default weight factory uses non-trainable unitary parameters, which instantiate a regular boolean logic graph. |
None
|
num_channels
|
int
|
The number of channels for each variable. |
1
|
enforce_smoothness
|
bool
|
Enforces smoothness of the circuit to support efficient marginalization. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Circuit |
Circuit
|
A symbolic circuit. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If only one of literal_input_factory and negated_literal_input_factory are specified. |
Source code in cirkit/templates/logic/graph.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
node_scope(node)
¤
Compute the scope of a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
LogicalCircuitNode
|
The node for which the scope is computed. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Scope |
Scope
|
The scope of the node. |
Source code in cirkit/templates/logic/graph.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
prune()
¤
Prune the current graph by applying unit propagation.
Prune a graph in place by applying unit propagation to conjunction and disjunctions. See https://en.wikipedia.org/wiki/Unit_propagation. Nodes that are not used as input to other nodes and are not among the output nodes are removed too.
Source code in cirkit/templates/logic/graph.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
smooth()
¤
Convert the current graph to a smooth graph in place. see https://yoojungchoi.github.io/files/ProbCirc20.pdf and https://proceedings.neurips.cc/paper/2019/file/940392f5f32a7ade1cc201767cf83e31-Paper.pdf for more information.
Returns:
| Name | Type | Description |
|---|---|---|
LogicalCircuit |
A new logic graph that is smooth. |
Source code in cirkit/templates/logic/graph.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
LogicalCircuitNode
¤
Bases: ABC
The abstract base class for nodes in logic circuits.
Source code in cirkit/templates/logic/graph.py
17 18 | |
LogicalInputNode
¤
Bases: LogicalCircuitNode
The abstract base class for input nodes in logic circuits.
Source code in cirkit/templates/logic/graph.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
_literal = literal
instance-attribute
¤
literal
property
¤
The literal of this input.
Returns:
| Name | Type | Description |
|---|---|---|
str |
int
|
The int representation of the literal. |
__init__(literal)
¤
Init class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
literal
|
int
|
The literal of this node. |
required |
Source code in cirkit/templates/logic/graph.py
32 33 34 35 36 37 38 39 | |
__repr__()
¤
Generate the repr string of the node.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The str representation of the node. |
Source code in cirkit/templates/logic/graph.py
50 51 52 53 54 55 56 | |
NegatedLiteralNode
¤
Bases: LogicalInputNode
A negated literal in the logical circuit.
Source code in cirkit/templates/logic/graph.py
63 64 | |
TopNode
¤
Bases: LogicalCircuitNode
The top node representing True in the logic circuit.
Source code in cirkit/templates/logic/graph.py
21 22 | |