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 PauliStrings as templates for easier interop #1081

Merged
merged 34 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
435ec8c
Initial implementation attempt
willsimmons1465 Sep 11, 2023
eeaddfc
Solve a bunch of linker errors
willsimmons1465 Sep 18, 2023
a95a372
Test comparators
willsimmons1465 Sep 18, 2023
7461c23
Test multiplications
willsimmons1465 Sep 18, 2023
9f99654
Tested hashing
willsimmons1465 Sep 18, 2023
7022419
Refactor Utils, OpType, Ops, Gate, Clifford
willsimmons1465 Sep 18, 2023
90f3de2
Refactored source and tests; some tests fail
willsimmons1465 Oct 2, 2023
b57a87a
Fix test errors
willsimmons1465 Oct 9, 2023
90ac4d4
Binders compile, failing json validation
willsimmons1465 Oct 10, 2023
3f419c5
Attempt to make serialisation backwards compatible
willsimmons1465 Oct 10, 2023
e9aa9b8
Fix remaining serialisation bugs
willsimmons1465 Oct 10, 2023
f08ddc8
Merge branch 'develop' into refactor/paulistring
willsimmons1465 Oct 10, 2023
291ae9a
Merge branch 'develop' into refactor/paulistring
willsimmons1465 Oct 16, 2023
e592255
Fixed it!
willsimmons1465 Oct 16, 2023
79a0bfa
Rename PauliStrings2 to PauliTensor
willsimmons1465 Oct 16, 2023
11d4dba
Remove old PauliStrings
willsimmons1465 Oct 16, 2023
f2d6bf5
Rename test_PauliString2
willsimmons1465 Oct 16, 2023
c453580
Rename file references
willsimmons1465 Oct 16, 2023
1d73aca
File references in CMakeLists
willsimmons1465 Oct 16, 2023
8b21d98
Bump tket version number
willsimmons1465 Oct 16, 2023
cf8177e
Run formatter
willsimmons1465 Oct 16, 2023
2452223
Fix binder errors
willsimmons1465 Oct 16, 2023
ac176f0
Merge branch 'develop' into refactor/paulistring
willsimmons1465 Oct 16, 2023
8c0cf89
Compiler errors on other OSs on CI
willsimmons1465 Oct 16, 2023
6b5e118
Fix stub changes
willsimmons1465 Oct 16, 2023
67b12e6
Test coverage
willsimmons1465 Oct 26, 2023
073364d
Fix comparison issue
willsimmons1465 Oct 26, 2023
ae49a76
Remove commented out code
willsimmons1465 Oct 26, 2023
ed900cb
Implement reviewer feedback
willsimmons1465 Oct 30, 2023
93e6673
Merge branch 'develop' into refactor/paulistring
willsimmons1465 Oct 30, 2023
6f796ee
Bump tket version numbers
willsimmons1465 Oct 30, 2023
999f67d
Docs formatting error on CI
willsimmons1465 Oct 30, 2023
fc7d345
Retain fix from merge conflict
willsimmons1465 Oct 30, 2023
f7510f9
Little bit more coverage
willsimmons1465 Oct 31, 2023
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
47 changes: 30 additions & 17 deletions pytket/binders/circuit/boxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,10 @@ void init_boxes(py::module &m) {
"An operation defined as the exponential of a tensor of Pauli "
"operations and a (possibly symbolic) phase parameter.")
.def(
py::init<
const py::tket_custom::SequenceVec<Pauli> &, const Expr &,
const CXConfigType &>(),
py::init([](const py::tket_custom::SequenceVec<Pauli> &paulis, Expr t,
CXConfigType config) {
return PauliExpBox(SymPauliTensor(paulis, t), config);
}),
"Construct :math:`e^{-\\frac12 i \\pi t \\sigma_0 \\otimes "
"\\sigma_1 \\otimes \\cdots}` from Pauli operators "
":math:`\\sigma_i \\in \\{I,X,Y,Z\\}` and a parameter "
Expand All @@ -263,10 +264,14 @@ void init_boxes(py::module &m) {
"An operation defined as a pair of exponentials of a tensor of Pauli "
"operations and their (possibly symbolic) phase parameters.")
.def(
py::init<
const py::tket_custom::SequenceVec<Pauli> &, const Expr &,
const py::tket_custom::SequenceVec<Pauli> &, Expr,
CXConfigType>(),
py::init([](const py::tket_custom::SequenceVec<Pauli> &paulis0,
Expr t0,
const py::tket_custom::SequenceVec<Pauli> &paulis1,
Expr t1, CXConfigType config) {
return PauliExpPairBox(
SymPauliTensor(paulis0, t0), SymPauliTensor(paulis1, t1),
config);
}),
"Construct a pair of Pauli exponentials of the form"
" :math:`e^{-\\frac12 i \\pi t_j \\sigma_0 \\otimes "
"\\sigma_1 \\otimes \\cdots}` from Pauli operator strings "
Expand Down Expand Up @@ -297,12 +302,13 @@ void init_boxes(py::module &m) {
.def(
py::init([](const py::tket_custom::SequenceVec<
std::pair<py::tket_custom::SequenceVec<Pauli>, Expr>>
&py_gadgets,
const CXConfigType &cx_config) {
std::vector<std::pair<std::vector<Pauli>, Expr>> gadgets(
std::make_move_iterator(py_gadgets.begin()),
std::make_move_iterator(py_gadgets.end()));
return PauliExpCommutingSetBox(gadgets, cx_config);
&pauli_gadgets,
CXConfigType config) {
std::vector<SymPauliTensor> gadgets;
for (const std::pair<py::tket_custom::SequenceVec<Pauli>, Expr> &g :
pauli_gadgets)
gadgets.push_back(SymPauliTensor(g.first, g.second));
return PauliExpCommutingSetBox(gadgets, config);
}),
"Construct a set of necessarily commuting Pauli exponentials of the "
"form"
Expand All @@ -317,7 +323,14 @@ void init_boxes(py::module &m) {
[](PauliExpCommutingSetBox &pbox) { return *pbox.to_circuit(); },
":return: the :py:class:`Circuit` described by the box")
.def(
"get_paulis", &PauliExpCommutingSetBox::get_pauli_gadgets,
"get_paulis",
[](const PauliExpCommutingSetBox &pbox) {
// For backwards compatibility with before templated PauliTensor
std::vector<std::pair<DensePauliMap, Expr>> gadgets;
for (const SymPauliTensor &g : pbox.get_pauli_gadgets())
gadgets.push_back({g.string, g.coeff});
return gadgets;
},
":return: the corresponding list of Pauli gadgets")
.def(
"get_cx_config", &PauliExpCommutingSetBox::get_cx_config,
Expand Down Expand Up @@ -677,15 +690,15 @@ void init_boxes(py::module &m) {
.def(
py::init([](const py::tket_custom::SequenceVec<std::string>
&pauli_strings) {
PauliStabiliserList stabilisers;
PauliStabiliserVec stabilisers;
for (auto &raw_string : pauli_strings) {
std::vector<Pauli> string;
bool coeff = true;
quarter_turns_t coeff = 0;
for (unsigned i = 0; i < raw_string.size(); i++) {
switch (raw_string[i]) {
case '-':
if (i == 0) {
coeff = false;
coeff = 2;
} else {
throw std::invalid_argument(
"Invalid Pauli string: " + raw_string);
Expand Down
6 changes: 3 additions & 3 deletions pytket/binders/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ PYBIND11_MODULE(partition, m) {
.def(
"add_result_for_term",
(void(MeasurementSetup::*)(
const QubitPauliString &,
const SpPauliString &,
const MeasurementSetup::MeasurementBitMap &)) &
MeasurementSetup::add_result_for_term,
"Add a new Pauli string with a corresponding BitMap", py::arg("term"),
Expand All @@ -153,7 +153,7 @@ PYBIND11_MODULE(partition, m) {

m.def(
"measurement_reduction",
[](const py::tket_custom::SequenceList<QubitPauliString> &strings,
[](const py::tket_custom::SequenceList<SpPauliString> &strings,
PauliPartitionStrat strat, GraphColourMethod method,
CXConfigType cx_config) {
return measurement_reduction(strings, strat, method, cx_config);
Expand All @@ -173,7 +173,7 @@ PYBIND11_MODULE(partition, m) {

m.def(
"term_sequence",
[](const py::tket_custom::SequenceList<QubitPauliString> &strings,
[](const py::tket_custom::SequenceList<SpPauliString> &strings,
PauliPartitionStrat strat, GraphColourMethod method) {
return term_sequence(strings, strat, method);
},
Expand Down
Loading
Loading