Skip to content
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

[refactor] new SingleQubitSquash class for squashing #168

Merged
merged 29 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
257800a
Refactor squashing
lmondada Jan 12, 2022
ecada8c
add explicit casting
lmondada Jan 13, 2022
479231a
do not commute no-ops
lmondada Jan 13, 2022
62d4821
changed squash_wire => squash_between
lmondada Jan 13, 2022
2a8d3a0
allow classical control in gen_euler_pass
lmondada Jan 13, 2022
b2cb5c8
commuting through special case
lmondada Jan 13, 2022
ed47c1b
fixup_angle is consistent in reverse mode
lmondada Jan 14, 2022
abe6628
improve symbolic cos
lmondada Jan 14, 2022
4032bc8
Update tket/src/Transformations/SingleQubitSquash/StandardSquash.cpp
lmondada Jan 19, 2022
f77dd8e
added conditional tests
lmondada Jan 19, 2022
1c5d234
moved squash_1qb_to_pqp
lmondada Jan 19, 2022
07fae18
added doc
lmondada Jan 19, 2022
5a6a1e5
addressed more comments
lmondada Jan 19, 2022
a8eb8e4
refactor squasher interface
lmondada Jan 19, 2022
69e3293
improved coverage
lmondada Jan 19, 2022
6d3ffd3
fixed tests
lmondada Jan 19, 2022
292774f
Merge branch 'develop' into refactor/squashing
lmondada Jan 19, 2022
035125b
added new files to local cmakefile
lmondada Jan 19, 2022
df1e3ae
removed infinite loop
lmondada Jan 19, 2022
6df0c8f
removed two useless tests
lmondada Jan 19, 2022
36d814e
fixed test
lmondada Jan 19, 2022
fee0ac0
fixed test (2)
lmondada Jan 19, 2022
75d19ad
replaced floats with fractions
lmondada Jan 20, 2022
6fa5d90
Update tket/src/Transformations/include/Transformations/SingleQubitSq…
lmondada Jan 20, 2022
873f698
Update tket/src/Transformations/include/Transformations/SingleQubitSq…
lmondada Jan 20, 2022
ffa6bac
added comment on well-behaved squashes
lmondada Jan 20, 2022
c3a1133
amended test instance
lmondada Jan 20, 2022
6344fc7
Revert "amended test instance"
cqc-alec Jan 24, 2022
2e06d5a
Workaround for symengine issue.
cqc-alec Jan 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions tket/src/Gate/Gate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,67 +377,73 @@ std::vector<Expr> Gate::get_params_reduced() const {
}

std::vector<Expr> Gate::get_tk1_angles() const {
const Expr half =
SymEngine::div(SymEngine::integer(1), SymEngine::integer(2));
const Expr quarter =
SymEngine::div(SymEngine::integer(1), SymEngine::integer(4));
const Expr eighth =
SymEngine::div(SymEngine::integer(1), SymEngine::integer(8));
switch (get_type()) {
case OpType::noop: {
return {0., 0., 0., 0.};
return {0, 0, 0, 0};
}
case OpType::Z: {
return {0., 0., 1., 0.5};
return {0, 0, 1, half};
}
case OpType::X: {
return {0., 1., 0., 0.5};
return {0, 1, 0, half};
}
case OpType::Y: {
return {0.5, 1., -0.5, 0.5};
return {half, 1, -half, half};
}
case OpType::S: {
return {0., 0., 0.5, 0.25};
return {0, 0, half, quarter};
}
case OpType::Sdg: {
return {0., 0., -0.5, -0.25};
return {0, 0, -half, -quarter};
}
case OpType::T: {
return {0., 0., 0.25, 0.125};
return {0, 0, quarter, eighth};
}
case OpType::Tdg: {
return {0., 0., -0.25, -0.125};
return {0, 0, -quarter, -eighth};
}
case OpType::V: {
return {0., 0.5, 0., 0.};
return {0, half, 0, 0};
}
case OpType::Vdg: {
return {0., -0.5, -0., 0.};
return {0, -half, 0, 0};
}
case OpType::SX: {
return {0., 0.5, 0., 0.25};
return {0, half, 0, quarter};
}
case OpType::SXdg: {
return {0., -0.5, 0., -0.25};
return {0, -half, 0, -quarter};
}
case OpType::H: {
return {0.5, 0.5, 0.5, 0.5};
return {half, half, half, half};
}
case OpType::Rx: {
return {0., params_.at(0), 0., 0.};
return {0, params_.at(0), 0, 0};
}
case OpType::Ry: {
return {0.5, params_.at(0), -0.5, 0.};
return {half, params_.at(0), -half, 0};
}
case OpType::Rz:
case OpType::PhaseGadget: {
return {0., 0., params_.at(0), 0.};
return {0, 0, params_.at(0), 0};
}
case OpType::U1: {
return {0., 0., params_.at(0), params_.at(0) / 2};
return {0, 0, params_.at(0), params_.at(0) / 2};
}
case OpType::U2: {
return {
params_.at(0) + 0.5, 0.5, params_.at(1) - 0.5,
params_.at(0) + half, half, params_.at(1) - half,
(params_.at(0) + params_.at(1)) / 2};
}
case OpType::U3: {
return {
params_.at(1) + 0.5, params_.at(0), params_.at(2) - 0.5,
params_.at(1) + half, params_.at(0), params_.at(2) - half,
(params_.at(1) + params_.at(2)) / 2};
}
case OpType::NPhasedX: {
Expand All @@ -446,13 +452,13 @@ std::vector<Expr> Gate::get_tk1_angles() const {
"OpType::NPhasedX can only be decomposed into a TK1 "
"if it acts on a single qubit");
}
return {params_.at(1), params_.at(0), -params_.at(1), 0.};
return {params_.at(1), params_.at(0), -params_.at(1), 0};
}
case OpType::PhasedX: {
return {params_.at(1), params_.at(0), -params_.at(1), 0.};
return {params_.at(1), params_.at(0), -params_.at(1), 0};
}
case OpType::TK1: {
return {params_.at(0), params_.at(1), params_.at(2), 0.};
return {params_.at(0), params_.at(1), params_.at(2), 0};
}
default: {
throw NotImplemented(
Expand Down
3 changes: 1 addition & 2 deletions tket/src/Predicates/PassGenerators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ PassPtr gen_squash_pass(
// converting chains of p, q rotations to minimal triplets of p,q-rotations (p,
// q in {Rx,Ry,Rz})
PassPtr gen_euler_pass(const OpType& q, const OpType& p, bool strict) {
PredicatePtr ccontrol_pred = std::make_shared<NoClassicalControlPredicate>();
PredicatePtrMap precons{CompilationUnit::make_type_pair(ccontrol_pred)};
PredicatePtrMap precons;

Transform t = Transform::squash_1qb_to_pqp(q, p, strict);
PostConditions pc{{}, {}, Guarantee::Preserve};
Expand Down
Loading