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

CliffordResynthesis pass can create invalid circuits #1468

Closed
cqc-alec opened this issue Jun 25, 2024 · 3 comments · Fixed by #1476
Closed

CliffordResynthesis pass can create invalid circuits #1468

cqc-alec opened this issue Jun 25, 2024 · 3 comments · Fixed by #1476
Assignees
Labels
bug Something isn't working

Comments

@cqc-alec
Copy link
Collaborator

from pytket.circuit import Circuit
from pytket.passes import CliffordResynthesis
import json

with open("circ.json", "r") as f:
    circuit = Circuit.from_dict(json.load(f))

CliffordResynthesis().apply(circuit)
cmds = circuit.get_commands()
print(cmds)

generates a critical assertion error while attempting to construct the command list.
circ.json

@cqc-alec cqc-alec added the bug Something isn't working label Jun 25, 2024
@cqc-alec cqc-alec self-assigned this Jun 25, 2024
@cqc-alec
Copy link
Collaborator Author

cqc-alec commented Jun 26, 2024

A much smaller example:

from pytket.circuit import Circuit
from pytket.passes import CliffordResynthesis

c = Circuit(6)
c.CZ(1, 4)
c.CZ(2, 3)
c.SWAP(3, 5)
c.CZ(1, 5)
c.SWAP(3, 5)
c.CZ(4, 5)
c.SWAP(1, 4)
c.CZ(1, 2)
c.CZ(3, 4)
c.SWAP(4, 5)
c.CZ(0, 3)
c.CZ(1, 5)
c.CZ(0, 4)

c.replace_SWAPs()
CliffordResynthesis().apply(c)
cmds = c.get_commands()
print(cmds)

generates the same assertion error.

@cqc-alec
Copy link
Collaborator Author

cqc-alec commented Jun 26, 2024

The implicit qubit permutation was a red herring. This even simpler example exhibits the problem:

from pytket.circuit import Circuit
from pytket.passes import CliffordResynthesis

c = Circuit(6)
c.CZ(1, 4)
c.CZ(2, 3)
c.CZ(1, 3)
c.CZ(4, 5)
c.CZ(4, 2)
c.CZ(3, 1)
c.CZ(0, 3)
c.CZ(4, 1)
c.CZ(0, 5)

CliffordResynthesis().apply(c)
cmds = c.get_commands()
print(cmds)

@cqc-alec
Copy link
Collaborator Author

There is a basic error in the logic used for CliffordResynthesis.

The logic is: first partition the circuit into convex subcircuits; then for each of those subcircuits, substitute its vertices with a resynthesised subcircuit.

"Convex" means that every path from A to B where A and B are vertices in the set contains only vertices that are in the set.

The problem is that after making the first of these substitutions, the second subcircuit may no longer be convex!

For example, consider the following (part of a) circuit:
image
The first convex subcircuit consists of the XXPhase(0.5) and the XXPhase(2.5); the second subcircuit consists of the XXPhase(1.5) and the YYPhase(1.5). These are disjoint convex subcircuits; however, if we were to merge the first one into a new "blob", with 3 inputs and 3 outputs, then the second one would no longer be convex because there is a path from the XXPhase(1.5) to the YPhase(1.5) passing through the blob and the YYPhase(0.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant