Circuit#
Currently, this API is unsupported in Python
-
class Circuit : public helayers::Saveable#
A class that keeps the directed acyclic graph (DAG) that is the circuit.
Public Functions
-
inline Circuit()#
Constructs an empty circuit.
-
~Circuit()#
Destructs a circuit.
-
Circuit(Circuit &&c) noexcept#
Move constructor.
- Parameters:
c – the circuit to move into this instance.
-
PNode addNode(PNode n)#
Add a node to the circuit.
- Parameters:
n – the node to add.
-
inline circuit::NodeId createNodeId()#
-
inline int createTensorId()#
Allocate a new tensor ID.
-
PNode addInputNode(const CircuitCiphertext &c)#
Add an input node (a ctxt input) to the DAG.
The ciphertext is added with no label. A label can be added later.
- Parameters:
c – The ciphertext to add.
-
void buildEdges() const#
Finish the construction of the DAG after all nodes have been added.
-
void uniteNodeMaps()#
Unites all node maps of this circuit.
Required after finishing building the circuit.
-
void populateNodesToGroups()#
Populate the NodeIds in the group map.
-
void populateGroupsToNodes()#
Populate the group names at the nodes.
-
inline int getBuildingBucket(int i) const#
Get the building bucket a NodeId is mapped to.
- Parameters:
i – The NodeId.
-
void removeNode(PNode rem)#
Remove a node from the circuit.
- Parameters:
rem – The node to remove.
-
void deleteUnaryNodeAndReconnectInputToOutputs(PNode &node)#
Delete a unary node from a circuit, while fixing the circuit connections so that the deleted node’s consumers are now directly consuming the deleted node’s input.
- Parameters:
node – The node to delete
-
void deleteBootstrapRealNodeAndReconnectInputsToOutputs(PNode &node)#
Delete a BootstrapReal node from a circuit, while fixing the circuit connections so that the deleted node’s consumers are now directly consuming the deleted node’s inputs.
- Parameters:
node – The node to delete
-
inline bool areEdgesBuilt() const#
Return whether the edges have been built.
-
void setLabelCtxt(const NodeLabel &label, NodeId id)#
Give a node a human-meaningful label.
- Parameters:
label – The human meaningful label.
id – The node id to label.
-
void setTensorMetadata(const NodeLabel &label, const TTShape &s)#
Store a TTShape with the circuit and give it a label.
- Parameters:
label – The label of the TTShape.
s – The shape to be stored.
-
const TTShape &getTensorMetadataShape(const NodeLabel &label) const#
Get a TTShape from the circuit using the label it was given.
- Parameters:
label – The label of the TTShape.
-
inline const std::map<NodeLabel, NodeId> &getLabelToIdMap() const#
Get the map translating from a label to a ctxt id.
-
NodeId getNodeIdByLabel(const NodeLabel &label) const#
Returns the NodeId for the node with given label.
- Parameters:
label – Input label
-
PNode getNodeById(const NodeId &id) const#
Get a node by its id.
- Parameters:
id – The id of the node to retrieve.
-
inline std::map<NodeId, PNode> &getNodeById()#
-
bool hasNodeWithOutputId(const NodeId &id) const#
Query whether a node with a given id exists in the circuit.
- Parameters:
id – The id of the node to query.
-
int32_t getNumNodes() const#
Get the number of nodes in the circuit.
-
std::vector<PNode> getNodes() const#
Get the vector of nodes in the circuit.
-
std::vector<PNode> getNodesInTopologicalOrder() const#
Get the vector of nodes in the circuit.
The nodes are returned in a topological order, i.e., if v is a descendent of u then v will appear after u.
-
const RawValues &getRawValues(const NodeId &id) const#
Get the raw values of a plaintext of a certain id.
- Parameters:
id – The id of the plaintext to retrieve.
-
void writeGateList(std::ostream &o) const#
Write the circuit into a GateList file.
- Parameters:
o – The stream to write the file into.
-
void saveUnlabeledInputs(circuit::CtxtCache *cache, bool deleteValues = true)#
Record all unlabeled ctxt the circuit encountered.
Since ctxt that were not labeled are not input it must mean they are encrypted parameters of the circuit. With this function these ctxts can be saved to cache to be later encrypted and be used when running the circuit.
- Parameters:
m – A cache mem to write the unlabeled ctxts to.
deleteValues – Determines whether the values should be deleted from the circuit.
-
void reuseParams(bool val = true)#
Determines whether to set all unlabeled inputs as immortal (see Node::setImmortal).
- Parameters:
val – When true sets all unlabeled nodes as immortal, when false resets the immortal flags.
-
inline const HeConfigRequirement &getHeConfigReqWhenRecording() const#
Get the HeConfigRequirements of the HeContext used when recording this circuit.
-
void startGroup(const std::string &g, bool makeUnique = false)#
Start a new group.
Every node logged from now until the group closes will be a part of the group.
- Parameters:
g – The group name.
makeUnique – Add a prefix to make the group name unique. If there can be multiple groups with the same name they can be made unique by setting this parameter to true. A unique suffix of ” #<id>” will be added to the name.
-
void endGroup(const std::string &g)#
Close a group.
Every node logged since the creation of the group until now was a part of the group.
- Parameters:
g – The group name.
-
inline const std::map<std::string, std::set<NodeId>> &getGroups() const#
Get the groups defined while recording.
-
inline void startEra(const EraInfo &e)#
Start a new era when recording a circuit.
- Parameters:
e – The info of the new era that starts.
-
inline const EraInfo &getEra(PNode n) const#
Get the info of the era a node was recordede in.
- Parameters:
n – The node whose info should be returned.
-
inline std::shared_ptr<EraInfo> getEra(int n)#
Get the info of the era.
- Parameters:
n – The index of the era.
-
void printStats(std::ostream &out = std::cout) const#
Print circuit statistics.
- Parameters:
out – The out stream to write to.
-
void setByLabelCopy(const NodeLabel &label, const CTileTensor &c)#
Set a CTileTensor associated with a label.
This fills all one InputCtxtNode for each tile of this tile tensor.
- Parameters:
label – The label of the CTileTensor.
c – The CTile.
-
void setByLabelCopy(const NodeLabel &label, const CTile &c)#
Sets the output of the InputCtxtNode associated with this label.
- Parameters:
label – The label of the InputCtxtNode.
Sets the output of the InputCtxtNode associated with this label.
- Parameters:
label – The label of the InputCtxtNode.
-
void getCTileTensorByLabel(const NodeLabel &l, CTileTensor &c) const#
Return a CTileTensor associated with a label.
- Parameters:
l – A label.
c – The resulting CTileTensor.
-
std::shared_ptr<CTile> getCTileByLabel(const NodeLabel &l) const#
Return a CTile associated with a label.
- Parameters:
l – A label.
-
bool isUnlabeledParameters(PNode node) const#
return whether node is unlabeled parameter
- Param :
-
inline const TensorRepository &getTensorRepository() const#
Returns the tensor repository object of this circuit.
-
inline Circuit()#