-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add BasePass.get_pre_conditions
and BasePass.get_post_conditions
#1689
Conversation
pytket/binders/passes.cpp
Outdated
} | ||
return pre_conditions; | ||
}, | ||
"Returns the pre condition Predicates for the given 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.
"Returns the pre condition Predicates for the given pass." | |
"Returns the precondition Predicates for the given 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.
done
pytket/binders/passes.cpp
Outdated
"Returns the pre condition Predicates for the given pass." | ||
"\n:return: A list of Predicate") | ||
.def( | ||
"get_post_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.
"get_post_conditions", | |
"get_postconditions", |
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.
done
pytket/binders/passes.cpp
Outdated
} | ||
return post_conditions; | ||
}, | ||
"Returns the post condition Predicates for the given 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.
"Returns the post condition Predicates for the given pass." | |
"Returns the postcondition Predicates for the given 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.
done
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 think it is also worth adding a function specifically to get the gate-set requirements of a pass; i.e. which gets the preconditions, checks for any GateSetPredicate
s, and returns the set intersection of their gate sets (or None
if there are no GateSetPredicate
s.)
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.
done
tket/conanfile.py
Outdated
@@ -23,7 +23,7 @@ | |||
|
|||
class TketConan(ConanFile): | |||
name = "tket" | |||
version = "1.3.48" | |||
version = "1.3.49" |
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.
This version bump shouldn't be necessary as the change only touches pytket.
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.
oops ofc - will revert
Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: Alec Edgington <[email protected]>
pytket/binders/passes.cpp
Outdated
OpTypeSet allowed_ops; | ||
for (const std::pair<const std::type_index, std::shared_ptr<tket::Predicate>> | ||
&p : base_pass.get_conditions().first) { | ||
if (p.second->to_string().substr(0, 17) == "GateSetPredicate:") { |
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 don't think this check is necessary. We can just use dynamic_cast
and ignore it if it returns nullptr
.
pytket/binders/passes.cpp
Outdated
if (p.second->to_string().substr(0, 17) == "GateSetPredicate:") { | ||
std::shared_ptr<GateSetPredicate> gsp_ptr = | ||
std::dynamic_pointer_cast<GateSetPredicate>(p.second); | ||
if (allowed_ops.empty()) { |
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.
This will end up giving the wrong result in the (admittedly unlikely) case that we have already encountered two GateSetPredicate
s with empty intersection. I suggest using a std::optional<OpTypeSet>
, where no-value means all all ops are allowed.
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.
done (I think)
pytket/binders/passes.cpp
Outdated
"Returns the intersection of all set of OpType for all " | ||
"GateSetPredicate in the `BasePass` preconditions.", | ||
"\n\n:return: A set of allowed OpType") |
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.
"Returns the intersection of all set of OpType for all " | |
"GateSetPredicate in the `BasePass` preconditions.", | |
"\n\n:return: A set of allowed OpType") | |
"Returns the intersection of all set of OpType for all " | |
"GateSetPredicate in the `BasePass` preconditions, or `None` if there are no gate-set predicares.", | |
"\n\n:return: A set of allowed OpType, or `None`") |
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.
done
pytket/conanfile.py
Outdated
@@ -38,7 +38,7 @@ def requirements(self): | |||
self.requires("pybind11_json/0.2.14") | |||
self.requires("symengine/0.13.0") | |||
self.requires("tkassert/0.3.4@tket/stable") | |||
self.requires("tket/1.3.49@tket/stable") | |||
self.requires("tket/1.3.50@tket/stable") |
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.
This shouldn't need updating.
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've reverted - let's see if the same issue comes up
pytket/tests/predicates_test.py
Outdated
assert OpType.CX in gate_set # type: ignore | ||
assert OpType.Measure in gate_set # type: ignore |
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.
Should be able to avoid the type: ignore
s by first asserting that gate_set is not None
.
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.
done
tket/conanfile.py
Outdated
@@ -23,7 +23,7 @@ | |||
|
|||
class TketConan(ConanFile): | |||
name = "tket" | |||
version = "1.3.49" | |||
version = "1.3.50" |
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.
Shouldn't be needed.
…1689) * Add new methods for getting predicates from python passes * bump * Update predicates_test.py * Update pytket/binders/passes.cpp Co-authored-by: Alec Edgington <[email protected]> * Update pytket/binders/passes.cpp Co-authored-by: Alec Edgington <[email protected]> * add get gate_set, check tests * Update predicates_test.py * Update predicates_test.py * Update predicates_test.py * bump, fix ruff issue * regen stubs * Update predicates_test.py * Update predicates_test.py * Update predicates_test.py * addresss comments * Update predicates_test.py --------- Co-authored-by: Alec Edgington <[email protected]>
…1689) * Add new methods for getting predicates from python passes * bump * Update predicates_test.py * Update pytket/binders/passes.cpp Co-authored-by: Alec Edgington <[email protected]> * Update pytket/binders/passes.cpp Co-authored-by: Alec Edgington <[email protected]> * add get gate_set, check tests * Update predicates_test.py * Update predicates_test.py * Update predicates_test.py * bump, fix ruff issue * regen stubs * Update predicates_test.py * Update predicates_test.py * Update predicates_test.py * addresss comments * Update predicates_test.py --------- Co-authored-by: Alec Edgington <[email protected]>
Adds two new methods to
BasePass
in passes.cpp to expose pre conditions and post conditions for a pass to the python layer asList[Predicate]
.Related issues
#1675
Checklist