Skip to content

Commit

Permalink
[TKET-1567] Add aas in rv3.1 (#254)
Browse files Browse the repository at this point in the history
* Update build_and_test.yml

* Feature/TokenSwapping (#94)

* Copy TokenSwapping CodeBase, update CMakeLists.txt

* Add TokenSwapping tests

* Update GraphTests to use TokenSwapping RNG

* Remove "class RNG;"

* Add cpp files to compilation

* Add "MappingManager" class and port older routing solution (#95)

* Copy code from private repository

* Add binders for mapping module

* Adding mapping module to setup.py

* Add shared_ptr to Architecture subclasses in binder file

* Port python test for mapping module

* Add token swapping stage to routing v3 (#96)

* Assert candidate swaps size (#108)

* Add assertion that there are at least some swaps to trial

* Pseudo code for Yao

* Fix routing with measurements issue

* Add classically controlled gates to lexiroute test

Co-authored-by: sjdilkes <[email protected]>

* Update Architecture method names

* get_all_nodes -> nodes

* Update Compilation Passes to use RoutingV3 (#115)

* Add token swapping stage, add test

* Update compilation passes to use new routing

* Add json serialization

* Continue adding JSON serialisation for routing_config

* Improve Json definitions

* Update JSON Serialization and use of Barrier

* Change from reference_wrapper to shared_ptr

* Add JSON_DECL for std::vector<RoutingMethodPtr>

* format routing_test

* Fix up tests and binders for python

* Uncoment measurement tests

* rename method to merge_ancilla

* debug proptest

* Make add_qubit add qubit to unit_bimaps_ if not nullptr

* Architectures -> Architecture

* Install boost on MacOS.

* comments to debug

* update proptest to support ancillas properly

* remove couts

* format

* Make Unitary dimensions match

* add tket assert for comparison

* Update test to check value

* add_qubit -> add_ancilla

* Remove kwargs formatting from argument

* Rename Architecture Methods

* rename architecture methods

* Allow architecture mapping to take original edges, to calculate Node to size_t mapping

* add get_square_grid_edges, to allow fixed tests independent of SquareGrid

* use ArchitectureMapping and edges in most tests, instead of Architecture

* trivial typos, comments, cmake update

* add copyright notices, pragma once, remove semicolon typos

* update binders for inheritance and docs

* format

* Remove NodeGraph

* update formatting

* Update CMakeLists and Setup.py

* Use explicit shared_ptr

* Refactor Routing module binder

Make "FullMappingPass" use a kwargs based argument to get round faulty docs type definitions.

* remove trailing whitespace

* update clang formatting

* reformat file

* update orientation of BRIDGE gates

* Update conf docs mapping, remove kwargs full mapping pass

Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: Zen Harper <[email protected]>

* Remove outdated Routing code from repository (#165)

* Add token swapping stage, add test

* Update compilation passes to use new routing

* Add json serialization

* Continue adding JSON serialisation for routing_config

* Improve Json definitions

* Update JSON Serialization and use of Barrier

* Change from reference_wrapper to shared_ptr

* Add JSON_DECL for std::vector<RoutingMethodPtr>

* format routing_test

* Fix up tests and binders for python

* Uncoment measurement tests

* rename method to merge_ancilla

* debug proptest

* Make add_qubit add qubit to unit_bimaps_ if not nullptr

* Architectures -> Architecture

* Install boost on MacOS.

* comments to debug

* update proptest to support ancillas properly

* remove couts

* format

* Make Unitary dimensions match

* add tket assert for comparison

* Update test to check value

* add_qubit -> add_ancilla

* Remove kwargs formatting from argument

* Rename Architecture Methods

* rename architecture methods

* Allow architecture mapping to take original edges, to calculate Node to size_t mapping

* add get_square_grid_edges, to allow fixed tests independent of SquareGrid

* use ArchitectureMapping and edges in most tests, instead of Architecture

* trivial typos, comments, cmake update

* add copyright notices, pragma once, remove semicolon typos

* update binders for inheritance and docs

* format

* Remove NodeGraph

* update formatting

* Update CMakeLists and Setup.py

* Use explicit shared_ptr

* Refactor Routing module binder

Make "FullMappingPass" use a kwargs based argument to get round faulty docs type definitions.

* remove trailing whitespace

* update clang formatting

* reformat file

* update orientation of BRIDGE gates

* Remove src/Routing

Move Placement files into new src/Placement subdirectory, update tests as necessary, move connectivty constraint verification to utils

* update tket/pytket to not install or use old pytket.routing

* clang formatting

* Update mitigation test to use explicit placement

* remove binder file

* Update conf docs mapping, remove kwargs full mapping pass

* update docs for new python modules

* Move Verification files to src/Mapping subdirectory

* Delete test_Routing.cpp

* Update imports for Verification.hpp

* Add default argument to LexiRouteRoutingMethod binder

Update python tests to use default

* upadte Verification.cpp compilation pass

* Formatting

Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: Zen Harper <[email protected]>

* Improve LexiRoute.cpp coverage

* Improve MappingFrontier.cpp test coverage

* Rmoeve decmopose_module method

* readd missing test

* Update LexiRoute test coverage

* Remove redundant comments

* Feature/reorder multi qubit gates (#157)

* Add token swapping stage, add test

* Update compilation passes to use new routing

* Add json serialization

* Continue adding JSON serialisation for routing_config

* Improve Json definitions

* Update JSON Serialization and use of Barrier

* Change from reference_wrapper to shared_ptr

* Add JSON_DECL for std::vector<RoutingMethodPtr>

* format routing_test

* Fix up tests and binders for python

* Uncoment measurement tests

* rename method to merge_ancilla

* debug proptest

* Make add_qubit add qubit to unit_bimaps_ if not nullptr

* Architectures -> Architecture

* Install boost on MacOS.

* comments to debug

* update proptest to support ancillas properly

* remove couts

* format

* Make Unitary dimensions match

* add tket assert for comparison

* Update test to check value

* add_qubit -> add_ancilla

* Remove kwargs formatting from argument

* Rename Architecture Methods

* rename architecture methods

* Allow architecture mapping to take original edges, to calculate Node to size_t mapping

* add get_square_grid_edges, to allow fixed tests independent of SquareGrid

* use ArchitectureMapping and edges in most tests, instead of Architecture

* trivial typos, comments, cmake update

* add copyright notices, pragma once, remove semicolon typos

* update binders for inheritance and docs

* format

* Remove NodeGraph

* update formatting

* Reorder CZ circuits

* Revert "Reorder CZ circuits"

This reverts commit 9d67720.

* Make two methods in MappingFrontier public

* Add MultiGateReorderRoutingMethod

* Remove unnecessary frontier advancement

* Avoid copying the whole MappingFrontier

* Remove the edge_in_frontier method

* Add comment for vertex rewiring

* Allow users to set search limits

* Change default max depth/size limits to 10

* Fix using incorrect port colours

* Obtain unitid by traversing to frontier instead of inputs

* Add test for MultiGateReorderRoutingMethod

* Refactor condition checks and rewire

* Implement check_method

* Add test for routing with LexiRoute

Co-authored-by: sjdilkes <[email protected]>
Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: Zen Harper <[email protected]>

* modify TKET_ASSERT: allow extra messages, catch exceptions in evaluation

* replace some exceptions with tket asserts; should be ignored by test coverage

* Start moving files for modularisation

* compilation refactor commit

* Reorder base cmake

* add assertmessage.cpp to compiilation

* Rework TokenSwapping includes

* clang format

* update linking for pytket

* reformat with black

* Revert "reformat with black"

This reverts commit 66ce863.

* reformat setup.py

* update proptests cmakelists

* Feature/add serialisation for multi qubit reorder (#184)

* Add JSON serialisation for  MultiGateReorderRoutingMethod
and getters

* Add tests for JSON serialisation for MultiGateReorderRoutingMethod

* Update test coverage for RoutingMethod serialization

* make mapping_frontier from mapping_frontier

* routing -> mapping

* use TKET_ASSERT_WITH_THROW instead of TKET_ASSERT

* Replace TKET_ASSERT with throw and use GCOVR_EXCL_START,STOP where appropriate

* replace throws with TKET_ASSERT_WITH_THROW where appropriate

* Add the TKET_ASSERT_WITH_THROW macro

* add simple swap functions tests

* add TKET_ASSERT_WITH_THROW tests, for detailed error messages

* clang format

* try to fix code coverage branching problems in TKET_ASSERT_WITH_THROW by hiding throws

* correct "does not return a value" error

* Infra/use bimap for quantum boundary (#185)

* Add sequenced_bimap_t

* Use sequenced_bimap_t for unit_vertport_frontier_t

* Update MultiGateReorder

* remove try/catch from tket assert with throw, to cut down branching

* remove TKET_ASSERT_WITH_THROW, replace with TKET_ASSERT

* Remove AssertMessage(), add TKET_ASSERT_WITH_MESSAGE

* manually add coverage exclusion tags for now, until the branching problem is fixed

* rename method, remove predicate from routing

* Add copyright information

* [RV3] [refactor] Clean up of the dependencies of the modules (#199)

* remove cycle from cmake lists

* clean up

* add comment

* fix binder include

* try to fix pytket build

* try to fix problems

* fix windows build

* try to fix windows

* add bimaps attribute to MappingFrontier

* update_quantum_boundary_uids remaps bimaps entries

* [1777] Split `LexiRouteRoutingMethod` into two methods (#209)

* LexiLabellingRoutingMethod class

* Add labelling method using lexiroute methods

* First LexiLabelling implementation, with testing

* update defaults

* confirm correct imports and routing method config

* Expose LabellingRoutingMethod to pytket

* Update json serilaization

* reformat utils test

* Address PR Comments

* [1795] RoutingMethod for Box Decompositoin (#212)

* Reject boxes in Architecture::valid_operation

* Add `next_q_cut` method to a quantum cut
Only consider quantum edges

* Use `next_q_cut` in `advance_frontier_boundary`

* Add BoxDecompositionRoutingMethod

* Add tests

* Reformat

* Reject boxes in LexiRouteMethod::check_method

* Update tests

* Add JSON serialisation

* Handle unused arguments

* Refactor Circuit::decompose_boxes

* fix naming

* update checking method for LexiRoute

* Update lexilabelling check_method

Co-authored-by: Yao Tang <[email protected]>

* update ci check (#210)

* update ci check

* Update build_and_test.yml

* Update build_and_test.yml

* Update build_and_test.yml

* Update changelog.rst

* Update copyright dates

2021 -> 2022

* Update pytket/binders/mapping.cpp

Co-authored-by: Alec Edgington <[email protected]>

* Update pytket/binders/mapping.cpp

Co-authored-by: Alec Edgington <[email protected]>

* Update pytket/binders/mapping.cpp

Co-authored-by: Alec Edgington <[email protected]>

* Corrections for PR

* Remove tokenswapping from dependneices

* Feature/decompose boxes in routing (#197)

* Reject boxes in Architecture::valid_operation

* Add `next_q_cut` method to a quantum cut
Only consider quantum edges

* Use `next_q_cut` in `advance_frontier_boundary`

* Add BoxDecompositionRoutingMethod

* Add tests

* Reformat

* Reject boxes in LexiRouteMethod::check_method

* Update tests

* Add JSON serialisation

* Handle unused arguments

* Refactor Circuit::decompose_boxes

* fix naming

Co-authored-by: sjdilkes <[email protected]>

* update compilation for tokenswapping

* Revert "Feature/decompose boxes in routing (#197)"

This reverts commit 86fb61e.

* Address PR Requested changes

* dummy pythonfile

* change copyright to 2022

* remove unused code, including PathFinderInterface

* rename HybridTsa00 -> HybridTsa; move files out of include directory

* move DebugFunctions into tests

* move get_swaps_lower_bound out of tket into tests

* simple typos; unused code; extra comments, asserts

* rename main_entry_functions -> SwapsFromQubitMapping; remove unused function

* move RNG from token swapping to Utils; erase tests/Graphs/RNG

* move get_random_set out of token swapping into test utils

* move some stuff out of namespace tsa_internal into namespace tket

* more cleanup

* clang format

* added OpType dependency to token swapping

* clang format

* replace throws with TKET_ASSERT_WITH_MESSAGE

* move BruteForceColouring.hpp, ColouringPriority.hpp out of include directory

* add TokenSwappingWithArch project; move files out of TokenSwapping

* remove architecture from TokenSwapping

* move DistancesInterface, NeighboursInterface out of namespace tsa_internal

* update TokenSwapping tests to use TokenSwappingWithArch

* bool type for delay_measures

* Create architecture_test.py

* Reduce test times: add TSGlobalTestParameters with run_long_tests option

* add test_DebugFunctions.cpp and remove test coverage exclusion

* Remove unreachable code.

* update architecture binder

* Revert "update architecture binder"

This reverts commit d7bbd01.

* formatting, remove nodegraph test

* update architecture and mapping tests

* add architecture_aware_synthesis_test.py

* Create placement_test.py

* Update range of python mapping tests

* update routing test coverage

* add ci run on push on - feature/RV3.1

* fix compilation issues

* remove token_swapping_method

* Update test_lexiroute

* add predicate back

* update setup.py

* Add LexiLabellingMethod

* Cover Alec's comments

* format transform_test

* change length of line

* remove trailing white space

* name -> name_of_ethod

* name -> name_of_method RoutingMethod

* tokenswappingwitharch

* add type ignores

* "name_of_method" -> "name'

* Update valid_operation description

* reformat transform_test

and remove "had"

* remove second auto_rebase_pass

* Add missing import.

* Add option to tket-tests conan build determining whether full tests are run.

If tket-tests:full=True, the compiler flag TKET_TESTS_FULL is defined.

* remove TokenSwappingWithArch project; move files into Architecture

* Set "full tests" option on scheduled CI runs only.

* change TKET_ASSERT_WITH_MESSAGE to have parentheses around message

* Add note to README.

* rename HybridTSA_00 to HybridTsa

* Replace TSGlobalTestParameters with #ifdef TKET_TESTS_FULL

* commit other forgotten files

* Remove GetTketAssertMessage and TKET_ASSERT_WITH_MESSAGE, go back to AssertMessage().

* clang format

* Move test_Utils.cpp to test/Utils directory, rename to test_HelperFunctions.cpp

* fix "function does not return a value" error

* fix "non-void function does not return a value" error, attempt 2!

* Forgot to remove final TokenSwappingWithArch bits

* Fix build failure.

Puzzling.

* Fix for mypy,

* [fix] Feature/rv3.1 (#223)

* try to fix problems

* solve problem CMake

* fix delay measure

* format

* format

* format

* add archtecture pointer

* fix format

* black format

* fix mypy

* fix doxygen

* fix typo

* fix mypy

* fix black format

* fix merge

* fix merge

* mypy fix

* mypy

* mypy

* name_of_method -> name

* add ass to rv3.1

* format

* black format

* add override

* remove todo

* Merge develop into feature/RV3.1 (#255)

* Merge `RoutingMethod::check_method` and `RoutingMethod::routing_method` (#244)

* Update build_and_test.yml

* Feature/TokenSwapping (#94)

* Copy TokenSwapping CodeBase, update CMakeLists.txt

* Add TokenSwapping tests

* Update GraphTests to use TokenSwapping RNG

* Remove "class RNG;"

* Add cpp files to compilation

* Add "MappingManager" class and port older routing solution (#95)

* Copy code from private repository

* Add binders for mapping module

* Adding mapping module to setup.py

* Add shared_ptr to Architecture subclasses in binder file

* Port python test for mapping module

* Add token swapping stage to routing v3 (#96)

* Assert candidate swaps size (#108)

* Add assertion that there are at least some swaps to trial

* Pseudo code for Yao

* Fix routing with measurements issue

* Add classically controlled gates to lexiroute test

Co-authored-by: sjdilkes <[email protected]>

* Update Architecture method names

* get_all_nodes -> nodes

* Update Compilation Passes to use RoutingV3 (#115)

* Add token swapping stage, add test

* Update compilation passes to use new routing

* Add json serialization

* Continue adding JSON serialisation for routing_config

* Improve Json definitions

* Update JSON Serialization and use of Barrier

* Change from reference_wrapper to shared_ptr

* Add JSON_DECL for std::vector<RoutingMethodPtr>

* format routing_test

* Fix up tests and binders for python

* Uncoment measurement tests

* rename method to merge_ancilla

* debug proptest

* Make add_qubit add qubit to unit_bimaps_ if not nullptr

* Architectures -> Architecture

* Install boost on MacOS.

* comments to debug

* update proptest to support ancillas properly

* remove couts

* format

* Make Unitary dimensions match

* add tket assert for comparison

* Update test to check value

* add_qubit -> add_ancilla

* Remove kwargs formatting from argument

* Rename Architecture Methods

* rename architecture methods

* Allow architecture mapping to take original edges, to calculate Node to size_t mapping

* add get_square_grid_edges, to allow fixed tests independent of SquareGrid

* use ArchitectureMapping and edges in most tests, instead of Architecture

* trivial typos, comments, cmake update

* add copyright notices, pragma once, remove semicolon typos

* update binders for inheritance and docs

* format

* Remove NodeGraph

* update formatting

* Update CMakeLists and Setup.py

* Use explicit shared_ptr

* Refactor Routing module binder

Make "FullMappingPass" use a kwargs based argument to get round faulty docs type definitions.

* remove trailing whitespace

* update clang formatting

* reformat file

* update orientation of BRIDGE gates

* Update conf docs mapping, remove kwargs full mapping pass

Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: Zen Harper <[email protected]>

* Remove outdated Routing code from repository (#165)

* Add token swapping stage, add test

* Update compilation passes to use new routing

* Add json serialization

* Continue adding JSON serialisation for routing_config

* Improve Json definitions

* Update JSON Serialization and use of Barrier

* Change from reference_wrapper to shared_ptr

* Add JSON_DECL for std::vector<RoutingMethodPtr>

* format routing_test

* Fix up tests and binders for python

* Uncoment measurement tests

* rename method to merge_ancilla

* debug proptest

* Make add_qubit add qubit to unit_bimaps_ if not nullptr

* Architectures -> Architecture

* Install boost on MacOS.

* comments to debug

* update proptest to support ancillas properly

* remove couts

* format

* Make Unitary dimensions match

* add tket assert for comparison

* Update test to check value

* add_qubit -> add_ancilla

* Remove kwargs formatting from argument

* Rename Architecture Methods

* rename architecture methods

* Allow architecture mapping to take original edges, to calculate Node to size_t mapping

* add get_square_grid_edges, to allow fixed tests independent of SquareGrid

* use ArchitectureMapping and edges in most tests, instead of Architecture

* trivial typos, comments, cmake update

* add copyright notices, pragma once, remove semicolon typos

* update binders for inheritance and docs

* format

* Remove NodeGraph

* update formatting

* Update CMakeLists and Setup.py

* Use explicit shared_ptr

* Refactor Routing module binder

Make "FullMappingPass" use a kwargs based argument to get round faulty docs type definitions.

* remove trailing whitespace

* update clang formatting

* reformat file

* update orientation of BRIDGE gates

* Remove src/Routing

Move Placement files into new src/Placement subdirectory, update tests as necessary, move connectivty constraint verification to utils

* update tket/pytket to not install or use old pytket.routing

* clang formatting

* Update mitigation test to use explicit placement

* remove binder file

* Update conf docs mapping, remove kwargs full mapping pass

* update docs for new python modules

* Move Verification files to src/Mapping subdirectory

* Delete test_Routing.cpp

* Update imports for Verification.hpp

* Add default argument to LexiRouteRoutingMethod binder

Update python tests to use default

* upadte Verification.cpp compilation pass

* Formatting

Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: Zen Harper <[email protected]>

* Improve LexiRoute.cpp coverage

* Improve MappingFrontier.cpp test coverage

* Rmoeve decmopose_module method

* readd missing test

* Update LexiRoute test coverage

* Remove redundant comments

* Feature/reorder multi qubit gates (#157)

* Add token swapping stage, add test

* Update compilation passes to use new routing

* Add json serialization

* Continue adding JSON serialisation for routing_config

* Improve Json definitions

* Update JSON Serialization and use of Barrier

* Change from reference_wrapper to shared_ptr

* Add JSON_DECL for std::vector<RoutingMethodPtr>

* format routing_test

* Fix up tests and binders for python

* Uncoment measurement tests

* rename method to merge_ancilla

* debug proptest

* Make add_qubit add qubit to unit_bimaps_ if not nullptr

* Architectures -> Architecture

* Install boost on MacOS.

* comments to debug

* update proptest to support ancillas properly

* remove couts

* format

* Make Unitary dimensions match

* add tket assert for comparison

* Update test to check value

* add_qubit -> add_ancilla

* Remove kwargs formatting from argument

* Rename Architecture Methods

* rename architecture methods

* Allow architecture mapping to take original edges, to calculate Node to size_t mapping

* add get_square_grid_edges, to allow fixed tests independent of SquareGrid

* use ArchitectureMapping and edges in most tests, instead of Architecture

* trivial typos, comments, cmake update

* add copyright notices, pragma once, remove semicolon typos

* update binders for inheritance and docs

* format

* Remove NodeGraph

* update formatting

* Reorder CZ circuits

* Revert "Reorder CZ circuits"

This reverts commit 9d67720.

* Make two methods in MappingFrontier public

* Add MultiGateReorderRoutingMethod

* Remove unnecessary frontier advancement

* Avoid copying the whole MappingFrontier

* Remove the edge_in_frontier method

* Add comment for vertex rewiring

* Allow users to set search limits

* Change default max depth/size limits to 10

* Fix using incorrect port colours

* Obtain unitid by traversing to frontier instead of inputs

* Add test for MultiGateReorderRoutingMethod

* Refactor condition checks and rewire

* Implement check_method

* Add test for routing with LexiRoute

Co-authored-by: sjdilkes <[email protected]>
Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: Zen Harper <[email protected]>

* modify TKET_ASSERT: allow extra messages, catch exceptions in evaluation

* replace some exceptions with tket asserts; should be ignored by test coverage

* Start moving files for modularisation

* compilation refactor commit

* Reorder base cmake

* add assertmessage.cpp to compiilation

* Rework TokenSwapping includes

* clang format

* update linking for pytket

* reformat with black

* Revert "reformat with black"

This reverts commit 66ce863.

* reformat setup.py

* update proptests cmakelists

* Feature/add serialisation for multi qubit reorder (#184)

* Add JSON serialisation for  MultiGateReorderRoutingMethod
and getters

* Add tests for JSON serialisation for MultiGateReorderRoutingMethod

* Update test coverage for RoutingMethod serialization

* make mapping_frontier from mapping_frontier

* routing -> mapping

* use TKET_ASSERT_WITH_THROW instead of TKET_ASSERT

* Replace TKET_ASSERT with throw and use GCOVR_EXCL_START,STOP where appropriate

* replace throws with TKET_ASSERT_WITH_THROW where appropriate

* Add the TKET_ASSERT_WITH_THROW macro

* add simple swap functions tests

* add TKET_ASSERT_WITH_THROW tests, for detailed error messages

* clang format

* try to fix code coverage branching problems in TKET_ASSERT_WITH_THROW by hiding throws

* correct "does not return a value" error

* Infra/use bimap for quantum boundary (#185)

* Add sequenced_bimap_t

* Use sequenced_bimap_t for unit_vertport_frontier_t

* Update MultiGateReorder

* remove try/catch from tket assert with throw, to cut down branching

* remove TKET_ASSERT_WITH_THROW, replace with TKET_ASSERT

* Remove AssertMessage(), add TKET_ASSERT_WITH_MESSAGE

* manually add coverage exclusion tags for now, until the branching problem is fixed

* Add copyright information

* [RV3] [refactor] Clean up of the dependencies of the modules (#199)

* remove cycle from cmake lists

* clean up

* add comment

* fix binder include

* try to fix pytket build

* try to fix problems

* fix windows build

* try to fix windows

* add bimaps attribute to MappingFrontier

* update_quantum_boundary_uids remaps bimaps entries

* Update build_and_test.yml

* Update changelog.rst

* Update copyright dates

2021 -> 2022

* Update pytket/binders/mapping.cpp

Co-authored-by: Alec Edgington <[email protected]>

* Update pytket/binders/mapping.cpp

Co-authored-by: Alec Edgington <[email protected]>

* Update pytket/binders/mapping.cpp

Co-authored-by: Alec Edgington <[email protected]>

* Corrections for PR

* Remove tokenswapping from dependneices

* Feature/decompose boxes in routing (#197)

* Reject boxes in Architecture::valid_operation

* Add `next_q_cut` method to a quantum cut
Only consider quantum edges

* Use `next_q_cut` in `advance_frontier_boundary`

* Add BoxDecompositionRoutingMethod

* Add tests

* Reformat

* Reject boxes in LexiRouteMethod::check_method

* Update tests

* Add JSON serialisation

* Handle unused arguments

* Refactor Circuit::decompose_boxes

* fix naming

Co-authored-by: sjdilkes <[email protected]>

* update compilation for tokenswapping

* Revert "Feature/decompose boxes in routing (#197)"

This reverts commit 86fb61e.

* Address PR Requested changes

* change copyright to 2022

* remove unused code, including PathFinderInterface

* rename HybridTsa00 -> HybridTsa; move files out of include directory

* move DebugFunctions into tests

* move get_swaps_lower_bound out of tket into tests

* simple typos; unused code; extra comments, asserts

* rename main_entry_functions -> SwapsFromQubitMapping; remove unused function

* move RNG from token swapping to Utils; erase tests/Graphs/RNG

* move get_random_set out of token swapping into test utils

* move some stuff out of namespace tsa_internal into namespace tket

* more cleanup

* clang format

* added OpType dependency to token swapping

* clang format

* replace throws with TKET_ASSERT_WITH_MESSAGE

* move BruteForceColouring.hpp, ColouringPriority.hpp out of include directory

* add TokenSwappingWithArch project; move files out of TokenSwapping

* remove architecture from TokenSwapping

* move DistancesInterface, NeighboursInterface out of namespace tsa_internal

* update TokenSwapping tests to use TokenSwappingWithArch

* bool type for delay_measures

* Create architecture_test.py

* Reduce test times: add TSGlobalTestParameters with run_long_tests option

* add test_DebugFunctions.cpp and remove test coverage exclusion

* Remove unreachable code.

* update architecture binder

* Revert "update architecture binder"

This reverts commit d7bbd01.

* formatting, remove nodegraph test

* update architecture and mapping tests

* add architecture_aware_synthesis_test.py

* Create placement_test.py

* Update range of python mapping tests

* update routing test coverage

* Cover Alec's comments

* format transform_test

* change length of line

* remove trailing white space

* name -> name_of_ethod

* name -> name_of_method RoutingMethod

* tokenswappingwitharch

* add type ignores

* Comment out check_method, rewrite types and methods

* Update tests to not use check_method

* update test_routingmethod

* "name_of_method" -> "name'

* Update valid_operation description

* reformat transform_test

and remove "had"

* remove second auto_rebase_pass

* Add missing import.

* Add option to tket-tests conan build determining whether full tests are run.

If tket-tests:full=True, the compiler flag TKET_TESTS_FULL is defined.

* remove TokenSwappingWithArch project; move files into Architecture

* Set "full tests" option on scheduled CI runs only.

* change TKET_ASSERT_WITH_MESSAGE to have parentheses around message

* Add note to README.

* rename HybridTSA_00 to HybridTsa

* Replace TSGlobalTestParameters with #ifdef TKET_TESTS_FULL

* commit other forgotten files

* Remove GetTketAssertMessage and TKET_ASSERT_WITH_MESSAGE, go back to AssertMessage().

* clang format

* Move test_Utils.cpp to test/Utils directory, rename to test_HelperFunctions.cpp

* fix "function does not return a value" error

* fix "non-void function does not return a value" error, attempt 2!

* Forgot to remove final TokenSwappingWithArch bits

* update test_json

* update python binders and tests

remove struct, use 4 element tuple

* remove commented out code, format

* change type return of method

for mypy

* address PR Comments

* use std::get

Co-authored-by: yao-cqc <[email protected]>
Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: Zen Harper <[email protected]>
Co-authored-by: cqc-melf <[email protected]>
Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: melf <[email protected]>

* [bugfix] [infra] Fix issues revealed by valgrind; add valgrind check on CI. (#242)

* Add StandardPass for basic qubit relabelling (#247)

* add NaivePlacement Class and naive_placement_mapping_pass

* clang format

* PR Requested Changes

* Add register accessors to Circuit (#246)

* Add register accessors to Circuit

* Add c_registers and q_registers methods

* [TKET-597] MBQC primitives and Flow Analysis (#218)

* Add MBQC generators for ZX

* Causal and Pauli flow, verification, identification, focus

* Focussed set identification

* Fix fall through annotation

* Add checks for is_graphlike in graphlike rewrites

* Move header to include folder

* Add files back into CMakeLists

* Update binders with new generator hierarchy

* Compiler warnings from uninitialised variables

* Improve docstrings and test coverage

* Fix compiler error on Windows CI

* Add method to get all opgroup names (#249)

* Add method to get all group names

* Improve test

* [infra] Don't invoke `setup.py` directly (#250)

* [infra] separated test utils from tests (#251)

* [feature] [rv3] Generate random nearby placements (#232)

* Add new LexirRouteROutingMethod header and cpp files

* add bool option to LexiRoute::set_interating_uids

* update methods to merge check and route

* Remove redundant line in Rebase.cpp (#253)

* address pr comments (and failing test)

* black formatting

* update build_and_test .yml

Co-authored-by: yao-cqc <[email protected]>
Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: Zen Harper <[email protected]>
Co-authored-by: cqc-melf <[email protected]>
Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: melf <[email protected]>
Co-authored-by: Will Simmons <[email protected]>
Co-authored-by: Luca Mondada <[email protected]>

* [TKET-1778] add architecture operation valid changes (#248)

* compiler pytket

* add tests and checks in python

* black format python

* update format c++

* c++ format

* get optype only once

* remove optype from valid_operation

* remove optype deps

* remove 3 node case

* Update build_and_test.yml

* try to debug

* add merge changes to aas

* add run on PR

* clean up

* address PR comments

* Update pytket/docs/changelog.rst

Co-authored-by: Alec Edgington <[email protected]>

* Update pytket/binders/architecture.cpp

Co-authored-by: Alec Edgington <[email protected]>

* Update pytket/docs/changelog.rst

Co-authored-by: Alec Edgington <[email protected]>

* fix bug in lexi (#260)

* merge

* format

* remove run on rv3.1 branch

* fix merge from develop

* adress pr comments

Co-authored-by: Silas Dilkes <[email protected]>
Co-authored-by: yao-cqc <[email protected]>
Co-authored-by: sjdilkes <[email protected]>
Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: Zen Harper <[email protected]>
Co-authored-by: Yao Tang <[email protected]>
Co-authored-by: Alec Edgington <[email protected]>
Co-authored-by: Will Simmons <[email protected]>
Co-authored-by: Luca Mondada <[email protected]>
  • Loading branch information
10 people authored Feb 28, 2022
1 parent d9df175 commit 57babdc
Show file tree
Hide file tree
Showing 15 changed files with 1,502 additions and 15 deletions.
4 changes: 4 additions & 0 deletions pytket/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ endif()
pybind11_add_module(mapping binders/mapping.cpp)
target_include_directories(mapping PRIVATE binders/include)
target_link_libraries(mapping PRIVATE
tket-ArchAwareSynth
tket-Architecture
tket-Characterisation
tket-Circuit
Expand All @@ -78,6 +79,9 @@ target_link_libraries(mapping PRIVATE
tket-Mapping
tket-Ops
tket-OpType
tket-PauliGraph
tket-Placement
tket-Transformations
tket-TokenSwapping
tket-Utils)

Expand Down
22 changes: 22 additions & 0 deletions pytket/binders/mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <pybind11/stl_bind.h>

#include "Circuit/Circuit.hpp"
#include "Mapping/AASLabelling.hpp"
#include "Mapping/AASRoute.hpp"
#include "Mapping/LexiLabelling.hpp"
#include "Mapping/LexiRoute.hpp"
#include "Mapping/MappingManager.hpp"
Expand Down Expand Up @@ -77,6 +79,26 @@ PYBIND11_MODULE(mapping, m) {
"physical mapping.",
py::arg("lookahead") = 10);

py::class_<
AASRouteRoutingMethod, std::shared_ptr<AASRouteRoutingMethod>,
RoutingMethod>(
m, "AASRouteRoutingMethod",
"Defines a RoutingMethod object for mapping circuits that uses the "
"architecture aware synthesis method implemented in tket.")
.def(
py::init<unsigned>(),
"AASRouteRoutingMethod constructor.\n\n:param aaslookahead: "
"recursive interation depth of the architecture aware synthesis."
"method.",
py::arg("aaslookahead"));

py::class_<
AASLabellingMethod, std::shared_ptr<AASLabellingMethod>, RoutingMethod>(
m, "AASLabellingMethod",
"Defines a Labeling Method for aas for labelling all unplaced qubits in "
"a circuit")
.def(py::init<>(), "AASLabellingMethod constructor.");

py::class_<
LexiLabellingMethod, std::shared_ptr<LexiLabellingMethod>, RoutingMethod>(
m, "LexiLabellingMethod",
Expand Down
20 changes: 20 additions & 0 deletions pytket/tests/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,26 @@ def test_phase_polybox() -> None:
assert np.array_equal(p_box.linear_transformation, linear_transformation)


def test_phase_polybox_big() -> None:
c = Circuit(3, 3)
n_qb = 3
qubit_indices = {Qubit(0): 0, Qubit(1): 1, Qubit(2): 2}
phase_polynomial = {
(True, False, True): 0.333,
(False, False, True): 0.05,
(False, False, False): 1.05,
}
linear_transformation = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
p_box = PhasePolyBox(n_qb, qubit_indices, phase_polynomial, linear_transformation)

c.add_phasepolybox(p_box, [0, 1, 2])
assert p_box.n_qubits == n_qb
assert p_box.qubit_indices == qubit_indices
assert p_box.phase_polynomial == phase_polynomial
assert np.array_equal(p_box.linear_transformation, linear_transformation)
assert DecomposeBoxes().apply(c)


def test_depth() -> None:
c = Circuit(3)
c.H(0).H(1).CX(1, 2).CZ(0, 1).H(1).CZ(1, 2)
Expand Down
127 changes: 124 additions & 3 deletions pytket/tests/mapping_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from pytket.mapping import MappingManager, RoutingMethodCircuit, LexiRouteRoutingMethod, LexiLabellingMethod # type: ignore
from pytket.mapping import MappingManager, RoutingMethodCircuit, LexiRouteRoutingMethod, AASRouteRoutingMethod, LexiLabellingMethod, AASLabellingMethod # type: ignore
from pytket.architecture import Architecture # type: ignore
from pytket import Circuit, OpType
from pytket.circuit import Node, Qubit # type: ignore
from pytket.circuit import Node, PhasePolyBox, Qubit # type: ignore
from pytket.placement import Placement # type: ignore
from typing import Tuple, Dict

import numpy as np

# simple deterministic heuristic used for testing purposes
def route_subcircuit_func(
Expand Down Expand Up @@ -117,6 +117,127 @@ def test_LexiRouteRoutingMethod() -> None:
assert routed_commands[3].qubits == [nodes[0], nodes[1]]


def test_AASRouteRoutingMethod() -> None:
test_c = Circuit(3, 3)
n_qb = 3
qubit_indices = {Qubit(0): 0, Qubit(1): 1, Qubit(2): 2}
phase_polynomial = {(True, False, True): 0.333, (False, False, True): 0.05}
linear_transformation = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
p_box = PhasePolyBox(n_qb, qubit_indices, phase_polynomial, linear_transformation)

test_c.add_phasepolybox(p_box, [0, 1, 2])

test_c.CX(0, 1).CX(0, 2).CX(1, 2)
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,
[
AASRouteRoutingMethod(1),
LexiLabellingMethod(),
LexiRouteRoutingMethod(),
AASLabellingMethod(),
],
)


def test_AASRouteRoutingMethod_2() -> None:
test_c = Circuit(3, 3)
n_qb = 3
qubit_indices = {Qubit(0): 0, Qubit(1): 1, Qubit(2): 2}
phase_polynomial = {(True, False, False): 0.333}
linear_transformation = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
p_box = PhasePolyBox(n_qb, qubit_indices, phase_polynomial, linear_transformation)

test_c.add_phasepolybox(p_box, [0, 1, 2])

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,
[
AASRouteRoutingMethod(1),
LexiLabellingMethod(),
LexiRouteRoutingMethod(),
AASLabellingMethod(),
],
)
routed_commands = test_c.get_commands()

assert routed_commands[0].op.type == OpType.Rz
assert routed_commands[0].qubits == [nodes[0]]
assert len(routed_commands) == 1


def test_AASRouteRoutingMethod_3() -> None:
test_c = Circuit(3, 3)
n_qb = 3
qubit_indices = {Qubit(0): 0, Qubit(1): 1, Qubit(2): 2}
phase_polynomial = {(True, True, False): 0.333}
linear_transformation = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
p_box = PhasePolyBox(n_qb, qubit_indices, phase_polynomial, linear_transformation)

test_c.add_phasepolybox(p_box, [0, 1, 2])

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,
[
AASRouteRoutingMethod(1),
AASLabellingMethod(),
],
)
routed_commands = test_c.get_commands()

assert routed_commands[0].op.type == OpType.CX
assert routed_commands[0].qubits == [nodes[0], nodes[1]]
assert routed_commands[1].op.type == OpType.Rz
assert routed_commands[1].qubits == [nodes[1]]
assert routed_commands[2].op.type == OpType.CX
assert routed_commands[2].qubits == [nodes[0], nodes[1]]
assert len(routed_commands) == 3


def test_AASRouteRoutingMethod_4() -> None:
test_c = Circuit(3, 3)
n_qb = 3
qubit_indices = {Qubit(0): 0, Qubit(1): 1, Qubit(2): 2}
phase_polynomial = {(True, True, False): 0.333}
linear_transformation = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
p_box = PhasePolyBox(n_qb, qubit_indices, phase_polynomial, linear_transformation)

test_c.add_phasepolybox(p_box, [0, 1, 2])
test_c.CX(0, 1)

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,
[
AASRouteRoutingMethod(1),
LexiLabellingMethod(),
LexiRouteRoutingMethod(),
AASLabellingMethod(),
],
)
routed_commands = test_c.get_commands()

assert routed_commands[0].op.type == OpType.CX
assert routed_commands[0].qubits == [nodes[0], nodes[1]]
assert routed_commands[1].op.type == OpType.Rz
assert routed_commands[1].qubits == [nodes[1]]
assert routed_commands[2].op.type == OpType.CX
assert routed_commands[2].qubits == [nodes[0], nodes[1]]
assert routed_commands[3].op.type == OpType.CX
assert routed_commands[3].qubits == [nodes[0], nodes[1]]
assert len(routed_commands) == 4


def test_RoutingMethodCircuit_custom() -> None:
test_c = Circuit(3).CX(0, 1).CX(0, 2).CX(1, 2)
nodes = [Node("test", 0), Node("test", 1), Node("test", 2)]
Expand Down
114 changes: 114 additions & 0 deletions tket/src/Mapping/AASLabelling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright 2019-2022 Cambridge Quantum Computing
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "Mapping/AASLabelling.hpp"

namespace tket {

std::pair<bool, unit_map_t> AASLabellingMethod::routing_method(
std::shared_ptr<MappingFrontier>& mapping_frontier,
const ArchitecturePtr& architecture) const {
bool found_unplaced_qubit = false;
bool found_unplaced_ppb = false;

// search for unplaced qubitto speed up the runtime
for (Qubit q : mapping_frontier->circuit_.all_qubits()) {
if (!architecture->node_exists(Node(q))) {
found_unplaced_qubit = true;
break;
}
}
if (found_unplaced_qubit) {
std::shared_ptr<unit_frontier_t> next_frontier =
frontier_convert_vertport_to_edge(
mapping_frontier->circuit_, mapping_frontier->quantum_boundary);

CutFrontier next_cut = mapping_frontier->circuit_.next_cut(
next_frontier, std::make_shared<b_frontier_t>());

for (const Vertex& v : *next_cut.slice) {
if (mapping_frontier->circuit_.get_OpType_from_Vertex(v) ==
OpType::PhasePolyBox) {
TKET_ASSERT(mapping_frontier->circuit_.is_quantum_node(v));
Op_ptr op_ptr_ppb =
mapping_frontier->circuit_.get_Op_ptr_from_Vertex(v);

for (const Edge& e : mapping_frontier->circuit_.get_in_edges_of_type(
v, EdgeType::Quantum)) {
for (const std::pair<UnitID, Edge>& pair :
next_frontier->get<TagKey>()) {
if (pair.second == e) {
if (!architecture->node_exists(Node(pair.first))) {
found_unplaced_ppb = true;
}
}
}
}
}
}
}

if (!found_unplaced_ppb) {
return {false, {}};
} else {
qubit_vector_t q_vec = mapping_frontier->circuit_.all_qubits();
unit_map_t qubit_to_nodes_place;
node_set_t node_set_placed;

for (Qubit q : q_vec) {
if (architecture->node_exists(Node(q))) {
qubit_to_nodes_place.insert({q, Node(q)});
node_set_placed.insert(Node(q));
}
}

node_vector_t nodes_vec = architecture->get_all_nodes_vec();

// place all unplaced qubits

for (Qubit q : q_vec) {
if (!architecture->node_exists(Node(q))) {
// found unplaced qubit
// other checks could be added here to avoid placing unused qubits or
// qubits that are not in an ppb

unsigned index_to_use = 0;
while (node_set_placed.find(nodes_vec[index_to_use]) !=
node_set_placed.end()) {
++index_to_use;
}
qubit_to_nodes_place.insert({q, nodes_vec[index_to_use]});
node_set_placed.insert(nodes_vec[index_to_use]);
}
}

mapping_frontier->update_quantum_boundary_uids(qubit_to_nodes_place);
mapping_frontier->circuit_.rename_units(qubit_to_nodes_place);

return {true, {}};
}
}

nlohmann::json AASLabellingMethod::serialize() const {
nlohmann::json j;
j["name"] = "AASLabellingMethod";
return j;
}

AASLabellingMethod AASLabellingMethod::deserialize(
const nlohmann::json& /*j*/) {
return AASLabellingMethod();
}

} // namespace tket
Loading

0 comments on commit 57babdc

Please sign in to comment.