Skip to content

Commit 6520a36

Browse files
authored
🔊 Allow to dump intermediate synthesis results (#243)
1 parent 288d5ab commit 6520a36

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

include/cliffordsynthesis/Configuration.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff 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;

mqt/qmap/bindings.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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'.")

mqt/qmap/pyqmap.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,10 @@ class Verbosity:
321321
def value(self) -> int: ...
322322

323323
class 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

src/cliffordsynthesis/CliffordSynthesizer.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "utils/logging.hpp"
1010

1111
#include <chrono>
12+
#include <fstream>
1213

1314
namespace cs {
1415

@@ -345,8 +346,18 @@ void CliffordSynthesizer::runMaxSAT(const EncoderConfig& config) {
345346

346347
Results 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

352363
void CliffordSynthesizer::updateResults(const Configuration& config,

test/cliffordsynthesis/test_synthesis.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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 {

0 commit comments

Comments
 (0)