CQCL / tket-json-rs

Rust data structure for serialising/deserialising TKET Circuit JSON v1
http://crates.io/crates/tket-json-rs
Apache License 2.0
2 stars 1 forks source link

Add support for `classical` field in `Operation` #53

Closed johnchildren closed 2 weeks ago

johnchildren commented 2 weeks ago

https://github.com/CQCL/tket/blame/a47578ec5d79bb5caf23ef2edee3f587bc3c7d14/schemas/circuit_v1.json#L127

According to the tket json schema Operation field should support the classical field for some kinds of Operations. Attached is an example of what a python implementation might look like.

class Conditional(BaseModel):
    """Used in Operation. Defines gate operation conditionally on classical registers.

    Based on pytket.circuit.Conditional."""

    op: "Operation"
    width: int
    value: int

class GenericClassical(BaseModel):
    """Type that encompasses all the classical operations listed in generic_classical_types.
    Those operations are described in https://cqcl.github.io/tket/pytket/api/optype.html, but
    they all have the same fields and so can be serialised and deserialised using this
    GenericClassical type."""

    n_i: Optional[int] = None
    n_io: Optional[int] = None
    name: Optional[str] = None
    values: Optional[Union[List[int], List[bool]]] = None
    upper: Optional[int] = None
    lower: Optional[int] = None

Classical = Union[
    MultiBit,  # If the Classical has an `n` field we know it's a MultiBit operation.
    GenericClassical,
]
johnchildren commented 2 weeks ago

https://github.com/CQCL/tket/blame/a47578ec5d79bb5caf23ef2edee3f587bc3c7d14/schemas/circuit_v1.json#L340 Shows the list of Operation types where this field is required