-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make CXMappingPass
a StandardPass
with round-trip serialization and deserialization
#1575
Conversation
CXMappingPass
a StandardPass
with round-trip serialization and deserialization
PassPtr return_pass = | ||
rebase_pass >> gen_full_mapping_pass(arc, placement_ptr, config); | ||
if (delay_measures) return_pass = return_pass >> DelayMeasures(); | ||
return_pass = return_pass >> rebase_pass >> | ||
gen_decompose_routing_gates_to_cxs_pass(arc, directed_cx); | ||
return return_pass; | ||
Transform t{[=](Circuit& circ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not totally confident in this: should we be passing a std::shared_ptr<unit_bimaps_t>
as well as a Circuit&
to the Transform
constructor? If so what should we do with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would the unit_bimaps_t
object be for? I might be forgetting some TKET infrastructure here. Certainly we don't need to pass any kind of qubit placement if that's what it's referring to (as the circuit UnitID are updated).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure myself. Seems to be used in placement passes where units are renamed (e.g. gen_placement_pass()
). So I assume not necessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm - I'm now not sure. Just double checking, the unit_bimaps_t
object tracks how qubits are re-labelled/permuted by optimisation? I'm now wondering if we should have always had them and not having them was an oversight? gen_routing_pass
does seem to have them, so I think in-fact we do need them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check my last commit. I don't know if this is correct, but I don't know what else to do with the maps either!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Relabel all two-qubit gates
CompilationUnit cu(circ);
bool changed = rebase_pass->apply(cu);
circ = cu.get_circ_ref();
// Now try placement, falling back on "LinePlacement" if "GraphPlacement" fails
try {
changed = changed | placement_ptr->place(circ, maps);
} catch (const std::runtime_error& e) {
std::stringstream ss;
ss << "PlacementPass failed with message: " << e.what()
<< " Fall back to LinePlacement.";
tket_log()->warn(ss.str());
Placement::Ptr line_placement_ptr = std::make_shared<LinePlacement>(
placement_ptr->get_architecture_ref());
changed = changed | line_placement_ptr->place(circ, maps);
}
// Now route
MappingManager mm(std::make_shared<Architecture>(arc));
changed = changed | mm.route_circuit_with_maps(circ, config, maps);
// Now decompose routing gates to cx gates (this won't change maps)
cu(circ);
if(delay_measures){
DelayMeasures()->apply(cu);
}
gen_decompose_routing_gates_to_cxs_pass(arc, directed_cx)->apply(cu);
circ = cu.get_circ_ref();
return changed;
}```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me, but I've asked for some clarification on the question.
PassPtr return_pass = | ||
rebase_pass >> gen_full_mapping_pass(arc, placement_ptr, config); | ||
if (delay_measures) return_pass = return_pass >> DelayMeasures(); | ||
return_pass = return_pass >> rebase_pass >> | ||
gen_decompose_routing_gates_to_cxs_pass(arc, directed_cx); | ||
return return_pass; | ||
Transform t{[=](Circuit& circ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would the unit_bimaps_t
object be for? I might be forgetting some TKET infrastructure here. Certainly we don't need to pass any kind of qubit placement if that's what it's referring to (as the circuit UnitID are updated).
PassPtr return_pass = | ||
rebase_pass >> gen_full_mapping_pass(arc, placement_ptr, config); | ||
if (delay_measures) return_pass = return_pass >> DelayMeasures(); | ||
return_pass = return_pass >> rebase_pass >> | ||
gen_decompose_routing_gates_to_cxs_pass(arc, directed_cx); | ||
return return_pass; | ||
Transform t{[=](Circuit& circ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm - I'm now not sure. Just double checking, the unit_bimaps_t
object tracks how qubits are re-labelled/permuted by optimisation? I'm now wondering if we should have always had them and not having them was an oversight? gen_routing_pass
does seem to have them, so I think in-fact we do need them?
This reverts commit eaa9d25.
PassPtr return_pass = | ||
rebase_pass >> gen_full_mapping_pass(arc, placement_ptr, config); | ||
if (delay_measures) return_pass = return_pass >> DelayMeasures(); | ||
return_pass = return_pass >> rebase_pass >> | ||
gen_decompose_routing_gates_to_cxs_pass(arc, directed_cx); | ||
return return_pass; | ||
Transform t{[=](Circuit& circ, std::shared_ptr<unit_bimaps_t> maps) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work?
`Transform t{[=](Circuit& circ, std::shared_ptr<unit_bimaps_t> maps) {
// Relabel all two-qubit gates
CompilationUnit cu(circ);
bool changed = rebase_pass->apply(cu);
circ = cu.get_circ_ref();
// Now try placement, falling back on "LinePlacement" if "GraphPlacement" fails
try {
changed = changed | placement_ptr->place(circ, maps);
} catch (const std::runtime_error& e) {
std::stringstream ss;
ss << "PlacementPass failed with message: " << e.what()
<< " Fall back to LinePlacement.";
tket_log()->warn(ss.str());
Placement::Ptr line_placement_ptr = std::make_shared<LinePlacement>(
placement_ptr->get_architecture_ref());
changed = changed | line_placement_ptr->place(circ, maps);
}
// Now route
MappingManager mm(std::make_shared<Architecture>(arc));
changed = changed | mm.route_circuit_with_maps(circ, config, maps);
// Now decompose routing gates to cx gates (this won't change maps)
cu(circ);
if(delay_measures){
DelayMeasures()->apply(cu);
}
gen_decompose_routing_gates_to_cxs_pass(arc, directed_cx)->apply(cu);
circ = cu.get_circ_ref();
return changed;
}`
PassPtr return_pass = | ||
rebase_pass >> gen_full_mapping_pass(arc, placement_ptr, config); | ||
if (delay_measures) return_pass = return_pass >> DelayMeasures(); | ||
return_pass = return_pass >> rebase_pass >> | ||
gen_decompose_routing_gates_to_cxs_pass(arc, directed_cx); | ||
return return_pass; | ||
Transform t{[=](Circuit& circ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Relabel all two-qubit gates
CompilationUnit cu(circ);
bool changed = rebase_pass->apply(cu);
circ = cu.get_circ_ref();
// Now try placement, falling back on "LinePlacement" if "GraphPlacement" fails
try {
changed = changed | placement_ptr->place(circ, maps);
} catch (const std::runtime_error& e) {
std::stringstream ss;
ss << "PlacementPass failed with message: " << e.what()
<< " Fall back to LinePlacement.";
tket_log()->warn(ss.str());
Placement::Ptr line_placement_ptr = std::make_shared<LinePlacement>(
placement_ptr->get_architecture_ref());
changed = changed | line_placement_ptr->place(circ, maps);
}
// Now route
MappingManager mm(std::make_shared<Architecture>(arc));
changed = changed | mm.route_circuit_with_maps(circ, config, maps);
// Now decompose routing gates to cx gates (this won't change maps)
cu(circ);
if(delay_measures){
DelayMeasures()->apply(cu);
}
gen_decompose_routing_gates_to_cxs_pass(arc, directed_cx)->apply(cu);
circ = cu.get_circ_ref();
return changed;
}```
This reverts commit ce3f8a3.
@@ -480,14 +481,53 @@ PassPtr gen_cx_mapping_pass( | |||
bool delay_measures) { | |||
OpTypeSet gate_set = all_single_qubit_types(); | |||
gate_set.insert(OpType::CX); | |||
PassPtr rebase_pass = | |||
gen_rebase_pass(gate_set, CircPool::CX(), CircPool::tk1_to_tk1); | |||
PassPtr rebase_pass = gen_auto_rebase_pass(gate_set); | |||
PassPtr return_pass = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove the references to return pass here I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used below in the line
PassConditions conditions = return_pass->get_conditions();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...which I think is still correct, although there may be an easier way to construct these conditions.
Description
Use
AutoRebase
instead ofRebaseCustom
in the pass; and wrap up theSequencePass
in aStandardPass
so that serialization and deserialization are inverse.Related issues
Fixes #1573 .
Checklist