compiled-knowledge 4.0.0a18__cp312-cp312-win_amd64.whl → 4.0.0a20__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of compiled-knowledge might be problematic. Click here for more details.
- ck/circuit/__init__.py +0 -3
- ck/circuit/_circuit_cy.c +37523 -0
- ck/circuit/_circuit_cy.cp312-win_amd64.pyd +0 -0
- ck/circuit/_circuit_cy.pxd +3 -4
- ck/circuit/_circuit_cy.pyx +80 -79
- ck/circuit_compiler/cython_vm_compiler/_compiler.c +19824 -0
- ck/circuit_compiler/cython_vm_compiler/_compiler.cp312-win_amd64.pyd +0 -0
- ck/circuit_compiler/cython_vm_compiler/_compiler.pyx +188 -75
- ck/circuit_compiler/cython_vm_compiler/cython_vm_compiler.py +29 -4
- ck/circuit_compiler/support/circuit_analyser/__init__.py +13 -0
- ck/circuit_compiler/support/circuit_analyser/_circuit_analyser_cy.c +10618 -0
- ck/circuit_compiler/support/circuit_analyser/_circuit_analyser_cy.cp312-win_amd64.pyd +0 -0
- ck/circuit_compiler/support/circuit_analyser/_circuit_analyser_cy.pyx +98 -0
- ck/circuit_compiler/support/{circuit_analyser.py → circuit_analyser/_circuit_analyser_py.py} +14 -2
- ck/pgm_compiler/ace/__init__.py +1 -1
- ck/pgm_compiler/support/circuit_table/__init__.py +1 -0
- ck/pgm_compiler/support/circuit_table/_circuit_table_cy.c +16396 -0
- ck/pgm_compiler/support/circuit_table/_circuit_table_cy.cp312-win_amd64.pyd +0 -0
- ck_demos/ace/demo_ace.py +5 -0
- {compiled_knowledge-4.0.0a18.dist-info → compiled_knowledge-4.0.0a20.dist-info}/METADATA +1 -1
- {compiled_knowledge-4.0.0a18.dist-info → compiled_knowledge-4.0.0a20.dist-info}/RECORD +24 -20
- ck/pgm_compiler/support/circuit_table/_circuit_table_cy_cpp_verion.pyx +0 -601
- ck/pgm_compiler/support/circuit_table/_circuit_table_cy_minimal_version.pyx +0 -311
- ck/pgm_compiler/support/circuit_table/_circuit_table_cy_v4.0.0a17.pyx +0 -325
- {compiled_knowledge-4.0.0a18.dist-info → compiled_knowledge-4.0.0a20.dist-info}/WHEEL +0 -0
- {compiled_knowledge-4.0.0a18.dist-info → compiled_knowledge-4.0.0a20.dist-info}/licenses/LICENSE.txt +0 -0
- {compiled_knowledge-4.0.0a18.dist-info → compiled_knowledge-4.0.0a20.dist-info}/top_level.txt +0 -0
|
Binary file
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import List, Dict, Sequence, Set
|
|
3
|
+
|
|
4
|
+
from ck.circuit._circuit_cy cimport Circuit, OpNode, VarNode, CircuitNode, ConstNode
|
|
5
|
+
from cython.operator cimport postincrement
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class CircuitAnalysis:
|
|
10
|
+
"""
|
|
11
|
+
A data structure representing the analysis of a function defined by
|
|
12
|
+
a circuit which chosen input variables and output result nodes.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
var_nodes: Sequence[VarNode] # specified input var nodes
|
|
16
|
+
result_nodes: Sequence[CircuitNode] # specified result nodes
|
|
17
|
+
op_nodes: Sequence[OpNode] # in-use op nodes, in computation order
|
|
18
|
+
const_nodes: Sequence[ConstNode] # in_use const nodes, in arbitrary order
|
|
19
|
+
op_to_result: Dict[int, int] # op nodes in the result, op_node = result[idx]: id(op_node) -> idx
|
|
20
|
+
op_to_tmp: Dict[int, int] # op nodes needing tmp memory, using tmp[idx]: id(op_node) -> idx
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def analyze_circuit(
|
|
24
|
+
var_nodes: Sequence[VarNode],
|
|
25
|
+
result_nodes: Sequence[CircuitNode],
|
|
26
|
+
) -> CircuitAnalysis:
|
|
27
|
+
"""
|
|
28
|
+
Analyzes a circuit as a function from var_nodes to result_nodes,
|
|
29
|
+
returning a CircuitAnalysis object.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
var_nodes: The chosen input variable nodes of the circuit.
|
|
33
|
+
result_nodes: The chosen output result nodes of the circuit.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
A CircuitAnalysis object.
|
|
37
|
+
"""
|
|
38
|
+
cdef list[CircuitNode] results_list = list(result_nodes)
|
|
39
|
+
|
|
40
|
+
# What op nodes are in use
|
|
41
|
+
cdef list[OpNode] op_nodes = _reachable_op_nodes(results_list)
|
|
42
|
+
|
|
43
|
+
# What constant values are in use
|
|
44
|
+
cdef set[int] seen_const_nodes = set()
|
|
45
|
+
cdef list[ConstNode] const_nodes = []
|
|
46
|
+
|
|
47
|
+
def _register_const(_node: ConstNode) -> None:
|
|
48
|
+
nonlocal seen_const_nodes
|
|
49
|
+
nonlocal const_nodes
|
|
50
|
+
_node_id: int = id(_node)
|
|
51
|
+
if _node_id not in seen_const_nodes:
|
|
52
|
+
const_nodes.append(_node)
|
|
53
|
+
seen_const_nodes.add(_node_id)
|
|
54
|
+
|
|
55
|
+
# Register all the used constants
|
|
56
|
+
for op_node in op_nodes:
|
|
57
|
+
for node in op_node.args:
|
|
58
|
+
if isinstance(node, ConstNode):
|
|
59
|
+
_register_const(node)
|
|
60
|
+
for node in results_list:
|
|
61
|
+
if isinstance(node, ConstNode):
|
|
62
|
+
_register_const(node)
|
|
63
|
+
for node in var_nodes:
|
|
64
|
+
if node.is_const():
|
|
65
|
+
_register_const(node.const)
|
|
66
|
+
|
|
67
|
+
# What op nodes are in the result.
|
|
68
|
+
# Dict op_to_result maps id(OpNode) to result index.
|
|
69
|
+
cdef dict[int, int] op_to_result = {
|
|
70
|
+
id(node): i
|
|
71
|
+
for i, node in enumerate(result_nodes)
|
|
72
|
+
if isinstance(node, OpNode)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
# Assign all other op nodes to a tmp slot.
|
|
76
|
+
# Dict op_to_tmp maps id(OpNode) to tmp index.
|
|
77
|
+
cdef int tmp_idx = 0
|
|
78
|
+
op_to_tmp: Dict[int, int] = {
|
|
79
|
+
id(op_node): postincrement(tmp_idx)
|
|
80
|
+
for op_node in op_nodes
|
|
81
|
+
if id(op_node) not in op_to_result
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return CircuitAnalysis(
|
|
85
|
+
var_nodes=var_nodes,
|
|
86
|
+
result_nodes=result_nodes,
|
|
87
|
+
op_nodes=op_nodes,
|
|
88
|
+
const_nodes=const_nodes,
|
|
89
|
+
op_to_result=op_to_result,
|
|
90
|
+
op_to_tmp=op_to_tmp,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
cdef list[OpNode] _reachable_op_nodes(list[CircuitNode] results):
|
|
95
|
+
if len(results) == 0:
|
|
96
|
+
return []
|
|
97
|
+
cdef Circuit circuit = results[0].circuit
|
|
98
|
+
return circuit.find_reachable_op_nodes(results)
|
ck/circuit_compiler/support/{circuit_analyser.py → circuit_analyser/_circuit_analyser_py.py}
RENAMED
|
@@ -7,8 +7,13 @@ from ck.circuit import OpNode, VarNode, CircuitNode, ConstNode
|
|
|
7
7
|
|
|
8
8
|
@dataclass
|
|
9
9
|
class CircuitAnalysis:
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
"""
|
|
11
|
+
A data structure representing the analysis of a function defined by
|
|
12
|
+
a circuit which chosen input variables and output result nodes.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
var_nodes: Sequence[VarNode] # specified input var nodes
|
|
16
|
+
result_nodes: Sequence[CircuitNode] # specified result nodes
|
|
12
17
|
op_nodes: Sequence[OpNode] # in-use op nodes, in computation order
|
|
13
18
|
const_nodes: Sequence[ConstNode] # in_use const nodes, in arbitrary order
|
|
14
19
|
op_to_result: Dict[int, int] # op nodes in the result, op_node = result[idx]: id(op_node) -> idx
|
|
@@ -22,6 +27,13 @@ def analyze_circuit(
|
|
|
22
27
|
"""
|
|
23
28
|
Analyzes a circuit as a function from var_nodes to result_nodes,
|
|
24
29
|
returning a CircuitAnalysis object.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
var_nodes: The chosen input variable nodes of the circuit.
|
|
33
|
+
result_nodes: The chosen output result nodes of the circuit.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
A CircuitAnalysis object.
|
|
25
37
|
"""
|
|
26
38
|
# What op nodes are in use
|
|
27
39
|
op_nodes: List[OpNode] = (
|
ck/pgm_compiler/ace/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
from .ace import compile_pgm, copy_ace_to_default_location, default_ace_location
|
|
1
|
+
from .ace import compile_pgm, copy_ace_to_default_location, default_ace_location, ace_available
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# There are two implementations of the `circuit_table` module are provided
|
|
2
2
|
# for developer R&D purposes. One is pure Python and the other is Cython.
|
|
3
3
|
# Which implementation is used can be selected here.
|
|
4
|
+
#
|
|
4
5
|
# A similar selection can be made for the `circuit` module.
|
|
5
6
|
# Note that if the Cython implementation is chosen for `circuit_table` then
|
|
6
7
|
# the Cython implementation must be chosen for `circuit`.
|