45 desc[
static_cast<std::underlying_type<gate_t>::type
>(id)] = d;
60 std::string result=
"digraph circuit{\n graph [rankdir=UD] ;\n";
69 result += std::to_string(i) +
" [label=";
73 result +=
"\"" +
desc[i] +
"\"";
91 result +=
"\"" +
desc[i] +
"\"";
94 result +=
"\"Π" +
desc[i] +
"\"";
101 result+=
",shape=\"double\"";
108 for(i=0; i<
wires.size(); ++i) {
110 std::unordered_map<gate_t, unsigned> number_gates;
111 for(
auto s:
wires[i]) {
112 if(number_gates.find(s)!=number_gates.end()) {
113 number_gates[s] = number_gates[s]+1;
120 for(
auto [s,n]: number_gates)
124 result += std::to_string(i)+
" -> "+
to_string(t);
126 result +=
" [label=\"R\"];\n";
128 result +=
" [label=\"L\"];\n";
132 result += std::to_string(i)+
" -> "+
to_string(s);
138 result +=
" [label=\"" + std::to_string(n) +
"\"];\n";
152 std::string render_bin =
"graph-easy";
153 std::string render_argtpl =
"--as=boxart --output={out} {in}";
159 "Tool 'graph-easy' is disabled in the tool registry");
161 render_argtpl = rec->
argtpl;
166 render_bin +
" not found on PATH; install it or add its "
167 "directory to provsql.tool_search_path");
176 std::string filename = tmp.
file(
"dot");
177 std::string outfilename = tmp.
file(
"dot.out");
180 std::ofstream ofs(filename);
185 render_argtpl, render_bin, filename, outfilename);
191 std::ifstream ifs(outfilename.c_str());
192 std::string str((std::istreambuf_iterator<char>(ifs)),
193 std::istreambuf_iterator<char>());
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).
RAII guard around a freshly mkdtemp'd /tmp directory.
std::string file(const std::string &basename)
Build a path under the temp dir and register it for cleanup.
void keep()
Leave the directory on disk; cleanup is skipped at scope exit.
ToolRegistry & tool_registry()
Shorthand for ToolRegistry::instance().
std::string expandCommandTemplate(const std::string &tpl, const std::string &binary, const std::string &in, const std::string &out, const std::vector< std::pair< std::string, std::string > > &extra={})
Expand a command template into a runnable shell command line.
int provsql_verbose
Verbosity level; controlled by the provsql.verbose_level GUC.
Core types, constants, and utilities shared across ProvSQL.