tket2 icon indicating copy to clipboard operation
tket2 copied to clipboard

`Circuit::num_gates` not consistent with TKET `n_gates`

Open lmondada opened this issue 2 years ago • 4 comments

The following surprised me. Consider a circuit made of a single rotation:

c = Circuit(1).Rz(0.5, 0)

Obviously, in TK1 we have

c.n_gates # this is 1

However, in TK2, we get

let c_str = r#"{"bits": [], "commands": [{"args": [["q", [0]]], "op": {"params": ["0.5"], "type": "Rz"}}], "created_qubits": [], "discarded_qubits": [], "implicit_permutation": [[["q", [0]], ["q", [0]]]], "phase": "0.0", "qubits": [["q", [0]]]}"#;
let ser: circuit_json::SerialCircuit = serde_json::from_str(c_str).unwrap();
let circ: Hugr = ser.decode().unwrap();
circ.num_gates() // this is 3

After reducing it to this example, it became clear to me that the overhead are the constant nodes introduced, but this is confusing.

lmondada avatar Sep 14 '23 10:09 lmondada

At least num_gates() seems like the wrong name; should be num_nodes() or something.

cqc-alec avatar Sep 14 '23 12:09 cqc-alec

I would also be fine with the current behaviour, but then we should

  • make it explicit in the docs
  • have another method that counts gates TK1-style; I need that for benchmarking (suggestion: num_q_gates).

lmondada avatar Sep 14 '23 13:09 lmondada

We should define what is a gate somewhere (clearly it's not the same as an Op).

aborgna-q avatar Sep 14 '23 13:09 aborgna-q

I would suggest avoiding "gate" as an additional concept, and instead something like num_q_ops

ss2165 avatar Sep 20 '23 08:09 ss2165