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

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

Open
ChenZhao44 opened this issue Jun 12, 2023 · 1 comment
Labels
code quality Code that should be refactored good first issue Good for newcomers

Comments

@ChenZhao44
Copy link
Contributor

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!.

@Krastanov
Copy link
Member

@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 Krastanov changed the title Unsafe behavior of sMZ during ECC simulation When passing a circuit to mctrajectory, pftrajectory and others, verify that it does not perform any unsafe operations Jun 20, 2023
@Krastanov Krastanov added good first issue Good for newcomers code quality Code that should be refactored labels Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Code that should be refactored good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants