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

Broken drawing examples #42

Closed
jpmoutinho opened this issue Oct 6, 2023 · 4 comments · Fixed by #210
Closed

Broken drawing examples #42

jpmoutinho opened this issue Oct 6, 2023 · 4 comments · Fixed by #210
Assignees
Labels
bug Something isn't working

Comments

@jpmoutinho
Copy link
Collaborator

jpmoutinho commented Oct 6, 2023

QFT

Some weird CPHASE lines, gets worse for larger QFTs:

from qadence import *
from qadence.draw import display
display(qft(3))

qft

HEA + QFT with tags

  • Qubits not ordered
  • Bottom qubit line ramps up into the HEA at the start
  • Bottom qubit lines jump off a cliff at the end
block_hea = tag(hea(2, 2), "hea")
block_qft = tag(qft(5), "qft")
display(chain(block_hea, block_qft))

test

@jpmoutinho jpmoutinho added the bug Something isn't working label Oct 6, 2023
@jpmoutinho
Copy link
Collaborator Author

Since these seem related to the QFT, it might be useful to have a simplified standalone function that writes it:

import torch
from qadence import *
from qadence.draw import display

def qft_layer(n_qubits, layer_ix):
    qubit_range = range(layer_ix + 1, n_qubits)
    # CPHASE ladder
    cphases = []
    for j in qubit_range:
        angle = torch.pi / (2 ** (j - layer_ix))
        cphases.append(CPHASE(j, layer_ix, angle))
    # Return Hadamard followed by CPHASEs
    return chain(H(layer_ix), *cphases)

def qft_digital(n_qubits):
    return chain(qft_layer(n_qubits, i) for i in range(n_qubits))

display(qft_digital(4))
image

@jpmoutinho
Copy link
Collaborator Author

Here's another example following the structure of the QFT but a bit simpler:

def broken_circuit(n_qubits):
    qubit_range = range(1, n_qubits)
    ops = []
    for j in qubit_range:
        ops.append(CNOT(0, j))
    return chain(*ops)

display(broken_circuit(5))

cnots

The reordering of the qubits happens when n_qubits is odd

@jpmoutinho
Copy link
Collaborator Author

from qadence import *

def broken_circuit(n_qubits):
    qubit_range = range(1, n_qubits)
    ops = []
    for j in qubit_range:
        ops.append(CNOT(0, j))
    return chain(*ops)

display(chain(broken_circuit(4), broken_circuit(2)))

tests

And the tilted controls happens when you chain a circuit with larger qubit support followed by one with smaller qubit support.

@jpmoutinho
Copy link
Collaborator Author

Few more example cases:

Gives error: display(chain(CNOT(0, 3), CNOT(0, 3)))
One on top of the other: display(chain(CNOT(0, 3), CNOT(1, 2)))
Qubit lines don't go to the end: display(chain(CNOT(1, 2), CNOT(0, 3)))
Control line tilted: display(chain(CNOT(0, 3), CNOT(0, 1)))
Second control qubit gets flushed to the end of the circuit: display(chain(CNOT(0, 3), CNOT(1, 3)))

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.

2 participants