circuit
circuit
¤
Circuit
¤
Bases: DiAcyclicGraph[Layer]
The symbolic circuit representation.
Source code in cirkit/symbolic/circuit.py
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 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
_scopes = {}
instance-attribute
¤
inner_layers
property
¤
Retrieves an iterator over inner layers (i.e., non-input layers).
Returns:
| Type | Description |
|---|---|
Iterator[SumLayer | ProductLayer]
|
Iterator[Union[SumLayer, ProductLayer]]: |
is_decomposable
cached
property
¤
Check if the circuit is decomposable.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the circuit is decomposable and False otherwise. |
is_omni_compatible
cached
property
¤
Check if the circuit is omni-compatible.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the circuit is omni-compatible and False otherwise. |
is_smooth
cached
property
¤
Check if the circuit is smooth.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the circuit is smooth and False otherwise. |
is_structured_decomposable
cached
property
¤
Check if the circuit is structured-decomposable.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the circuit is structured-decomposable and False otherwise. |
layers
property
¤
layers_inputs
property
¤
layers_outputs
property
¤
num_channels = num_channels
instance-attribute
¤
num_variables
property
¤
operation = operation
instance-attribute
¤
product_layers
property
¤
Retrieves an iterator over product layers.
Returns:
| Type | Description |
|---|---|
Iterator[ProductLayer]
|
Iterator[ProductLayer]: |
properties
cached
property
¤
Retrieves all the structural properties of the circuit: smoothness, decomposability, structured-decomposability and omni-compatibility.
Returns:
| Type | Description |
|---|---|
StructuralProperties
|
The structural properties. |
scope = Scope.union(*tuple(self._scopes[sl] for sl in self.outputs))
instance-attribute
¤
sum_layers
property
¤
__init__(num_channels, layers, in_layers, outputs, *, operation=None)
¤
Initializes a symbolic circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_channels
|
int
|
The number of channels for each variable. |
required |
layers
|
Sequence[Layer]
|
The list of symbolic layers. |
required |
in_layers
|
Mapping[Layer, Sequence[Layer]]
|
A dictionary containing the list of inputs to each layer. |
required |
outputs
|
Sequence[Layer]
|
The output layers of the circuit. |
required |
operation
|
CircuitOperation | None
|
The optional operation the circuit has been obtained through. |
None
|
Source code in cirkit/symbolic/circuit.py
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 | |
from_operation(num_channels, blocks, in_blocks, output_blocks, *, operation)
classmethod
¤
Constructs a circuit that resulted from an operation over other circuits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_channels
|
int
|
The number of channels per variable. |
required |
blocks
|
list[CircuitBlock]
|
The list of circuit blocks. |
required |
in_blocks
|
dict[CircuitBlock, Sequence[CircuitBlock]]
|
A dictionary containing the list of block inputs to each circuit block. |
required |
output_blocks
|
list[CircuitBlock]
|
The outputs blocks of the circuit. |
required |
operation
|
CircuitOperation
|
A circuit operation containing the information of the operation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Circuit |
Circuit
|
A symbolic circuit.Ki |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there is a circuit block having more than one layer with no inputs that are not input layers (i.e., they are either sum of product layers). |
Source code in cirkit/symbolic/circuit.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
layer_inputs(sl)
¤
Retrieves the inputs to a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sl
|
Layer
|
The layer. |
required |
Returns:
| Type | Description |
|---|---|
Sequence[Layer]
|
Sequence[Layer]: The list of inputs. |
Source code in cirkit/symbolic/circuit.py
295 296 297 298 299 300 301 302 303 304 | |
layer_outputs(sl)
¤
Retrieves the outputs of a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sl
|
Layer
|
The layer. |
required |
Returns:
| Type | Description |
|---|---|
Sequence[Layer]
|
Sequence[Layer]: The list of outputs. |
Source code in cirkit/symbolic/circuit.py
306 307 308 309 310 311 312 313 314 315 | |
layer_scope(sl)
¤
Retrieves the scope of a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sl
|
Layer
|
The layer. |
required |
Returns:
| Type | Description |
|---|---|
Scope
|
The scope of the given layer. |
Source code in cirkit/symbolic/circuit.py
284 285 286 287 288 289 290 291 292 293 | |
subgraph(*outputs)
¤
Retrieve the sub-circuit having the given layers as outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*outputs
|
Layer
|
The output layers. |
()
|
Returns:
| Type | Description |
|---|---|
Circuit
|
The sub-circuit having the given layers as outputs. |
Source code in cirkit/symbolic/circuit.py
371 372 373 374 375 376 377 378 379 380 381 | |
CircuitBlock
¤
Bases: RootedDiAcyclicGraph[Layer]
The circuit block data structure. A circuit block is a fragment of a symbolic circuit, consisting of a single root (or output) layer. A circuit block can be of only two types: (1) a circuit block whose layers that do not have any inputs must all be input layers, and (2) a circuit block where there is one and only one layer that does not have any other input, which can be either a sum or product layer.
Source code in cirkit/symbolic/circuit.py
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 | |
inner_layers
property
¤
Retrieves an iterator over inner layers (i.e., layers that have at least one input).
Returns:
| Type | Description |
|---|---|
Iterator[SumLayer | ProductLayer]
|
Iterator[Union[SumLayer, ProductLayer]]: |
layers
property
¤
layers_inputs
property
¤
layers_outputs
property
¤
product_layers
property
¤
Retrieves an iterator over product layers.
Returns:
| Type | Description |
|---|---|
Iterator[ProductLayer]
|
Iterator[ProductLayer]: |
sum_layers
property
¤
__init__(layers, in_layers, output)
¤
Initializes a circuit block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layers
|
Sequence[Layer]
|
The sequence of layers in the block. |
required |
in_layers
|
Mapping[Layer, list[Layer]]
|
A dictionary containing the list of inputs to each layer. |
required |
output
|
Layer
|
The root (or output) of the circuit block. |
required |
Source code in cirkit/symbolic/circuit.py
84 85 86 87 88 89 90 91 92 93 94 | |
from_layer(sl)
staticmethod
¤
Instantiate a circuit block from a single layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sl
|
Layer
|
The layer. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
CircuitBlock |
CircuitBlock
|
The circuit block consisting of only one layer. |
Source code in cirkit/symbolic/circuit.py
172 173 174 175 176 177 178 179 180 181 182 | |
from_layer_composition(*layers)
staticmethod
¤
Instantiate a circuit block from a composition of multiple layers. The ordering of the composition is given by the ordering of the layers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layers
|
Layer
|
A sequence of layers. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
CircuitBlock |
CircuitBlock
|
The circuit block consisting of a composition of layers. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the given sequence of layers consists of less than two layers. |
Source code in cirkit/symbolic/circuit.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
from_nary_layer(lout, *ls)
staticmethod
¤
Instantiate a circuit block consisting of an output layer having multiple layers as inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lout
|
Layer
|
The output layer. |
required |
*ls
|
InputLayer
|
A sequence of inpput layers. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
CircuitBlock |
CircuitBlock
|
The circuit block consisting of an output layer with several input layers as inputs. |
Source code in cirkit/symbolic/circuit.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
layer_inputs(sl)
¤
Retrieves the inputs to a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sl
|
Layer
|
The layer. |
required |
Returns:
| Type | Description |
|---|---|
Sequence[Layer]
|
Sequence[Layer]: The sequence of inputs. |
Source code in cirkit/symbolic/circuit.py
96 97 98 99 100 101 102 103 104 105 | |
layer_outputs(sl)
¤
Retrieves the outputs of a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sl
|
Layer
|
The layer. |
required |
Returns:
| Type | Description |
|---|---|
Sequence[Layer]
|
Sequence[Layer]: The sequence of outputs. |
Source code in cirkit/symbolic/circuit.py
107 108 109 110 111 112 113 114 115 116 | |
CircuitOperation
dataclass
¤
The symbolic operation that is applied to obtain a symbolic circuit.
Source code in cirkit/symbolic/circuit.py
64 65 66 67 68 69 70 71 72 73 | |
CircuitOperator
¤
Bases: IntEnum
The available symbolic operators defined over circuits.
Source code in cirkit/symbolic/circuit.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
CONCATENATE = auto()
class-attribute
instance-attribute
¤
The concatenation operator defined over many circuits.
CONJUGATION = auto()
class-attribute
instance-attribute
¤
The conjugatation operator defined over a circuit computing a complex function.
DIFFERENTIATION = auto()
class-attribute
instance-attribute
¤
The differentiation operator defined over a circuit.
EVIDENCE = auto()
class-attribute
instance-attribute
¤
The evidence operator defined over a circuit.
INTEGRATION = auto()
class-attribute
instance-attribute
¤
The integration operator defined over a circuit.
MULTIPLICATION = auto()
class-attribute
instance-attribute
¤
The multiplication operator defined over two circuits.
StructuralProperties
dataclass
¤
The available structural properties of a circuit.
Source code in cirkit/symbolic/circuit.py
33 34 35 36 37 38 39 40 41 42 43 44 | |
decomposable
instance-attribute
¤
Whether the circuit is decomposable.
omni_compatible
instance-attribute
¤
Whether the circuit is omni-compatible, i.e., compatible to a fully-factorized circuit.
smooth
instance-attribute
¤
Whether the circuit is smooth.
structured_decomposable
instance-attribute
¤
Whether the circuit is structured-decomposable, i.e., is compatible with itself.
__init__(smooth, decomposable, structured_decomposable, omni_compatible)
¤
StructuralPropertyError
¤
Bases: Exception
An exception that is raised when an error regarding one circuit structural property occurs.
Source code in cirkit/symbolic/circuit.py
20 21 22 23 24 25 26 27 28 29 30 | |
__init__(msg)
¤
Initializes a structural property error with a message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
The message. |
required |
Source code in cirkit/symbolic/circuit.py
24 25 26 27 28 29 30 | |
_are_compatible(sfs1, sfs2)
¤
Source code in cirkit/symbolic/circuit.py
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | |
_scope_factorizations(sc)
¤
Source code in cirkit/symbolic/circuit.py
544 545 546 547 548 549 550 551 552 553 554 555 | |
are_compatible(sc1, sc2)
¤
Check if two symbolic circuits are compatible. Note that compatibility is a commutative property of circuits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sc1
|
Circuit
|
The first symbolic circuit. |
required |
sc2
|
Circuit
|
The second symbolic circuit. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the first symbolic circuit is compatible with the second one. |
Source code in cirkit/symbolic/circuit.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |
pipeline_topological_ordering(roots)
¤
Retrieves the topological ordering of circuits in a pipeline, given a sequence of root (or output) symbolic circuits in a pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
roots
|
Sequence[Circuit]
|
The sequence of root (or output) symbolic circuits in a pipeline. |
required |
Returns:
| Type | Description |
|---|---|
Iterator[Circuit]
|
Iterator[Circuit]: An iterator of the topological ordering of circuits in a pipeline. |
Source code in cirkit/symbolic/circuit.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |