Skip to content

[DRAFT] make QRE deterministic#3346

Draft
fedimser wants to merge 5 commits into
mainfrom
fedimser/det-qre
Draft

[DRAFT] make QRE deterministic#3346
fedimser wants to merge 5 commits into
mainfrom
fedimser/det-qre

Conversation

@fedimser

@fedimser fedimser commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Why?

  • QRE, when translating Cirq circuit to trace and encountering classically-controlled gate, does this:
elif isinstance(op, ClassicallyControlledOperation):
    if random.random() < self.classical_control_probability:
        self.handle_op(op.without_classical_controls())
  • When we have n IAND gates, they on average produce 0.5*n CZ gates. QRE will not count exactly 0.5*n, but it will count some number close to 0.5*n.
  • Let's say I want to optimize trace generation for some gate that I know generates n IAND gates. If I use push_block(n)/IAND/pop_block, instead of getting approximately 0.5*n CZ gates in result, I will get either 0 or n CZ gates, with probability 0.5 each. For large n this introduces large discrepancy, and direction of that discrepancy (over or under estimation) is random.
  • My solution is instead of flipping a coin and probabilistically adding non-controlled gate, always add the gate but multiply all counts it produces by 0.5. I.e. replace the code above with:
elif isinstance(op, ClassicallyControlledOperation):
    self.push_block(self.classical_control_probability)
    self.handle_op(op.without_classical_controls())
    self.pop_block()
  • This also requires us to change a lot of types in Rust code from u64 to f64.

I am not sure it's the best way to do this, as using real numbers introduces different kind of non-determinism, related to rounding errors. Also clippy doesn't like mixing u64 and f64.

@fedimser fedimser changed the title make QRE deterministic [DRAFT] make QRE deterministic Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant