QNLP  v1.0
QNLP::GateWriter Class Reference

#include <GateWriter.hpp>

Collaboration diagram for QNLP::GateWriter:
Collaboration graph

Public Member Functions

 GateWriter ()
 Construct a new Gate Writer object. More...
 
 GateWriter (std::string latexCSVFilename, std::string matrixFilename)
 Construct a new Gate Writer object. More...
 
 ~GateWriter ()
 Destroy the Gate Writer object. More...
 
void gateOut (std::string gateLabel, std::string matrixVals)
 Writes the given matrix to matrix_val_out. Assumes matrix type is printable. More...
 
void segmentMarkerOut (std::string segmentString)
 Marks the output file with a string pattern to allow easy of parsing for gates to algorithm operations. More...
 
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. More...
 
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. More...
 
std::unordered_set< std::string > & getAppliedGates ()
 Return the map of all applied gates so far. More...
 

Private Attributes

std::ofstream latex_csv_out
 
std::ofstream matrix_val_out
 
std::unordered_set< std::string > gates
 

Detailed Description

Definition at line 9 of file GateWriter.hpp.

Constructor & Destructor Documentation

◆ GateWriter() [1/2]

QNLP::GateWriter::GateWriter ( )
inline

Construct a new Gate Writer object.

Definition at line 19 of file GateWriter.hpp.

19  : GateWriter("qnlp_gate_calls.csv", "qnlp_matrices.log"){
20  }
GateWriter()
Construct a new Gate Writer object.
Definition: GateWriter.hpp:19

◆ GateWriter() [2/2]

QNLP::GateWriter::GateWriter ( std::string  latexCSVFilename,
std::string  matrixFilename 
)
inline

Construct a new Gate Writer object.

Parameters
latexCSVFilenameFilename for Latex CSV
matrixFilenameFilename for matrix

Definition at line 28 of file GateWriter.hpp.

28  {
29  //Check if file exists, add header upon creation if not
30  std::ifstream file_exists(latexCSVFilename.c_str()) ;
31 
32  latex_csv_out.open ( latexCSVFilename, std::ofstream::out | std::ofstream::app );
33  matrix_val_out.open( matrixFilename, std::ofstream::out | std::ofstream::app );
34 
35  if (!(bool) file_exists)
36  latex_csv_out << "gate_label,gate_ctrl,gate_tgt,gate_value" << std::endl;
37  }
std::ofstream latex_csv_out
Definition: GateWriter.hpp:11
std::ofstream matrix_val_out
Definition: GateWriter.hpp:11

References latex_csv_out, and matrix_val_out.

◆ ~GateWriter()

QNLP::GateWriter::~GateWriter ( )
inline

Destroy the Gate Writer object.

Definition at line 43 of file GateWriter.hpp.

43  {
44  latex_csv_out << "\n" << std::endl;
45  matrix_val_out << "\n" << std::endl;
46 
47  latex_csv_out.close();
48  matrix_val_out.close();
49  }
std::ofstream latex_csv_out
Definition: GateWriter.hpp:11
std::ofstream matrix_val_out
Definition: GateWriter.hpp:11

References latex_csv_out, and matrix_val_out.

Member Function Documentation

◆ gateOut()

void QNLP::GateWriter::gateOut ( std::string  gateLabel,
std::string  matrixVals 
)
inline

Writes the given matrix to matrix_val_out. Assumes matrix type is printable.

Parameters
matrix

Definition at line 56 of file GateWriter.hpp.

56  {
57  if( !gates.count(gateLabel)){
58  matrix_val_out << gateLabel << "," << matrixVals << std::endl;
59  gates.insert(gateLabel);
60  }
61  }
std::unordered_set< std::string > gates
Definition: GateWriter.hpp:12
std::ofstream matrix_val_out
Definition: GateWriter.hpp:11

References gates, and matrix_val_out.

Referenced by twoQubitGateCall().

Here is the caller graph for this function:

◆ getAppliedGates()

std::unordered_set<std::string>& QNLP::GateWriter::getAppliedGates ( )
inline

Return the map of all applied gates so far.

Returns
std::unordered_map<std::string, Mat2x2Type>&

Definition at line 101 of file GateWriter.hpp.

101  {
102  return gates;
103  }
std::unordered_set< std::string > gates
Definition: GateWriter.hpp:12

References gates.

◆ oneQubitGateCall()

void QNLP::GateWriter::oneQubitGateCall ( const std::string &  gateLabel,
const std::string &  matrixVals,
std::size_t  gate_idx 
)
inline

Writes the single qubit gate to disk. -1 used to denote lack of control line.

Parameters
gateLabelstd::string used to label gate name.
matrixValThe matrix representing the gate.
gate_idxThe qubit index to apply gate.

Definition at line 79 of file GateWriter.hpp.

79  {
80  twoQubitGateCall(gateLabel, matrixVals, -1, gate_idx);
81  }
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.
Definition: GateWriter.hpp:91

References twoQubitGateCall().

Referenced by TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ segmentMarkerOut()

void QNLP::GateWriter::segmentMarkerOut ( std::string  segmentString)
inline

Marks the output file with a string pattern to allow easy of parsing for gates to algorithm operations.

Parameters
segmentStringThe name of the segment to print into the file.

Definition at line 68 of file GateWriter.hpp.

68  {
69  latex_csv_out << "#!#{" << segmentString << "}#!#" << std::endl;
70  }
std::ofstream latex_csv_out
Definition: GateWriter.hpp:11

References latex_csv_out.

◆ twoQubitGateCall()

void QNLP::GateWriter::twoQubitGateCall ( const std::string  gateLabel,
const std::string  matrixVals,
std::size_t  gate_ctrl_idx,
std::size_t  gate_tgt_idx 
)
inline

Writes the controlled gate to disk.

Parameters
gateLabelstd::string used to label gate name.
matrixValThe matrix representing the gate.
gate_ctrl_idxThe qubit index for the gate control line
gate_tgt_idxThe qubit index for the gate target line

Definition at line 91 of file GateWriter.hpp.

91  {
92  latex_csv_out << gateLabel << "," << gate_ctrl_idx << "," << gate_tgt_idx << "," << matrixVals << std::endl;
93  gateOut(gateLabel, matrixVals);
94  }
void gateOut(std::string gateLabel, std::string matrixVals)
Writes the given matrix to matrix_val_out. Assumes matrix type is printable.
Definition: GateWriter.hpp:56
std::ofstream latex_csv_out
Definition: GateWriter.hpp:11

References gateOut(), and latex_csv_out.

Referenced by oneQubitGateCall().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ gates

std::unordered_set<std::string> QNLP::GateWriter::gates
private

Definition at line 12 of file GateWriter.hpp.

Referenced by gateOut(), and getAppliedGates().

◆ latex_csv_out

std::ofstream QNLP::GateWriter::latex_csv_out
private

Definition at line 11 of file GateWriter.hpp.

Referenced by GateWriter(), segmentMarkerOut(), twoQubitGateCall(), and ~GateWriter().

◆ matrix_val_out

std::ofstream QNLP::GateWriter::matrix_val_out
private

Definition at line 11 of file GateWriter.hpp.

Referenced by gateOut(), GateWriter(), and ~GateWriter().


The documentation for this class was generated from the following file: