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

Ensure register decls and usage match #242

Open
qartik opened this issue Oct 8, 2024 · 0 comments
Open

Ensure register decls and usage match #242

qartik opened this issue Oct 8, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@qartik
Copy link
Member

qartik commented Oct 8, 2024

A possible "gotcha" here is that if a pytket circuit contains bits that do not form part of a full register -- for example, if it contains a bit c[1] but not c[0] -- then these bits are ignored by circuit.c_registers (similarly for qubits). I am not sure how phirgen handles this case currently (maybe an error, maybe add missing bits?) -- but if such a circuit were passed to this function it would presumably generate invalid PHIR.

[...]

Sure, how about this:

from pytket.circuit import Circuit, Qubit, Bit
from pytket.phir.api import pytket_to_phir

circ = Circuit()
circ.add_qubit(Qubit(1))
circ.add_bit(Bit(1))
circ.H(1)
circ.Measure(1, 1)
phir = pytket_to_phir(circ)
print(phir)

Currently this produces the following:

{
  "format": "PHIR/JSON",
  "version": "0.1.0",
  "metadata": { "source": "pytket-phir v0.8.1" },
  "ops": [
    {
      "data": "qvar_define",
      "data_type": "qubits",
      "variable": "q",
      "size": 1
    },
    { "data": "cvar_define", "data_type": "i64", "variable": "c", "size": 1 },
    { "//": "H q[1];" },
    { "qop": "H", "angles": null, "args": [["q", 1]] },
    { "//": "Measure q[1] --> c[1];" },
    { "qop": "Measure", "returns": [["c", 1]], "args": [["q", 1]] }
  ]
}

This looks incorrect, since it seems to be indexing q[1] in a size-1 register. I am not sure what pecos will do with this, probably error?

With the change in this PR, I suspect it will be differently wrong, since the qubit and bit registers would not be declared at all?

I think it would be OK to reject circuits with incomplete registers.

Originally posted by @cqc-alec in #238 (comment)

@qartik qartik self-assigned this Oct 8, 2024
@qartik qartik added the bug Something isn't working label Oct 8, 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
Projects
None yet
Development

No branches or pull requests

1 participant