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

Failing hugr decoder with custom operations. #683

Closed
aborgna-q opened this issue Nov 13, 2023 · 1 comment · Fixed by #690
Closed

Failing hugr decoder with custom operations. #683

aborgna-q opened this issue Nov 13, 2023 · 1 comment · Fixed by #690
Labels
bug Something isn't working

Comments

@aborgna-q
Copy link
Collaborator

aborgna-q commented Nov 13, 2023

The following test fails while computing the signature of the opaque operation.
(Called unwrap on a None at src/ops/custom.rs:87:54).

const V: &str = r#"{
    "version":"v0",
    "nodes": [
      {"parent":0,"input_extensions":null,"op":"DFG","signature":{"input":[{"t":"Q"}],"output":[{"t":"Q"}],"extension_reqs":[]}},
      {"parent":0,"input_extensions":null,"op":"Input","types":[{"t":"Q"}]},
      {"parent":0,"input_extensions":null,"op":"Output","types":[{"t":"Q"}]},
      {"parent":0,"input_extensions":null,"op":"LeafOp","lop":"CustomOp","extension":"TKET1","op_name":"TKET1 Json Op","description":"An opaque TKET1 operation.","args":[{"tya":"Opaque","arg":{"typ":{"extension":"TKET1","id":"TKET1 Json Payload","args":[],"bound":"E"},"value":{"op":{"type":"V","signature":["Q"]},"num_qubits":1,"num_bits":0,"param_inputs":[],"num_params":0}}}],
        "signature":null
      }
    ],
    "edges":[[[1,0],[3,0]],[[3,0],[2,0]]],
    "metadata":[{"TKET1_JSON.bit_registers":[],"TKET1_JSON.implicit_permutation":[[["q",[0]],["q",[0]]]],"TKET1_JSON.phase":"0.0","TKET1_JSON.qubit_registers":[["q",[0]]],"name":null},null,null,null]
}"#;

fn main() {
    let _circ: hugr::Hugr = serde_json::from_str(V).unwrap();
}

Notice that the signature of the opaque op is not included.

The HUGR was generated by TKET2 from the following qasm file and serde_json-encoded (the same error happens with any other non-supported opaque operation).

OPENQASM 2.0;
include "qelib1.inc";

qreg q[1];
v q[0];

The example is in the branch deser-opaqueop. Just cargo run --example deser_opaque`

@aborgna-q aborgna-q added the bug Something isn't working label Nov 13, 2023
@aborgna-q
Copy link
Collaborator Author

aborgna-q commented Nov 13, 2023

TKET1 Json Op signatures are computed based on the operation parameters.
The resulting signature for the OpaqueOp should always be encoded in the json, so that we don't require access to the extension at decoding time.

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