Coder Social home page Coder Social logo

Comments (1)

CalMacCQ avatar CalMacCQ commented on August 26, 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

from tket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.