diff --git a/notebooks/compilation-options.ipynb b/notebooks/compilation-options.ipynb
index 0ffc05a1..08896612 100644
--- a/notebooks/compilation-options.ipynb
+++ b/notebooks/compilation-options.ipynb
@@ -203,8 +203,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "CPU times: user 4.58 s, sys: 1.02 s, total: 5.6 s\n",
- "Wall time: 5.52 s\n"
+ "CPU times: user 4.78 s, sys: 1.14 s, total: 5.92 s\n",
+ "Wall time: 5.76 s\n"
]
}
],
@@ -273,7 +273,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "1.26 s ± 19.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
+ "1.29 s ± 21.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
@@ -338,8 +338,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "CPU times: user 4.6 s, sys: 989 ms, total: 5.59 s\n",
- "Wall time: 5.52 s\n"
+ "CPU times: user 4.68 s, sys: 915 ms, total: 5.6 s\n",
+ "Wall time: 5.54 s\n"
]
}
],
@@ -433,7 +433,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "58.9 ms ± 22.1 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
+ "58.9 ms ± 28.8 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
@@ -527,8 +527,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "CPU times: user 4.97 s, sys: 962 ms, total: 5.93 s\n",
- "Wall time: 5.86 s\n"
+ "CPU times: user 4.55 s, sys: 758 ms, total: 5.31 s\n",
+ "Wall time: 5.25 s\n"
]
}
],
@@ -591,7 +591,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "25.6 ms ± 4.2 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
+ "25.7 ms ± 27.3 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
diff --git a/notebooks/learning-a-circuit-with-pic.ipynb b/notebooks/learning-a-circuit-with-pic.ipynb
index 90864e17..c91ed4da 100644
--- a/notebooks/learning-a-circuit-with-pic.ipynb
+++ b/notebooks/learning-a-circuit-with-pic.ipynb
@@ -29,7 +29,7 @@
"metadata": {},
"outputs": [],
"source": [
- "from cirkit.templates import circuit_templates\n",
+ "from cirkit.templates import utils, data_modalities\n",
"from cirkit.pipeline import compile\n",
"import random\n",
"import numpy as np\n",
@@ -45,14 +45,14 @@
"# Set the torch device to use\n",
"device = torch.device('cuda')\n",
"\n",
- "symbolic_circuit = circuit_templates.image_data(\n",
+ "symbolic_circuit = data_modalities.image_data(\n",
" (1, 28, 28), # The shape of MNIST image, i.e., (num_channels, image_height, image_width)\n",
" region_graph='quad-graph', # Select the structure of the circuit to follow the QuadGraph region graph\n",
" input_layer='categorical', # Use Categorical distributions for the pixel values (0-255) as input layers\n",
" num_input_units=64, # Each input layer consists of 64 Categorical input units\n",
" sum_product_layer='cp', # Use CP sum-product layers, i.e., alternate dense sum layers and hadamard product layers\n",
" num_sum_units=64, # Each dense sum layer consists of 64 sum units\n",
- " sum_weight_param=circuit_templates.Parameterization(\n",
+ " sum_weight_param=utils.Parameterization(\n",
" activation='none', # Do not use any parameterization\n",
" initialization='normal' # Initialize the sum weights by sampling from a standard normal distribution\n",
" )\n",
@@ -327,17 +327,17 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Step 200: Average NLL: 801.153\n",
- "Step 400: Average NLL: 707.815\n",
- "Step 600: Average NLL: 686.067\n",
- "Step 800: Average NLL: 677.673\n",
- "Step 1000: Average NLL: 664.983\n",
- "Step 1200: Average NLL: 656.790\n",
- "Step 1400: Average NLL: 653.522\n",
- "Step 1600: Average NLL: 651.386\n",
- "Step 1800: Average NLL: 650.300\n",
- "Step 2000: Average NLL: 648.279\n",
- "Step 2200: Average NLL: 647.581\n"
+ "Step 200: Average NLL: 800.724\n",
+ "Step 400: Average NLL: 704.707\n",
+ "Step 600: Average NLL: 684.442\n",
+ "Step 800: Average NLL: 675.654\n",
+ "Step 1000: Average NLL: 666.133\n",
+ "Step 1200: Average NLL: 656.394\n",
+ "Step 1400: Average NLL: 653.244\n",
+ "Step 1600: Average NLL: 651.271\n",
+ "Step 1800: Average NLL: 650.399\n",
+ "Step 2000: Average NLL: 648.530\n",
+ "Step 2200: Average NLL: 647.928\n"
]
}
],
@@ -393,8 +393,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Average test LL: -642.370\n",
- "Bits per dimension: 1.182\n"
+ "Average test LL: -642.912\n",
+ "Bits per dimension: 1.183\n"
]
}
],
diff --git a/notebooks/learning-a-circuit.ipynb b/notebooks/learning-a-circuit.ipynb
index 10386631..ae3226cb 100644
--- a/notebooks/learning-a-circuit.ipynb
+++ b/notebooks/learning-a-circuit.ipynb
@@ -176,8 +176,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "CPU times: user 3.18 s, sys: 267 ms, total: 3.45 s\n",
- "Wall time: 3.4 s\n"
+ "CPU times: user 2.65 s, sys: 322 ms, total: 2.97 s\n",
+ "Wall time: 2.89 s\n"
]
}
],
diff --git a/notebooks/logic-circuits.ipynb b/notebooks/logic-circuits.ipynb
index 8b607183..73826cbb 100644
--- a/notebooks/logic-circuits.ipynb
+++ b/notebooks/logic-circuits.ipynb
@@ -137,7 +137,7 @@
"id": "af50f45e",
"metadata": {},
"source": [
- "Converting a `LogicGraph` to a symbolic `cirkit` graph is straightforward by using the static method `cirkit.symbolic.circuit.Circuit.from_logic_graph`."
+ "Converting a `LogicGraph` to a symbolic `cirkit` graph is straightforward by using the method `build_circuit`."
]
},
{
@@ -152,72 +152,73 @@
"\n",
"\n",
- "\n",
- "\n",
+ "\n",
"\n"
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 3,
@@ -227,13 +228,14 @@
],
"source": [
"from cirkit.symbolic.circuit import Circuit\n",
+ "from cirkit.symbolic.io import plot_circuit\n",
"\n",
"def literal_label(layer):\n",
- " prefix = \"¬\" if layer.probs.output.value.squeeze().tolist() == [1.0, 0.0] else \"\"\n",
+ " prefix = \"¬\" if layer.probs.output.initializer.value.squeeze().tolist() == [1.0, 0.0] else \"\"\n",
" return f\"{prefix}{next(iter(layer.scope))}\"\n",
"\n",
- "circuit = Circuit.from_logic_circuit(alpha_graph, enforce_smoothness=False)\n",
- "circuit.plot(input_label=literal_label)"
+ "circuit = alpha_graph.build_circuit(enforce_smoothness=False)\n",
+ "plot_circuit(circuit, input_label=literal_label)"
]
},
{
@@ -334,7 +336,7 @@
{
"data": {
"text/plain": [
- "tensor([[[1.]]])"
+ "tensor([[[1.]]], grad_fn=)"
]
},
"execution_count": 5,
@@ -365,7 +367,7 @@
{
"data": {
"text/plain": [
- "tensor([[[0.]]])"
+ "tensor([[[0.]]], grad_fn=)"
]
},
"execution_count": 6,
@@ -432,7 +434,7 @@
}
],
"source": [
- "smooth_circuit = Circuit.from_logic_circuit(alpha_graph, enforce_smoothness=True)\n",
+ "smooth_circuit = alpha_graph.build_circuit(enforce_smoothness=True)\n",
"\n",
"with ctx:\n",
" smooth_compiled_circuit = compile(smooth_circuit)\n",
@@ -459,17 +461,17 @@
},
{
"cell_type": "code",
- "execution_count": 21,
+ "execution_count": 9,
"id": "97fd5510",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "tensor([[[2.]]])"
+ "tensor([[[2.]]], grad_fn=)"
]
},
- "execution_count": 21,
+ "execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
@@ -480,17 +482,17 @@
},
{
"cell_type": "code",
- "execution_count": 22,
+ "execution_count": 10,
"id": "1317d38b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "tensor([[[2.]]])"
+ "tensor([[[2.]]], grad_fn=)"
]
},
- "execution_count": 22,
+ "execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
@@ -515,16 +517,10 @@
"\n",
"We will rely on the [pySDD](https://github.com/ML-KULeuven/PySDD) library to compile propositional formulas to SDD circuits, exploiting the [official SDD compiler](http://reasoning.cs.ucla.edu/sdd/). \n",
"\n",
- "You can install pySDD with\n",
+ "You can install pySDD with the following command.\n",
"\n",
"```\n",
"$ pip install PySDD\n",
- "```\n",
- "\n",
- "additionally, we will visualize the boolean circuit using graphviz, which can be installed using \n",
- "\n",
- "```\n",
- "$ pip install graphviz\n",
"```"
]
},
@@ -539,7 +535,7 @@
},
{
"cell_type": "code",
- "execution_count": 23,
+ "execution_count": 11,
"id": "0ebb8e3a",
"metadata": {},
"outputs": [
@@ -549,70 +545,70 @@
"\n",
"\n",
- "\n",
"\n",
"\n"
],
"text/plain": [
- ""
+ ""
]
},
- "execution_count": 23,
+ "execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
@@ -644,7 +640,7 @@
},
{
"cell_type": "code",
- "execution_count": 24,
+ "execution_count": 12,
"id": "8cc2e96e",
"metadata": {},
"outputs": [
@@ -654,97 +650,97 @@
"\n",
"\n",
- "\n",
"\n",
- "