Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the gate system by introducing a generic Operation variant and updating fusers, runners, and Python bindings to support it. Critical bugs were identified in lib/fuser_mqubit.h where an undefined variable time was used in error messages. Additionally, the use of std::terminate() in lib/operation_base.h for error handling was flagged as inappropriate for a library, with suggestions to use exceptions or static assertions instead.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the core operation model by introducing a generic std::variant-based Operation type, replacing specific gate structures across the library, applications, and Python bindings. This change necessitates a transition to C++17 and updates to fusers, runners, and simulators to handle the new polymorphic operation container. The review identifies a critical logic error in the noise-application functions, AddNoise and MakeNoisy, where Measurement operations are incorrectly treated as unitary gates. This results in invalid state-collapse simulations due to erroneous timestamp modifications and the inappropriate addition of noise channels. The feedback suggests implementing specialized handling for measurements to maintain simulation integrity.
Summary
This PR implements a major refactoring of the gate interface and circuit representation within
qsim. To improve type safety and extensibility, the monolithicGatestruct has been decomposed into specialized types. The core circuit element is now transitioned to anOperationvariant, allowing for more granular handling of gates, measurements, and noise channels. This is a breaking change for internal APIs.Key Changes
Gatestruct into distinct types:Gate: Standard unitary operations.ControlledGate: Operations with control.Measurement: Measurement operations.Channel: Unitary and non-unitary quantum channels.DecomposedGate: Schmidt-decomposed gates.std::variantto define the basic unit of a circuit.using Operation = std::variant<Gate, ControlledGate, Measurement, Channel>;using Operation = std::variant<FusedGate, Measurement, const Operation*>;Operationtypes. Unified clean and noisy circuits.Future-Proofing & Extensibility
By moving to a variant-based
Operationmodel, the architecture is now significantly more flexible. This refactoring explicitly paves the way for:Gatelogic.