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

RoutingPass runs forever with Unitary2qBox #1463

Open
Jackattack10313 opened this issue Jun 23, 2024 · 2 comments
Open

RoutingPass runs forever with Unitary2qBox #1463

Jackattack10313 opened this issue Jun 23, 2024 · 2 comments
Assignees
Labels
bug Something isn't working stale

Comments

@Jackattack10313
Copy link

Here's my circuit and my compilation code

circuit = pytket.Circuit(n_qubits)
box = pytket.circuit.Unitary2qBox(generate_random_op())
circuit.add_unitary2qbox(box, 0, 1)
circuit.add_unitary2qbox(box, 2, 3)
circuit.add_unitary2qbox(box, 1, 2)
circuit.add_unitary2qbox(box, 0, 3)

arch = pytket.architecture.Architecture([(0,1), (1, 2), (2, 3), (3, 4)])

from pytket.placement import LinePlacement
from pytket.passes import PlacementPass, RoutingPass

PlacementPass(LinePlacement(arch)).apply(circuit)
RoutingPass(arch).apply(circuit)

If I replace the unitary2qbox components with any predefined 2 qubit gate, the code executes without issue.

@CalMacCQ
Copy link
Contributor

CalMacCQ commented Jun 24, 2024

Thanks for making an issue,

Is the call to generate_random_op making a random 2 qubit unitary matrix? I've replaced it with a specific unitary below to ensure reproducibility.

I have actually reporoduced this... It does seem like RoutingPass gets stuck for me. I think its a problem with RoutingPass not working with Unitary2qBox in general. As a user its fair to expect this to either succeed or raise an informative error.

from pytket.circuit import Circuit, Unitary2qBox
from pytket.placement import LinePlacement
from pytket.passes import PlacementPass, RoutingPass
from pytket.architecture import Architecture
import numpy as np


# Define 2q unitary subroutine
unitary_2q = np.asarray([[0, 1, 0, 0],
                        [0, 0, 0, -1],
                        [1, 0, 0, 0],
                        [0, 0, -1j, 0]])

box_2q = Unitary2qBox(unitary_2q)


# Build Circuit
circuit = Circuit(4)
circuit.add_unitary2qbox(box_2q, 0, 1)
circuit.add_unitary2qbox(box_2q, 2, 3)
circuit.add_unitary2qbox(box_2q, 1, 2)
circuit.add_unitary2qbox(box_2q, 0, 3)


# Define architecture
arch = Architecture([(0, 1), (1, 2), (2, 3), (3, 4)])

# Perform placement pass
PlacementPass(LinePlacement(arch)).apply(circuit)

All of the above works fine.. If I now do

RoutingPass(arch).apply(circuit)

This seems to not terminate with python 3.11.1 and pytket v 1.27 which is indeed puzzling... we should look into that. If however I perform the DecomposeBoxes pass to decompose the unitaries to simpler gates and then do the RoutingPass everything works fine. It seems that RoutingPass is not playing nicely with the higher level box operations.

Seems like a bug to me.

Workaround below

from pytket.passes import DecomposeBoxes

# Define architecture
arch = Architecture([(0, 1), (1, 2), (2, 3), (3, 4)])

# Route circuit
PlacementPass(LinePlacement(arch)).apply(circuit)

# Decompose the Unitary boxes to primitive gates - this is the new step
DecomposeBoxes().apply(circuit)

# Route Circuit
RoutingPass(arch).apply(circuit) # Now working

@CalMacCQ CalMacCQ added the bug Something isn't working label Jun 24, 2024
@CalMacCQ CalMacCQ changed the title Routing pass runs forever with unitary2qbox RoutingPass runs forever with Unitary2qBox Jun 24, 2024
Copy link

github-actions bot commented Nov 1, 2024

This issue has been automatically marked as stale.

@github-actions github-actions bot added the stale label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

3 participants