Replies: 3 comments 5 replies
-
@BoxiLi Where should I begin with these changes ? Wanted to check where my draft PR should go ? This repo or For now, I will begin with the new subclasses. Your proposed changes to how a circuit is defined could be made later once all the gates are structured properly. |
Beta Was this translation helpful? Give feedback.
-
@BoxiLi Feel free to add to the checklist below.
|
Beta Was this translation helpful? Give feedback.
-
@BoxiLi For the sub-classes of Would you prefer there also be sub-classes based of off what already exists here - |
Beta Was this translation helpful? Give feedback.
-
Background
In QuTiP, a quantum circuit is represented by a class
QubitCircuit
, with a list ofGate
orMeasurement
instances saved in it. As the number of gate types increases, it is becoming harder and harder to maintain. In many methods, one needs to iterate over a list of all possible gates (resolve_gate
,propagators
and latex plotting). This makes adding a new gate very cumbersome. Although there is a classGate
, it is only used to check the input type as well as the name. To make further development on circuit simulation easier, a refactor forGate
is necessary.Proposal
New Gate class architechture
A new structure for
Gate
class with different gates defined as subclasses:Operation
Common methods for quantum gates such as
resolve_gate
can be then moved to eachGate
subclass:If a method is not supported for one class, we can simply define a method in the top-level parent class for error handling:
This is a much better structure than a lookup table in every method.
The user interface should not change. However, to support the old syntax
Gate("X", targets, controls, ...)
, we may still need a lookup table in the classGate
.New way of defining a circuit
The current way of adding a gate to the circuit is the following
With the new gate class, we should be able to also use the following syntax
which is more convenient. This could be implemented independently from the new gate class structure.
Beta Was this translation helpful? Give feedback.
All reactions