Comments (4)
Hi Michael,
Thanks for making us aware of that broken link. It looks like our README.md file was not updated properly in our latest release. The cirq routing example notebook was removed from the repository as it was out of date but our new routing example notebook, https://github.com/CQCL/pytket/blob/master/examples/routing_example.ipynb, should cover everything the previous notebook did and more.
In 0.4 we have separated the Placement and Routing methods. The 'pytket.routing.route()’ method uses no default placement method, instead starting with no logical qubits placed on physical qubits and setting the initial placement of logical qubits as they are encountered in gates in the circuit.
This functionality you describe is possible though by using our Placement methods. Cells 32, 33 and 34 in our routing example notebook show how these methods can be used to create qubit mapping objects and reassign circuit boundaries.
Alternatively, if you use the CompilationUnit framework for optimisation and routing of circuits the initial and final maps are tracked and retrievable - https://cqcl.github.io/pytket/build/html/predicates.html?highlight=compilationunit#pytket.predicates.CompilationUnit. Our compilation example notebook gives an introduction to the passes available and how to combine them https://github.com/CQCL/pytket/blob/master/examples/compilation_example.ipynb. The routing notebook gives an introduction on using the CompilationUnit framework for routing circuits with predicates in cells 36-42.
Thanks,
Silas
from pytket-docs.
Hi Silas,
thanks for your answer!
I struggle a bit to understand the Placement methods (cells 32,33 and 34). In the example, they are used before calling the route function, so I guess the Placement is finding the initial mapping, is that right? How would I get the final mapping then? If this is already the final mapping, what does "unplaced" mean then?
I also tried using the CompilationUnit with the passes "gen_default_mapping_pass()" to route the circuits and "RebasePyZX()" to get rid of the BRIDGE gates. Whenever there is no BRIDGE gate (after using the first pass), the results are correct (compared to the same circuit on a fully-connected device). However, if there is a BRIDGE, this seems not to be true anymore. As I understood, the BRIDGE gate is a distributed CX-gate, which should not change the final qubit mapping. The same happens if I use 'pytket.transform.Transform.DecomposeBRIDGE()'. Are you aware of this problem or do you know what reason this could have? Can I provide the "gen_default_mapping_pass()" a parameter telling it not to uses BRIDGEs, similar as the bridge_interactions parameter in the route function?
Thanks a lot,
Michael
from pytket-docs.
Hi Michael,
Yes, each placement method finds an initial map for the circuit depending on the device connectivity constraints. This map can be partial - some placement methods may opt to not assign all logical qubits to physical nodes. This may be because a logical qubit has its first two-qubit interaction deep in to the circuits execution, and so the placement method can’t accurately predict how the initial map will have changed by the time this two-qubit interaction is encountered. Allowing the routing method to deal with unplaced qubits as it routes the circuit leads to result improvements. The place() method reassigns qubits in a Circuits boundary to Nodes of a Device object. If a full initial map is desired, values in the partial initial map can be manually converted to nodes in the device. I have inserted a sample code snippet here that shows one way of doing this.
def find_adjacent_node(used_nodes, coupling_map):
for couple in coupling_map:
if couple[0] in used_nodes and couple[1] not in used_nodes:
return couple[1]
if couple[0] not in used_nodes and couple[1] in used_nodes:
return couple[0]
def fill_partial_mapping(dev, partial_map):
used_nodes = set()
unplaced_qubits = set()
new_map = partial_map
for k, v in partial_map.items():
if v.reg_name != 'unplaced':
used_nodes.add(v)
if v.reg_name == 'unplaced':
unplaced_qubits.add(k)
for q in unplaced_qubits:
n = find_adjacent_node(used_nodes, dev.get_coupling())
used_nodes.add(n)
new_map[q] = n
return new_map
my_placer = GraphPlacement(my_device)
partial_initial_mapping = my_placer.get_placement_map(my_circuit)
full_initial_mapping = fill_partial_mapping(my_device, partial_initial_mapping)
To return the final mapping outside of the CompilationUnit framework, the method _route_return_map can be imported from pytket.routing, which takes the same arguments as “route” but returns a pair of {Circuit, final_map}. A combination of filling the partial mapping and returning the final map here should emulate the previous behaviour you desired.
The BRIDGE gate is a distributed-CX gate and so shouldn’t change the final qubit mapping. I am not aware of a problem but I will investigate and keep you updated. It is currently not possible to change the routing parameters using “gen_default_mapping_pass”, but I shall add this functionality for our next release.
Thanks,
Silas
from pytket-docs.
Hi Silas,
thanks a lot for your detailed answer and thanks for explaining to me how the Placement methods work!
The method "_route_return_map" is exactly doing what I was looking for and returns the correct final mapping.
Best regards,
Michael
from pytket-docs.
Related Issues (20)
- Is there a simple example for inner/outer product of single qubit states? HOT 5
- Initialisation of qubits passed to the backends HOT 3
- ImportError: cannot import name 'ToffoliBox' from 'pytket.circuit' (/usr/local/lib/python3.7/dist-packages/pytket/circuit/__init__.py) HOT 2
- Mention `EmpiricalDistribution` and `ProbabilityDistribution` in the user manual
- [CI] [examples] Investigate excessive time taken to run some notebooks
- [CI] New workflow for updating pre-commit hooks HOT 1
- pytket 1.1.0 depends on networkx~=2.4 HOT 1
- enable qsharp backend in comparing_simulators.py HOT 1
- remove `pre-commit == 3.0.0` from manual page HOT 1
- update to sphinx 6.2 HOT 5
- `optimisation_level=2` bug HOT 1
- `ImportError` with pytket>=1.20 and Python 3.11 HOT 2
- missing `ipykernel` requirement HOT 5
- Manual build failing HOT 2
- Re-enable warning-as-error for `sphinx-build` HOT 1
- BackendResult incorrect return types for strict type checking HOT 1
- Remove mention of retired IBM devices from user manual and examples HOT 2
- Fix manual and examples to be compatible with pytket-qiskit 0.49 HOT 1
- Latest pytket-qiskit incompatible with pytket-pyquil HOT 4
- Remove scipy version pin in manual build after next pytket release
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytket-docs.