43 desc[
static_cast<std::underlying_type<gate_t>::type
>(id)] = d;
58 std::string result=
"digraph circuit{\n graph [rankdir=UD] ;\n";
67 result += std::to_string(i) +
" [label=";
71 result +=
"\"" +
desc[i] +
"\"";
89 result +=
"\"" +
desc[i] +
"\"";
92 result +=
"\"Π" +
desc[i] +
"\"";
99 result+=
",shape=\"double\"";
106 for(i=0; i<
wires.size(); ++i) {
108 std::unordered_map<gate_t, unsigned> number_gates;
109 for(
auto s:
wires[i]) {
110 if(number_gates.find(s)!=number_gates.end()) {
111 number_gates[s] = number_gates[s]+1;
118 for(
auto [s,n]: number_gates)
122 result += std::to_string(i)+
" -> "+
to_string(t);
124 result +=
" [label=\"R\"];\n";
126 result +=
" [label=\"L\"];\n";
130 result += std::to_string(i)+
" -> "+
to_string(s);
136 result +=
" [label=\"" + std::to_string(n) +
"\"];\n";
150 char cdir[] =
"/tmp/provsqlXXXXXX";
151 if(mkdtemp(cdir) == NULL) {
154 std::string filename=std::string(cdir)+
"/dot", outfilename=filename+
".out";
156 std::ofstream ofs(filename.c_str());
164 unlink(filename.c_str());
165 std::string dirname=filename.substr(0, filename.rfind(
'/'));
166 rmdir(dirname.c_str());
168 "graph-easy not found on PATH; install it or add its "
169 "directory to provsql.tool_search_path");
172 std::string cmdline=
"graph-easy --as=boxart --output="+outfilename+
" "+filename;
177 if(unlink(filename.c_str())) {
185 std::ifstream ifs(outfilename.c_str());
186 std::string str((std::istreambuf_iterator<char>(ifs)),
187 std::istreambuf_iterator<char>());
190 if(unlink(outfilename.c_str())) {
193 std::string dirname=filename.substr(0, filename.rfind(
'/'));
194 if(rmdir(dirname.c_str())) {
gate_t
Strongly-typed gate identifier.
std::string to_string(gate_t g)
Convert a gate_t to its decimal string representation.
Provenance circuit variant that renders to GraphViz DOT format.
DotGate
Gate types for a DOT visualisation circuit.
@ PROJECT
Projection gate.
@ OPLUS
Semiring plus (⊕).
@ OMINUS
Semiring monus (⊖), full.
@ OMINUSL
Monus, left child only.
@ OMINUSR
Monus, right child only.
@ DELTA
δ-semiring operator
@ IN
Input (variable) gate.
@ UNDETERMINED
Placeholder gate not yet assigned a type.
@ OTIMES
Semiring times (⊗).
Exception type thrown by circuit operations on invalid input.
std::vector< gate_t > & getWires(gate_t g)
DotGate getGateType(gate_t g) const
virtual gate_t setGate(const uuid &u, gateType type)
Create or update the gate associated with UUID u.
std::vector< DotGate > gates
std::vector< std::vector< gate_t > > wires
virtual gate_t addGate()
Allocate a new gate with a default-initialised type.
virtual std::string toString(gate_t g) const override
Return a textual description of gate g for debugging.
gate_t addGate() override
Allocate a new gate with a default-initialised type.
std::set< gate_t > inputs
Input gate IDs (rendered as leaf nodes).
gate_t setGate(const uuid &u, DotGate type) override
Create or update the gate associated with UUID u.
std::string render() const
Render the entire circuit as a GraphViz DOT digraph string.
std::vector< std::string > desc
Per-gate label strings (indexed by gate ID).
int provsql_verbose
Verbosity level; controlled by the provsql.verbose_level GUC.
Core types, constants, and utilities shared across ProvSQL.