Quick Start Guide¶
Installation¶
KLay supports Linux, Mac and Windows. Make sure you have installed Python, and install KLay using pip.
>>> pip install klaycircuits
To install the latest development version of KLay, you can install from the Github repo.
>>> pip install git+https://github.com/ML-KULeuven/klay
Usage¶
First, we need to create a circuit. You can both manually define the circuit, or import it from a knowledge compiler. For more information, check out the Circuit Creation Tutorial.
import klay
circuit = klay.Circuit()
circuit.add_sdd(sdd_node)
Now that we have the circuit, we can evaluate it. To do this, we first turn the circuit into a PyTorch module.
module = circuit.to_torch_module()
The input to the module should be a tensor with the weights for each literal. For more details, see the Circuit Evaluation Tutorial.
weights = torch.tensor([...])
result = module(weights)
result.backward()