diff --git a/src/circuit_json.rs b/src/circuit_json.rs index 74111a4..566cf96 100644 --- a/src/circuit_json.rs +++ b/src/circuit_json.rs @@ -137,6 +137,17 @@ pub enum Classical { }, } +/// Additional fields for Wasm operations. +#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)] +pub struct Wasm { + n: u64, + ww_n: u64, + width_i_parameter: Vec, + width_o_parameter: Vec, + func_name: String, + wasm_file_uid: String, +} + /// Serializable operation descriptor. #[derive(Deserialize, Serialize, Clone, Debug, PartialEq)] #[non_exhaustive] @@ -166,6 +177,9 @@ pub struct Operation

{ /// Data for commands which only act on Bits classically. #[serde(skip_serializing_if = "Option::is_none")] pub classical: Option>, + /// Data for commands which apply WASM operations. + #[serde(skip_serializing_if = "Option::is_none")] + pub wasm: Option>, } /// Operation applied in a circuit, with defined arguments. @@ -206,6 +220,9 @@ pub struct SerialCircuit

{ pub bits: Vec, /// Implicit permutation of the output qubits. pub implicit_permutation: Vec, + /// Number of wasm wires in the circuit. + #[serde(skip_serializing_if = "Option::is_none")] + pub number_of_ws: Option, } impl

Default for Operation

{ @@ -219,6 +236,7 @@ impl

Default for Operation

{ signature: None, conditional: None, classical: None, + wasm: None, } } } diff --git a/tests/data/wasm.json b/tests/data/wasm.json new file mode 100644 index 0000000..ff1cef5 --- /dev/null +++ b/tests/data/wasm.json @@ -0,0 +1,35 @@ +{ + "bits": [], + "commands": [ + { + "args": [["_w", [0]]], + "op": { + "type": "WASM", + "wasm": { + "func_name": "add_two", + "n": 0, + "wasm_file_uid": "6a0a29e235cd5c60353254bc2b459e631d381cdd0bded7ae6cb44afb784bd2de", + "width_i_parameter": [0], + "width_o_parameter": [0], + "ww_n": 1 + } + } + } + ], + "implicit_permutation": [ + [ + ["q", [0]], + ["q", [0]] + ], + [ + ["q", [1]], + ["q", [1]] + ] + ], + "number_of_ws": 1, + "phase": "0.0", + "qubits": [ + ["q", [0]], + ["q", [1]] + ] +} diff --git a/tests/roundtrip.rs b/tests/roundtrip.rs index e3c1466..41aa4ea 100644 --- a/tests/roundtrip.rs +++ b/tests/roundtrip.rs @@ -7,11 +7,13 @@ use tket_json_rs::SerialCircuit; const SIMPLE: &str = include_str!("data/simple.json"); const CLASSICAL: &str = include_str!("data/classical.json"); const DIAGONAL: &str = include_str!("data/diagonal-box.json"); +const WASM: &str = include_str!("data/wasm.json"); #[rstest] #[case::simple(SIMPLE, 4)] #[case::classical(CLASSICAL, 3)] #[case::diagonal_box(DIAGONAL, 1)] +#[case::wasm_box(WASM, 1)] fn roundtrip(#[case] json: &str, #[case] num_commands: usize) { let initial_json: Value = serde_json::from_str(json).unwrap(); let ser: SerialCircuit = serde_json::from_value(initial_json.clone()).unwrap();