1 #ifndef QNLP_GATEWRITER 2 #define QNLP_GATEWRITER 6 #include <unordered_set> 12 std::unordered_set<std::string>
gates;
28 GateWriter( std::string latexCSVFilename, std::string matrixFilename ){
30 std::ifstream file_exists(latexCSVFilename.c_str()) ;
32 latex_csv_out.open ( latexCSVFilename, std::ofstream::out | std::ofstream::app );
33 matrix_val_out.open( matrixFilename, std::ofstream::out | std::ofstream::app );
35 if (!(
bool) file_exists)
36 latex_csv_out <<
"gate_label,gate_ctrl,gate_tgt,gate_value" << std::endl;
56 void gateOut(std::string gateLabel, std::string matrixVals){
57 if( !
gates.count(gateLabel)){
59 gates.insert(gateLabel);
69 latex_csv_out <<
"#!#{" << segmentString <<
"}#!#" << std::endl;
79 void oneQubitGateCall(
const std::string& gateLabel,
const std::string& matrixVals, std::size_t gate_idx){
91 void twoQubitGateCall(
const std::string gateLabel,
const std::string matrixVals, std::size_t gate_ctrl_idx, std::size_t gate_tgt_idx){
92 latex_csv_out << gateLabel <<
"," << gate_ctrl_idx <<
"," << gate_tgt_idx <<
"," << matrixVals << std::endl;
std::unordered_set< std::string > & getAppliedGates()
Return the map of all applied gates so far.
void gateOut(std::string gateLabel, std::string matrixVals)
Writes the given matrix to matrix_val_out. Assumes matrix type is printable.
~GateWriter()
Destroy the Gate Writer object.
std::ofstream latex_csv_out
GateWriter(std::string latexCSVFilename, std::string matrixFilename)
Construct a new Gate Writer object.
std::unordered_set< std::string > gates
void segmentMarkerOut(std::string segmentString)
Marks the output file with a string pattern to allow easy of parsing for gates to algorithm operation...
std::ofstream matrix_val_out
GateWriter()
Construct a new Gate Writer object.
void twoQubitGateCall(const std::string gateLabel, const std::string matrixVals, std::size_t gate_ctrl_idx, std::size_t gate_tgt_idx)
Writes the controlled gate to disk.
void oneQubitGateCall(const std::string &gateLabel, const std::string &matrixVals, std::size_t gate_idx)
Writes the single qubit gate to disk. -1 used to denote lack of control line.