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

Fix conditional barriers #119

Closed
qciaran opened this issue Jan 24, 2024 · 2 comments · Fixed by #118
Closed

Fix conditional barriers #119

qciaran opened this issue Jan 24, 2024 · 2 comments · Fixed by #118
Assignees
Labels
enhancement New feature or request

Comments

@qciaran
Copy link
Collaborator

qciaran commented Jan 24, 2024

When I try to run the qasm with conditional barriers like if(m==0) barrier q[0], q[1]; using qasm_to_phir() it raises ValidationError.

It also might be useful to introduce a barrier into PHIR...

@qciaran qciaran added the bug Something isn't working label Jan 24, 2024
@qciaran
Copy link
Collaborator Author

qciaran commented Jan 24, 2024

Here is example Qasm:

OPENQASM 2.0;
include "qelib1.inc";

qreg q[2];
creg m[2];

h q[0];
if(m==0) barrier q[0], q[1];
CX q[0], q[1];

measure q -> m;

@qartik
Copy link
Member

qartik commented Jan 24, 2024

I believe the issue is because we are skipping barriers in PHIR, we do have a todo at

case tk.BarrierOp():
# TODO(kartik): confirm with Ciaran/spec
# https://github.com/CQCL/phir/blob/main/spec.md
logger.debug("Skipping Barrier instruction")
:

        case tk.BarrierOp():
            # TODO(kartik): confirm with Ciaran/spec
            # https://github.com/CQCL/phir/blob/main/spec.md
            logger.debug("Skipping Barrier instruction")

I wasn't sure what the right behavior should be as the spec doesn't mention it. Could you suggest what instruction should be emitted? I can update both the spec and phirgen for this issue.

Here's the PHIR being generated right now:

{
    'format': 'PHIR/JSON',
    'version': '0.1.0',
    'metadata': {'source': 'pytket-phir v0.3.1.dev2'},
    'ops': [
        {'data': 'qvar_define', 'data_type': 'qubits', 'variable': 'q', 'size': 2},
        {'data': 'cvar_define', 'data_type': 'u32', 'variable': 'm', 'size': 2},
        {'//': 'H q[0];'},
        {'qop': 'H', 'angles': None, 'args': [['q', 0]]},
        {'//': 'IF ([m[0], m[1]] == 0) THEN IF ([m[0], m[1]] == 0) THEN Barrier q[0], q[1];'},
        {'block': 'if', 'condition': {'cop': '==', 'args': ['m', 0]}, 'true_branch': [None]},
        {'//': 'CX q[0], q[1];'},
        {'qop': 'CX', 'angles': None, 'args': [[['q', 0], ['q', 1]]]},
        {'//': 'Measure q[0] --> m[0];'},
        {'qop': 'Measure', 'returns': [['m', 0]], 'args': [['q', 0]]},
        {'//': 'Measure q[1] --> m[1];'},
        {'qop': 'Measure', 'returns': [['m', 1]], 'args': [['q', 1]]}
    ]
}

Another related issue #55

@qartik qartik transferred this issue from CQCL/pytket-phir Jan 24, 2024
@qartik qartik added enhancement New feature or request and removed bug Something isn't working labels Jan 25, 2024
qartik referenced this issue Jan 30, 2024
Should fix https://github.com/CQCL/phir/issues/53

Requires CQCL/phir#56

Also requires support for barrier instructions in pecos
@qartik qartik transferred this issue from CQCL/phir Jan 30, 2024
@qartik qartik self-assigned this Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants