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

[feature] RV3.1 #256

Merged
merged 181 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from 178 commits
Commits
Show all changes
181 commits
Select commit Hold shift + click to select a range
3c84f72
Update build_and_test.yml
sjdilkes Oct 22, 2021
39f46d3
Feature/TokenSwapping (#94)
sjdilkes Oct 25, 2021
8ba7968
Add "MappingManager" class and port older routing solution (#95)
sjdilkes Oct 25, 2021
5b50029
Add token swapping stage to routing v3 (#96)
sjdilkes Oct 26, 2021
4c92d8d
Assert candidate swaps size (#108)
yao-cqc Nov 9, 2021
edba555
Merge branch 'develop' into feature/routing-v3
sjdilkes Dec 13, 2021
6592cfd
Update Architecture method names
sjdilkes Dec 13, 2021
b3cda73
get_all_nodes -> nodes
sjdilkes Dec 13, 2021
a61e1fb
Merge branch 'develop' into feature/routing-v3
sjdilkes Jan 4, 2022
af08810
Merge branch 'develop' into feature/routing-v3
sjdilkes Jan 5, 2022
24be612
Update Compilation Passes to use RoutingV3 (#115)
sjdilkes Jan 7, 2022
8295443
Merge branch 'develop' into feature/routing-v3
sjdilkes Jan 7, 2022
ad98c38
Remove outdated Routing code from repository (#165)
sjdilkes Jan 11, 2022
d46a49c
Improve LexiRoute.cpp coverage
sjdilkes Jan 14, 2022
1f71597
Improve MappingFrontier.cpp test coverage
sjdilkes Jan 14, 2022
1319c0e
Merge branch 'develop' into feature/routing-v3
sjdilkes Jan 17, 2022
b31c2c0
Rmoeve decmopose_module method
sjdilkes Jan 17, 2022
b18a8db
readd missing test
sjdilkes Jan 17, 2022
0941f74
Update LexiRoute test coverage
sjdilkes Jan 17, 2022
d9aa114
Remove redundant comments
sjdilkes Jan 18, 2022
eba680a
Feature/reorder multi qubit gates (#157)
yao-cqc Jan 18, 2022
89a3dfe
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
sjdilkes Jan 18, 2022
c9cf8b2
modify TKET_ASSERT: allow extra messages, catch exceptions in evaluation
drzenharper Jan 19, 2022
b2b0680
replace some exceptions with tket asserts; should be ignored by test …
drzenharper Jan 19, 2022
7b6289b
Merge branch 'develop' into feature/routing-v3
sjdilkes Jan 19, 2022
05c3908
Start moving files for modularisation
sjdilkes Jan 20, 2022
548e52e
compilation refactor commit
sjdilkes Feb 1, 2022
edeaf70
Reorder base cmake
sjdilkes Feb 1, 2022
8b5f108
add assertmessage.cpp to compiilation
sjdilkes Feb 1, 2022
c1f3e53
Rework TokenSwapping includes
sjdilkes Feb 2, 2022
e0d7dee
clang format
sjdilkes Feb 2, 2022
568283f
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 2, 2022
33436f1
update linking for pytket
sjdilkes Feb 2, 2022
66ce863
reformat with black
sjdilkes Feb 2, 2022
3aab473
Revert "reformat with black"
sjdilkes Feb 2, 2022
a9f7478
reformat setup.py
sjdilkes Feb 2, 2022
0516423
update proptests cmakelists
sjdilkes Feb 2, 2022
7e37426
Feature/add serialisation for multi qubit reorder (#184)
yao-cqc Feb 3, 2022
25bf193
Update test coverage for RoutingMethod serialization
sjdilkes Feb 3, 2022
df0c739
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
sjdilkes Feb 3, 2022
c4f427e
make mapping_frontier from mapping_frontier
sjdilkes Feb 3, 2022
389fc2a
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 3, 2022
991b85d
routing -> mapping
sjdilkes Feb 3, 2022
df99fbf
use TKET_ASSERT_WITH_THROW instead of TKET_ASSERT
drzenharper Feb 3, 2022
8fbe2f4
Replace TKET_ASSERT with throw and use GCOVR_EXCL_START,STOP where ap…
drzenharper Feb 3, 2022
719498a
replace throws with TKET_ASSERT_WITH_THROW where appropriate
drzenharper Feb 3, 2022
fd09f42
Add the TKET_ASSERT_WITH_THROW macro
drzenharper Feb 3, 2022
fc6bbe8
add simple swap functions tests
drzenharper Feb 3, 2022
3e4ee20
add TKET_ASSERT_WITH_THROW tests, for detailed error messages
drzenharper Feb 3, 2022
2d3a1ab
clang format
drzenharper Feb 3, 2022
740cfc6
try to fix code coverage branching problems in TKET_ASSERT_WITH_THROW…
drzenharper Feb 4, 2022
04efd72
correct "does not return a value" error
drzenharper Feb 4, 2022
1b667a5
Infra/use bimap for quantum boundary (#185)
yao-cqc Feb 4, 2022
7fede77
remove try/catch from tket assert with throw, to cut down branching
drzenharper Feb 4, 2022
ca40c43
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
drzenharper Feb 4, 2022
5991a8c
remove TKET_ASSERT_WITH_THROW, replace with TKET_ASSERT
drzenharper Feb 7, 2022
032f64e
Remove AssertMessage(), add TKET_ASSERT_WITH_MESSAGE
drzenharper Feb 7, 2022
52f221c
manually add coverage exclusion tags for now, until the branching pro…
drzenharper Feb 8, 2022
8e7d4be
rename method, remove predicate from routing
sjdilkes Feb 8, 2022
7d7ba1f
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 8, 2022
dc761e0
Add copyright information
sjdilkes Feb 8, 2022
d805b0b
[RV3] [refactor] Clean up of the dependencies of the modules (#199)
cqc-melf Feb 8, 2022
e3f2b68
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 9, 2022
e8f23dc
add bimaps attribute to MappingFrontier
sjdilkes Feb 9, 2022
4a210cc
update_quantum_boundary_uids remaps bimaps entries
sjdilkes Feb 9, 2022
3d997b4
[1777] Split `LexiRouteRoutingMethod` into two methods (#209)
sjdilkes Feb 10, 2022
2bc26c0
[1795] RoutingMethod for Box Decompositoin (#212)
sjdilkes Feb 10, 2022
eef94d6
Merge branch 'expose-get_swaps' into wheel/feature/RV3.1
sjdilkes Feb 10, 2022
0695935
update ci check (#210)
cqc-melf Feb 10, 2022
1b2b806
Merge branch 'feature/RV3.1' into wheel/feature/RV3.1
sjdilkes Feb 11, 2022
bac8cc2
Update build_and_test.yml
sjdilkes Feb 11, 2022
2d2d25d
Update changelog.rst
sjdilkes Feb 11, 2022
20404bf
Update copyright dates
sjdilkes Feb 11, 2022
3cffd1f
Update pytket/binders/mapping.cpp
sjdilkes Feb 11, 2022
7c092f2
Update pytket/binders/mapping.cpp
sjdilkes Feb 11, 2022
9a9007d
Update pytket/binders/mapping.cpp
sjdilkes Feb 11, 2022
849c7c5
Corrections for PR
sjdilkes Feb 11, 2022
8ed2f2b
Remove tokenswapping from dependneices
sjdilkes Feb 14, 2022
2b20d2f
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
sjdilkes Feb 14, 2022
86fb61e
Feature/decompose boxes in routing (#197)
yao-cqc Feb 14, 2022
4d2dbce
update compilation for tokenswapping
sjdilkes Feb 14, 2022
0202c30
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
sjdilkes Feb 14, 2022
a112236
Revert "Feature/decompose boxes in routing (#197)"
sjdilkes Feb 14, 2022
650a189
Address PR Requested changes
sjdilkes Feb 14, 2022
99f3c61
dummy pythonfile
sjdilkes Feb 14, 2022
0e742a8
change copyright to 2022
drzenharper Feb 14, 2022
ca30a50
remove unused code, including PathFinderInterface
drzenharper Feb 14, 2022
3366e22
rename HybridTsa00 -> HybridTsa; move files out of include directory
drzenharper Feb 14, 2022
b67528c
move DebugFunctions into tests
drzenharper Feb 14, 2022
db33a86
move get_swaps_lower_bound out of tket into tests
drzenharper Feb 14, 2022
3e518df
simple typos; unused code; extra comments, asserts
drzenharper Feb 14, 2022
8719249
rename main_entry_functions -> SwapsFromQubitMapping; remove unused f…
drzenharper Feb 14, 2022
07aa0ed
move RNG from token swapping to Utils; erase tests/Graphs/RNG
drzenharper Feb 14, 2022
f065447
move get_random_set out of token swapping into test utils
drzenharper Feb 14, 2022
34507b6
move some stuff out of namespace tsa_internal into namespace tket
drzenharper Feb 14, 2022
7e08c8c
more cleanup
drzenharper Feb 14, 2022
067782d
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
drzenharper Feb 15, 2022
efeb704
clang format
drzenharper Feb 15, 2022
c88e949
added OpType dependency to token swapping
drzenharper Feb 15, 2022
ef57306
clang format
drzenharper Feb 15, 2022
192171a
replace throws with TKET_ASSERT_WITH_MESSAGE
drzenharper Feb 15, 2022
61a7b7e
move BruteForceColouring.hpp, ColouringPriority.hpp out of include di…
drzenharper Feb 15, 2022
51cabf0
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 15, 2022
9694e9b
Merge branch 'feature/routing-v3' into feature/RV3.1
sjdilkes Feb 15, 2022
fff97a9
add TokenSwappingWithArch project; move files out of TokenSwapping
drzenharper Feb 15, 2022
96a8aa6
remove architecture from TokenSwapping
drzenharper Feb 15, 2022
890180b
move DistancesInterface, NeighboursInterface out of namespace tsa_int…
drzenharper Feb 15, 2022
b460561
update TokenSwapping tests to use TokenSwappingWithArch
drzenharper Feb 15, 2022
97b1efa
bool type for delay_measures
sjdilkes Feb 15, 2022
f7878df
Create architecture_test.py
sjdilkes Feb 15, 2022
3a1ce49
Reduce test times: add TSGlobalTestParameters with run_long_tests option
drzenharper Feb 15, 2022
f1e2c0b
add test_DebugFunctions.cpp and remove test coverage exclusion
drzenharper Feb 15, 2022
281e70a
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
drzenharper Feb 15, 2022
de2f963
Remove unreachable code.
drzenharper Feb 15, 2022
d7bbd01
update architecture binder
sjdilkes Feb 16, 2022
c6259aa
Revert "update architecture binder"
sjdilkes Feb 16, 2022
7533f90
formatting, remove nodegraph test
sjdilkes Feb 16, 2022
220a7b0
update architecture and mapping tests
sjdilkes Feb 16, 2022
1bd2dfd
add architecture_aware_synthesis_test.py
sjdilkes Feb 16, 2022
770ac41
Create placement_test.py
sjdilkes Feb 16, 2022
9fbbd95
Update range of python mapping tests
sjdilkes Feb 16, 2022
f7452df
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
sjdilkes Feb 16, 2022
f10be47
update routing test coverage
sjdilkes Feb 16, 2022
0c59a24
Merge branch 'feature/routing-v3' into feature/RV3.1
sjdilkes Feb 16, 2022
09fcd8a
add ci run on push on - feature/RV3.1
cqc-melf Feb 16, 2022
5a3f190
fix compilation issues
sjdilkes Feb 16, 2022
6069be2
Merge branch 'feature/RV3.1' into wheel/feature/RV3.1
sjdilkes Feb 16, 2022
c819859
remove token_swapping_method
sjdilkes Feb 16, 2022
d219fef
Update test_lexiroute
sjdilkes Feb 16, 2022
3190588
Merge branch 'feature/RV3.1' of https://github.com/CQCL/tket into fea…
sjdilkes Feb 16, 2022
ed59309
add predicate back
sjdilkes Feb 16, 2022
57126ce
update setup.py
sjdilkes Feb 16, 2022
df61866
Add LexiLabellingMethod
sjdilkes Feb 16, 2022
b75e7f9
Cover Alec's comments
sjdilkes Feb 16, 2022
abe3445
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 16, 2022
a1b5a49
format transform_test
sjdilkes Feb 16, 2022
f24e76b
change length of line
sjdilkes Feb 16, 2022
7eaf6fe
remove trailing white space
sjdilkes Feb 16, 2022
904bd16
name -> name_of_ethod
sjdilkes Feb 16, 2022
8fe485f
name -> name_of_method RoutingMethod
sjdilkes Feb 16, 2022
ecd9b51
tokenswappingwitharch
sjdilkes Feb 16, 2022
329f223
add type ignores
sjdilkes Feb 17, 2022
f9394eb
"name_of_method" -> "name'
sjdilkes Feb 18, 2022
abbe67c
merge from rv3
cqc-melf Feb 18, 2022
4f2ded6
Update valid_operation description
sjdilkes Feb 18, 2022
517c883
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 18, 2022
a53b7ee
reformat transform_test
sjdilkes Feb 18, 2022
4999115
remove second auto_rebase_pass
sjdilkes Feb 18, 2022
8575f32
Merge branch 'develop' into feature/routing-v3
cqc-melf Feb 18, 2022
eca1eac
merge
cqc-melf Feb 18, 2022
ac29545
Add missing import.
cqc-alec Feb 18, 2022
222fee6
Merge branch 'develop' into feature/routing-v3
cqc-alec Feb 18, 2022
e3ae6bc
Add option to tket-tests conan build determining whether full tests a…
cqc-alec Feb 18, 2022
5245c1f
remove TokenSwappingWithArch project; move files into Architecture
drzenharper Feb 18, 2022
3435365
Set "full tests" option on scheduled CI runs only.
cqc-alec Feb 18, 2022
237e23e
change TKET_ASSERT_WITH_MESSAGE to have parentheses around message
drzenharper Feb 18, 2022
042ab9b
Add note to README.
cqc-alec Feb 18, 2022
d40c098
rename HybridTSA_00 to HybridTsa
drzenharper Feb 18, 2022
080a878
Replace TSGlobalTestParameters with #ifdef TKET_TESTS_FULL
drzenharper Feb 18, 2022
61dde34
commit other forgotten files
drzenharper Feb 18, 2022
8820c92
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
drzenharper Feb 18, 2022
6809f96
Remove GetTketAssertMessage and TKET_ASSERT_WITH_MESSAGE, go back to …
drzenharper Feb 18, 2022
587780a
clang format
drzenharper Feb 18, 2022
c7a830a
Move test_Utils.cpp to test/Utils directory, rename to test_HelperFun…
drzenharper Feb 18, 2022
efeeca3
fix "function does not return a value" error
drzenharper Feb 18, 2022
ac4d57c
fix "non-void function does not return a value" error, attempt 2!
drzenharper Feb 18, 2022
b704bb1
Forgot to remove final TokenSwappingWithArch bits
drzenharper Feb 18, 2022
db395d8
Fix build failure.
cqc-alec Feb 18, 2022
39f1d86
Fix for mypy,
cqc-alec Feb 18, 2022
e2d42b5
merge
cqc-melf Feb 19, 2022
05dda1f
[fix] Feature/rv3.1 (#223)
cqc-melf Feb 19, 2022
ba2f1d3
Merge branch 'develop' into feature/RV3.1
sjdilkes Feb 21, 2022
d58ffa6
name_of_method -> name
sjdilkes Feb 21, 2022
ba96e50
Merge develop into feature/RV3.1 (#255)
sjdilkes Feb 25, 2022
80914ba
[TKET-1778] add architecture operation valid changes (#248)
cqc-melf Feb 25, 2022
eb1b1ea
Merge branch 'develop' into feature/RV3.1
sjdilkes Feb 28, 2022
cefa92c
Update build_and_test.yml
sjdilkes Feb 28, 2022
967bcf0
address PR comments
sjdilkes Feb 28, 2022
cd99996
Update pytket/docs/changelog.rst
sjdilkes Feb 28, 2022
2a068ab
Update pytket/binders/architecture.cpp
sjdilkes Feb 28, 2022
22dda0b
Update pytket/docs/changelog.rst
sjdilkes Feb 28, 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
9 changes: 9 additions & 0 deletions pytket/binders/architecture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include "Circuit/Circuit.hpp"
#include "Utils/Json.hpp"
#include "binder_json.hpp"
#include "binder_utils.hpp"
#include "typecast.hpp"

namespace py = pybind11;
using json = nlohmann::json;
Expand Down Expand Up @@ -56,6 +59,12 @@ PYBIND11_MODULE(architecture, m) {
"given two nodes in Architecture, "
"returns distance between them",
py::arg("node_0"), py::arg("node_1"))
.def(
cqc-alec marked this conversation as resolved.
Show resolved Hide resolved
"valid_operation", &Architecture::valid_operation,
"Returns true if the given operation acting on the given ",
"nodes can be executed on the Architecture connectivity graph."
"\n\n:param uids: UnitID validity is being checked for",
sjdilkes marked this conversation as resolved.
Show resolved Hide resolved
py::arg("uids"))
cqc-alec marked this conversation as resolved.
Show resolved Hide resolved
.def(
"get_adjacent_nodes", &Architecture::get_neighbour_nodes,
"given a node, returns adjacent nodes in Architecture.",
Expand Down
15 changes: 14 additions & 1 deletion pytket/binders/mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
// limitations under the License.

#include <pybind11/functional.h>
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>

#include "Circuit/Circuit.hpp"
#include "Mapping/LexiLabelling.hpp"
#include "Mapping/LexiRoute.hpp"
#include "Mapping/MappingManager.hpp"
#include "Mapping/RoutingMethodCircuit.hpp"
#include "binder_utils.hpp"

namespace py = pybind11;

Expand Down Expand Up @@ -63,14 +68,22 @@ PYBIND11_MODULE(mapping, m) {
RoutingMethod>(
m, "LexiRouteRoutingMethod",
"Defines a RoutingMethod object for mapping circuits that uses the "
"Lexicographical Comparison approach outlined in arXiv:1902.08091.")
"Lexicographical Comparison approach outlined in arXiv:1902.08091."
"Only supports 1-qubit, 2-qubit and barrier gates.")
.def(
py::init<unsigned>(),
"LexiRoute constructor.\n\n:param lookahead: Maximum depth of "
"lookahead employed when picking SWAP for purpose of logical to "
"physical mapping.",
py::arg("lookahead") = 10);

py::class_<
LexiLabellingMethod, std::shared_ptr<LexiLabellingMethod>, RoutingMethod>(
m, "LexiLabellingMethod",
"Defines a RoutingMethod for labelling Qubits that uses the "
"Lexicographical Comparison approach outlined in arXiv:1902.08091.")
.def(py::init<>(), "LexiLabellingMethod constructor.");

py::class_<MappingManager>(
m, "MappingManager",
"Defined by a pytket Architecture object, maps Circuit logical qubits "
Expand Down
12 changes: 8 additions & 4 deletions pytket/binders/passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <pybind11/functional.h>

#include "ArchAwareSynth/SteinerForest.hpp"
#include "Mapping/LexiLabelling.hpp"
#include "Mapping/LexiRoute.hpp"
#include "Mapping/RoutingMethod.hpp"
#include "Predicates/CompilerPass.hpp"
#include "Predicates/PassGenerators.hpp"
Expand All @@ -33,8 +35,9 @@ namespace tket {

static PassPtr gen_cx_mapping_pass_kwargs(
const Architecture &arc, const PlacementPtr &placer, py::kwargs kwargs) {
RoutingMethodPtr method = std::make_shared<LexiRouteRoutingMethod>();
std::vector<RoutingMethodPtr> config = {method};
std::vector<RoutingMethodPtr> config = {
std::make_shared<LexiLabellingMethod>(),
std::make_shared<LexiRouteRoutingMethod>()};
if (kwargs.contains("config")) {
config = py::cast<std::vector<RoutingMethodPtr>>(kwargs["config"]);
}
Expand All @@ -50,8 +53,9 @@ static PassPtr gen_cx_mapping_pass_kwargs(
}

static PassPtr gen_default_routing_pass(const Architecture &arc) {
RoutingMethodPtr method = std::make_shared<LexiRouteRoutingMethod>();
std::vector<RoutingMethodPtr> config = {method};
std::vector<RoutingMethodPtr> config = {
std::make_shared<LexiLabellingMethod>(),
std::make_shared<LexiRouteRoutingMethod>()};
return gen_routing_pass(arc, config);
}

Expand Down
6 changes: 5 additions & 1 deletion pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ Minor new features:
* New ``pytket.passes.NaivePlacementPass`` which completes a basic relabelling of all Circuit Qubit
not labelled as some Architecture Node to any available Architecture Node
* Add ``opgroups`` property to ``Circuit``.

* ``Architecture`` has new ``valid_operations`` method which returns true if passed UnitID respect
sjdilkes marked this conversation as resolved.
Show resolved Hide resolved
architecture constraints.
* New methods for mapping logical to physical circuits for some ``Architecture``: ``LexiRouteRoutingMethod``
sjdilkes marked this conversation as resolved.
Show resolved Hide resolved
``LexiLabellingMethod``, ``MultiGateReorderRoutingMethod``.
cqc-alec marked this conversation as resolved.
Show resolved Hide resolved

0.19.2 (February 2022)
----------------------

Expand Down
20 changes: 19 additions & 1 deletion pytket/tests/architecture_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from pytket.circuit import Node # type: ignore
from pytket.circuit import Node, Op, OpType, Circuit, Qubit, PhasePolyBox # type: ignore
from pytket.architecture import Architecture, SquareGrid, FullyConnected # type: ignore
import numpy as np


def test_architectures() -> None:
Expand Down Expand Up @@ -78,8 +79,25 @@ def test_arch_types() -> None:
assert isinstance(sg, SquareGrid)


def test_valid_operation() -> None:
edges = [(0, 1), (1, 2), (2, 0), (0, 3), (3, 4), (4, 5), (5, 6)]
arc = Architecture(edges)

assert not arc.valid_operation([Node(1), Node(3)])
assert arc.valid_operation([Node(0)])
assert arc.valid_operation([Node(0), Node(1)])
assert not arc.valid_operation([Node(0), Node(1), Node(2)])
assert not arc.valid_operation([Node(10)])
assert not arc.valid_operation([Node(10), Node(11), Node(15)])
assert not arc.valid_operation([Node(0), Node(1), Node(2), Node(3)])
assert not arc.valid_operation([Node(0), Node(4)])
assert not arc.valid_operation([Node(0), Node(1), Node(2)])
cqc-alec marked this conversation as resolved.
Show resolved Hide resolved
assert not arc.valid_operation([Node(0), Node(1), Node(4)])


if __name__ == "__main__":
test_architectures()
test_architecture_eq()
test_fully_connected()
test_arch_types()
test_valid_operation()
4 changes: 2 additions & 2 deletions pytket/tests/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pytket.circuit import Circuit, OpType, BasisOrder, Qubit, Bit, Node # type: ignore
from pytket.predicates import CompilationUnit # type: ignore
from pytket.passes import PauliSimp, CliffordSimp, ContextSimp # type: ignore
from pytket.mapping import MappingManager, LexiRouteRoutingMethod # type: ignore
from pytket.mapping import MappingManager, LexiRouteRoutingMethod, LexiLabellingMethod # type: ignore
from pytket.architecture import Architecture # type: ignore
from pytket.utils.outcomearray import OutcomeArray, readout_counts
from pytket.utils.prepare import prepare_circuit
Expand Down Expand Up @@ -528,7 +528,7 @@ def test_postprocess_3() -> None:

mm = MappingManager(arc)
rc = c.copy()
mm.route_circuit(rc, [LexiRouteRoutingMethod()])
mm.route_circuit(rc, [LexiLabellingMethod(), LexiRouteRoutingMethod()])
n_shots = 100
h = b.process_circuit(b.get_compiled_circuit(c), n_shots=n_shots, postprocess=True)
r = b.get_result(h)
Expand Down
7 changes: 4 additions & 3 deletions pytket/tests/mapping_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from pytket.mapping import MappingManager, RoutingMethodCircuit, LexiRouteRoutingMethod # type: ignore
from pytket.mapping import MappingManager, RoutingMethodCircuit, LexiRouteRoutingMethod, LexiLabellingMethod # type: ignore
from pytket.architecture import Architecture # type: ignore
from pytket import Circuit, OpType
from pytket.circuit import Node, Qubit # type: ignore
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_LexiRouteRoutingMethod() -> None:
nodes = [Node("test", 0), Node("test", 1), Node("test", 2)]
test_a = Architecture([[nodes[0], nodes[1]], [nodes[1], nodes[2]]])
test_mm = MappingManager(test_a)
test_mm.route_circuit(test_c, [LexiRouteRoutingMethod()])
test_mm.route_circuit(test_c, [LexiLabellingMethod(), LexiRouteRoutingMethod()])
routed_commands = test_c.get_commands()

assert routed_commands[0].op.type == OpType.CX
Expand Down Expand Up @@ -151,11 +151,11 @@ def test_RoutingMethodCircuit_custom_list() -> None:
test_c,
[
RoutingMethodCircuit(route_subcircuit_func_false, 5, 5),
LexiLabellingMethod(),
LexiRouteRoutingMethod(),
],
)
routed_commands = test_c.get_commands()

assert routed_commands[0].op.type == OpType.CX
assert routed_commands[0].qubits == [nodes[1], nodes[0]]
assert routed_commands[1].op.type == OpType.CX
Expand All @@ -170,6 +170,7 @@ def test_RoutingMethodCircuit_custom_list() -> None:
test_c,
[
RoutingMethodCircuit(route_subcircuit_func, 5, 5),
LexiLabellingMethod(),
LexiRouteRoutingMethod(),
],
)
Expand Down
6 changes: 3 additions & 3 deletions pytket/tests/mitigation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from pytket.utils.spam import SpamCorrecter, compress_counts
from pytket.circuit import Node, Circuit, Qubit # type: ignore
from pytket.mapping import MappingManager, LexiRouteRoutingMethod # type: ignore
from pytket.mapping import MappingManager, LexiLabellingMethod, LexiRouteRoutingMethod # type: ignore
from pytket.architecture import Architecture # type: ignore
from pytket.placement import place_with_map # type: ignore
from pytket.passes import DelayMeasures # type: ignore
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_spam_integration() -> None:
place_with_map(bellcc, qmap)
mm = MappingManager(arc)
rbell = bellcc.copy()
mm.route_circuit(rbell, [LexiRouteRoutingMethod()])
mm.route_circuit(rbell, [LexiLabellingMethod(), LexiRouteRoutingMethod()])

def check_correction(
counts0: Dict[Tuple[int, ...], int], counts1: Dict[Tuple[int, ...], int]
Expand Down Expand Up @@ -509,7 +509,7 @@ def test_spam_routing() -> None:
testc = Circuit(4, 4).H(0).CX(0, 3).CX(1, 2).CX(0, 1).CX(3, 2).measure_all()
routed = testc.copy()
mm = MappingManager(arc)
mm.route_circuit(routed, [LexiRouteRoutingMethod()])
mm.route_circuit(routed, [LexiLabellingMethod(), LexiRouteRoutingMethod()])
DelayMeasures().apply(routed)
readout = routed.qubit_readout

Expand Down
12 changes: 6 additions & 6 deletions pytket/tests/placement_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
place_with_map,
)
from pytket.passes import PauliSimp, DefaultMappingPass # type: ignore
from pytket.mapping import MappingManager, LexiRouteRoutingMethod # type: ignore
from pytket.mapping import MappingManager, LexiRouteRoutingMethod, LexiLabellingMethod # type: ignore
from pytket.qasm import circuit_from_qasm # type: ignore

import json
Expand Down Expand Up @@ -73,9 +73,9 @@ def test_placements() -> None:
assert circ_qbs != graph_placed.qubits

mm = MappingManager(test_architecture)
mm.route_circuit(base_placed, [LexiRouteRoutingMethod()])
mm.route_circuit(line_placed, [LexiRouteRoutingMethod()])
mm.route_circuit(graph_placed, [LexiRouteRoutingMethod()])
mm.route_circuit(base_placed, [LexiLabellingMethod(), LexiRouteRoutingMethod()])
cqc-alec marked this conversation as resolved.
Show resolved Hide resolved
mm.route_circuit(line_placed, [LexiLabellingMethod(), LexiRouteRoutingMethod()])
mm.route_circuit(graph_placed, [LexiLabellingMethod(), LexiRouteRoutingMethod()])

assert base_placed.valid_connectivity(test_architecture, False)
assert line_placed.valid_connectivity(test_architecture, False)
Expand Down Expand Up @@ -121,8 +121,8 @@ def test_placement_config() -> None:
assert map1 != map2

mm = MappingManager(test_architecture)
mm.route_circuit(circ1, [LexiRouteRoutingMethod()])
mm.route_circuit(circ2, [LexiRouteRoutingMethod()])
mm.route_circuit(circ1, [LexiLabellingMethod(), LexiRouteRoutingMethod()])
mm.route_circuit(circ2, [LexiLabellingMethod(), LexiRouteRoutingMethod()])
assert circ1.n_gates < circ2.n_gates


Expand Down
10 changes: 7 additions & 3 deletions pytket/tests/predicates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
CompilationUnit,
UserDefinedPredicate,
)
from pytket.mapping import LexiRouteRoutingMethod # type: ignore
from pytket.mapping import LexiLabellingMethod, LexiRouteRoutingMethod # type: ignore
from pytket.architecture import Architecture # type: ignore
from pytket.placement import Placement, GraphPlacement # type: ignore
from pytket.transform import Transform, PauliSynthStrat, CXConfigType # type: ignore
Expand Down Expand Up @@ -230,7 +230,9 @@ def test_routing_and_placement_pass() -> None:
assert seq_pass.apply(cu2)
assert cu2.initial_map == expected_map

full_pass = FullMappingPass(arc, pl, config=[LexiRouteRoutingMethod()])
full_pass = FullMappingPass(
arc, pl, config=[LexiLabellingMethod(), LexiRouteRoutingMethod()]
)
cu3 = CompilationUnit(circ.copy())
assert full_pass.apply(cu3)
assert cu3.initial_map == expected_map
Expand Down Expand Up @@ -682,7 +684,9 @@ def sq(a: float, b: float, c: float) -> Circuit:
[k.to_list(), v.to_list()] for k, v in qm.items()
]
# FullMappingPass
fm_pass = FullMappingPass(arc, placer, config=[LexiRouteRoutingMethod()])
fm_pass = FullMappingPass(
arc, placer, config=[LexiLabellingMethod(), LexiRouteRoutingMethod()]
)
assert fm_pass.to_dict()["pass_class"] == "SequencePass"
p_pass = fm_pass.get_sequence()[0]
r_pass = fm_pass.get_sequence()[1]
Expand Down
14 changes: 10 additions & 4 deletions pytket/tests/transform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from pytket.transform import Transform, CXConfigType, PauliSynthStrat # type: ignore
from pytket.qasm import circuit_from_qasm
from pytket.architecture import Architecture # type: ignore
from pytket.mapping import MappingManager, LexiRouteRoutingMethod # type: ignore
from pytket.mapping import MappingManager, LexiRouteRoutingMethod, LexiLabellingMethod # type: ignore
from pytket.placement import Placement, GraphPlacement, LinePlacement, NoiseAwarePlacement # type: ignore

from sympy import Symbol # type: ignore
Expand Down Expand Up @@ -770,7 +770,9 @@ def test_decompose_swap_to_cx() -> None:
pl = Placement(arc)
pl.place_with_map(circ, init_map)

MappingManager(arc).route_circuit(circ, [LexiRouteRoutingMethod()])
MappingManager(arc).route_circuit(
circ, [LexiLabellingMethod(), LexiRouteRoutingMethod()]
)
assert circ.valid_connectivity(arc, False)
Transform.DecomposeSWAPtoCX(arc).apply(circ)
assert len(circ.get_commands()) == 20
Expand Down Expand Up @@ -813,8 +815,12 @@ def test_FullMappingPass() -> None:
cu_1 = CompilationUnit(circ)
gp_placer = GraphPlacement(arc)
lp_placer = LinePlacement(arc)
m_pass_0 = FullMappingPass(arc, gp_placer, [LexiRouteRoutingMethod()])
m_pass_1 = FullMappingPass(arc, lp_placer, [LexiRouteRoutingMethod()])
m_pass_0 = FullMappingPass(
arc, gp_placer, [LexiLabellingMethod(), LexiRouteRoutingMethod()]
)
m_pass_1 = FullMappingPass(
arc, lp_placer, [LexiLabellingMethod(), LexiRouteRoutingMethod()]
)
m_pass_0.apply(cu_0)
m_pass_1.apply(cu_1)
out_circ_0 = cu_0.circuit
Expand Down
21 changes: 5 additions & 16 deletions tket/src/Architecture/Architecture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,14 @@

namespace tket {

// basic implementation that works off same prior assumptions
// TODO: Update this for more mature systems of multi-qubit gates
bool Architecture::valid_operation(
const OpType& optype, const std::vector<Node>& uids) const {
bool Architecture::valid_operation(const std::vector<Node>& uids) const {
for (Node n : uids) {
if (!this->node_exists(Node(n))) return false;
}
if (uids.size() == 1) {
// with current Architecture can assume all single qubit gates valid
return true;
} else if (optype == OpType::Barrier) {
return true;
} else if (uids.size() == 2) {
if (this->node_exists(uids[0]) && this->node_exists(uids[1]) &&
this->bidirectional_edge_exists(uids[0], uids[1])) {
return true;
}
} else if (uids.size() == 3 && optype == OpType::BRIDGE) {
bool con_0_exists = this->bidirectional_edge_exists(uids[0], uids[1]);
bool con_1_exists = this->bidirectional_edge_exists(uids[2], uids[1]);
if (this->node_exists(uids[0]) && this->node_exists(uids[1]) &&
this->node_exists(uids[2]) && con_0_exists && con_1_exists) {
if (this->bidirectional_edge_exists(uids[0], uids[1])) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tket/src/Architecture/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ add_library(tket-${COMP}

list(APPEND DEPS_${COMP}
Graphs
OpType
TokenSwapping
Utils)


foreach(DEP ${DEPS_${COMP}})
target_include_directories(
tket-${COMP} PRIVATE ${TKET_${DEP}_INCLUDE_DIR})
Expand Down
4 changes: 1 addition & 3 deletions tket/src/Architecture/include/Architecture/Architecture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "Graphs/CompleteGraph.hpp"
#include "Graphs/DirectedGraph.hpp"
#include "OpType/OpType.hpp"
#include "Utils/BiMapHeaders.hpp"
#include "Utils/EigenConfig.hpp"
#include "Utils/Json.hpp"
Expand Down Expand Up @@ -107,8 +106,7 @@ class Architecture : public ArchitectureBase<graphs::DirectedGraph<Node>> {
* Returns true if the given operation acting on the given nodes
* can be executed on the Architecture connectivity graph.
*/
bool valid_operation(
const OpType &optype, const std::vector<Node> &uids) const;
bool valid_operation(const std::vector<Node> &uids) const;

/**
* Sub-architecture generated by a subset of nodes.
Expand Down
Loading