File tree Expand file tree Collapse file tree 5 files changed +34
-9
lines changed
include/cliffordsynthesis Expand file tree Collapse file tree 5 files changed +34
-9
lines changed Original file line number Diff line number Diff line change @@ -15,11 +15,13 @@ struct Configuration {
1515 Configuration () = default ;
1616
1717 // / General configuration for the synthesis algorithm
18- std::size_t initialTimestepLimit = 0U ;
19- bool useMaxSAT = false ;
20- TargetMetric target = TargetMetric::Gates;
21- bool useSymmetryBreaking = true ;
22- plog::Severity verbosity = plog::Severity::warning;
18+ std::size_t initialTimestepLimit = 0U ;
19+ bool useMaxSAT = false ;
20+ TargetMetric target = TargetMetric::Gates;
21+ bool useSymmetryBreaking = true ;
22+ bool dumpIntermediateResults = false ;
23+ std::string intermediateResultsPath = " ./" ;
24+ plog::Severity verbosity = plog::Severity::warning;
2325
2426 // / Settings for the SAT solver
2527 std::size_t nThreads = 1U ;
Original file line number Diff line number Diff line change @@ -421,6 +421,15 @@ PYBIND11_MODULE(pyqmap, m) {
421421 &cs::Configuration::useSymmetryBreaking,
422422 " Use symmetry breaking clauses to speed up the synthesis "
423423 " process. Defaults to `true`." )
424+ .def_readwrite (" dump_intermediate_results" ,
425+ &cs::Configuration::dumpIntermediateResults,
426+ " Dump intermediate results of the synthesis process. "
427+ " Defaults to `false`." )
428+ .def_readwrite (" intermediate_results_path" ,
429+ &cs::Configuration::intermediateResultsPath,
430+ " Path to the directory where intermediate results should "
431+ " be dumped. Defaults to `./`. The path needs to include a "
432+ " path separator at the end." )
424433 .def_readwrite (
425434 " verbosity" , &cs::Configuration::verbosity,
426435 " Verbosity level for the synthesis process. Defaults to 'warning'." )
Original file line number Diff line number Diff line change @@ -321,8 +321,10 @@ class Verbosity:
321321 def value (self ) -> int : ...
322322
323323class SynthesisConfiguration :
324+ dump_intermediate_results : bool
324325 gate_limit_factor : float
325326 initial_timestep_limit : int
327+ intermediate_results_path : str
326328 minimize_gates_after_depth_optimization : bool
327329 minimize_gates_after_two_qubit_gate_optimization : bool
328330 n_threads : int
Original file line number Diff line number Diff line change 99#include " utils/logging.hpp"
1010
1111#include < chrono>
12+ #include < fstream>
1213
1314namespace cs {
1415
@@ -345,8 +346,18 @@ void CliffordSynthesizer::runMaxSAT(const EncoderConfig& config) {
345346
346347Results CliffordSynthesizer::callSolver (const EncoderConfig& config) {
347348 ++solverCalls;
348- auto encoder = encoding::SATEncoder (config);
349- return encoder.run ();
349+ auto encoder = encoding::SATEncoder (config);
350+ const auto res = encoder.run ();
351+ if (configuration.dumpIntermediateResults && res.sat ()) {
352+ const auto filename = configuration.intermediateResultsPath +
353+ " intermediate_" + std::to_string (solverCalls) +
354+ " .qasm" ;
355+ INFO () << " Dumping circuit to " << filename;
356+ std::ofstream file (filename);
357+ file << res.getResultCircuit ();
358+ file.close ();
359+ }
360+ return res;
350361}
351362
352363void CliffordSynthesizer::updateResults (const Configuration& config,
Original file line number Diff line number Diff line change @@ -87,8 +87,9 @@ class SynthesisTest : public ::testing::TestWithParam<TestConfiguration> {
8787 }
8888 std::cout << " Target tableau:\n " << targetTableau;
8989
90- config = Configuration ();
91- config.verbosity = plog::Severity::verbose;
90+ config = Configuration ();
91+ config.verbosity = plog::Severity::verbose;
92+ config.dumpIntermediateResults = true ;
9293 }
9394
9495 void TearDown () override {
You can’t perform that action at this time.
0 commit comments