QuantumClifford.jl icon indicating copy to clipboard operation
QuantumClifford.jl copied to clipboard

When passing a circuit to `mctrajectory`, `pftrajectory` and others, verify that it does not perform any unsafe operations

Open ChenZhao44 opened this issue 1 year ago • 1 comments

using QuantumClifford
using QuantumClifford.ECC

circ = [
    sHadamard(1),
    sCNOT(1, 2),
    sMZ(1),
    sMZ(2),
]

frames = PauliFrame(10, 2, 2)
pftrajectories(frames, circ)

sMZ(1) and sMZ(2) will cause an out-of-bounds behavior that could crash the program without throwing an error. This is because they are equivalent to sMZ(1, 0) and sMZ(2, 0) and will try to access index 0. I recommend changing the default parameter of bit to 1 instead of 0. Ideally, it would be better to check the indices in pftrajectories for the circuit we are going to simulate before calling apply!.

ChenZhao44 avatar Jun 12 '23 15:06 ChenZhao44

@ChenZhao44 , this is now fixed -- if the index is 0, it is simply not saved anywhere. The default of 1 would also be unsafe, because there is not guarantee that a frame would have allocated even one bit of space for classical memory. I will leave this open as a general issue for "preprocess circuits to verify they do not have unsafe or undefined operations". It should probably be a part of the compactifation pass.

Krastanov avatar Jun 20 '23 17:06 Krastanov