Skip to content

Commit 32ef781

Browse files
committed
Included optimization flag in treespile (sim. annealing to minimize Pauli weight)
1 parent 9431d97 commit 32ef781

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/cmd/fham_cmd.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ dvlab::Command fham_qubitize_cmd(FermionHamiltonianMgr& fham_mgr, QubitHamiltoni
133133
qbham_mgr.set_filename(fham_mgr.get_filename());
134134
qbham_mgr.add_procedures(fham_mgr.get_procedures());
135135

136-
std::string proc_name = strategy == "jw" ? "fham_qubitize_jw" : "fham_qubitize_ternary_tree";
136+
std::string proc_name = strategy == "ternary_tree" ? "fham_qubitize_ternary_tree" : "fham_qubitize_jw";
137137
if (strategy == "ternary_tree" && optimize) proc_name += "_optimized";
138138
qbham_mgr.add_procedure(proc_name);
139139

@@ -194,6 +194,9 @@ dvlab::Command fham_treespile_cmd(
194194
.constraint(choices_allow_prefix({"log_success_rate", "default"}))
195195
.default_value("default")
196196
.help("cost function for Floyd-Warshall used inside treespile");
197+
parser.add_argument<bool>("-o", "--optimize")
198+
.action(store_true)
199+
.help("Run simulated annealing to minimize Pauli weight");
197200
},
198201
[&](ArgumentParser const& parser) {
199202
if (device_mgr.empty()) {
@@ -217,12 +220,13 @@ dvlab::Command fham_treespile_cmd(
217220

218221
auto const time = parser.get<double>("time");
219222
auto const cost_fn_str = parser.get<std::string>("--cost-fn");
223+
bool optimize = parser.get<bool>("--optimize");
220224
auto cost_fn = device::default_floyd_warshall_cost;
221225
if (dvlab::str::is_prefix_of(dvlab::str::tolower_string(cost_fn_str), "log_success_rate")) {
222226
cost_fn = device::log_success_rate_floyd_warshall_cost;
223227
}
224228

225-
auto const result = treespile(*f_ham, device, time, n_steps, cost_fn);
229+
auto const result = treespile(*f_ham, device, time, n_steps, cost_fn, optimize);
226230

227231
if (!result.has_value()) {
228232
auto const reason = result.error();

src/hamiltonian/treespile.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,8 @@ treespile(
449449
device::Device const& device,
450450
double time,
451451
size_t n_trotterization_steps,
452-
device::APSPCostFnType const& cost_fn) {
452+
device::APSPCostFnType const& cost_fn,
453+
bool optimize) {
453454
//
454455
using FailReason = TreespileFailReason;
455456

@@ -470,14 +471,18 @@ treespile(
470471

471472
auto const apsp = floyd_warshall(device, cost_fn);
472473

473-
auto const tree = build_bonsai_ternary_tree(device, apsp, n_modes);
474+
auto tree = build_bonsai_ternary_tree(device, apsp, n_modes);
474475

475476
if (!tree.has_value()) {
476477
// NOTE: it's still possible for bonsai to fail because the device might
477478
// be disconnected.
478479
return tl::unexpected(FailReason::tt_build_failed_not_enough_qubits);
479480
}
480481

482+
if (optimize) {
483+
tree = optimize_mapping(*tree, hamiltonian, &device);
484+
}
485+
481486
auto const mapping = TernaryTreeMapping(tree.value());
482487

483488
auto const qubit_hamiltonian = qubitize(hamiltonian, mapping);

src/hamiltonian/treespile.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ treespile(
3737
device::Device const& device,
3838
double time,
3939
size_t n_trotterization_steps,
40-
device::APSPCostFnType const& cost_fn = device::default_floyd_warshall_cost);
40+
device::APSPCostFnType const& cost_fn = device::default_floyd_warshall_cost,
41+
bool optimize = false);
4142

4243

4344
} // namespace qsyn::hamiltonian

0 commit comments

Comments
 (0)