1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- from typing import List , Literal , Optional , Union
15+ from __future__ import annotations
1616
17- # %%
18- from oqd_compiler_infrastructure import TypeReflectBaseModel , VisitableBaseModel
17+ from typing import Annotated , List , Optional , Union
18+
19+ from oqd_compiler_infrastructure import TypeReflectBaseModel
20+ from pydantic import Discriminator
1921from pydantic .types import NonNegativeInt
2022
21- from oqd_core .interface .analog .operator import OperatorSubtypes
23+ from oqd_core .interface .analog .operator import OperatorSubTypes
2224
2325__all__ = [
2426 "AnalogCircuit" ,
3335########################################################################################
3436
3537
36- class AnalogGate (TypeReflectBaseModel ):
38+ class AnalogOperation (TypeReflectBaseModel ):
3739 """
38- Class representing an analog gate composed of Hamiltonian terms and dissipation terms
39-
40- Attributes:
41- hamiltonian (Operator): Hamiltonian terms of the gate
40+ Class representing an analog operation applied to the quantum system
4241 """
4342
44- hamiltonian : OperatorSubtypes
43+ pass
44+
45+
46+ ########################################################################################
4547
4648
47- # %%
48- class AnalogOperation (VisitableBaseModel ):
49+ class AnalogGate (TypeReflectBaseModel ):
4950 """
50- Class representing an analog operation applied to the quantum system
51+ Class representing an analog gate composed of Hamiltonian terms and dissipation terms
52+
53+ Attributes:
54+ hamiltonian (Operator): Hamiltonian terms of the gate
5155 """
5256
53- pass
57+ hamiltonian : OperatorSubTypes
5458
5559
5660class Evolve (AnalogOperation ):
@@ -62,17 +66,18 @@ class Evolve(AnalogOperation):
6266 gate (AnalogGate): Analog gate to evolve by
6367 """
6468
65- key : Literal ["evolve" ] = "evolve"
6669 duration : float
67- gate : Union [AnalogGate , str ]
70+ gate : AnalogGate
71+
72+
73+ ########################################################################################
6874
6975
7076class Measure (AnalogOperation ):
7177 """
7278 Class representing a measurement in the analog circuit
7379 """
7480
75- key : Literal ["measure" ] = "measure"
7681 targets : Optional [List [int ]] = None
7782
7883
@@ -81,14 +86,20 @@ class Initialize(AnalogOperation):
8186 Class representing a initialization in the analog circuit
8287 """
8388
84- key : Literal ["initialize" ] = "initialize"
8589 targets : Optional [List [int ]] = None
8690
8791
92+ ########################################################################################
93+
8894"""
8995Union of classes
9096"""
91- Statement = Union [Measure , Evolve , Initialize ]
97+ AnalogOperationSubTypes = Annotated [
98+ Union [Measure , Evolve , Initialize ], Discriminator (discriminator = "class_" )
99+ ]
100+
101+
102+ ########################################################################################
92103
93104
94105class AnalogCircuit (AnalogOperation ):
@@ -100,7 +111,7 @@ class AnalogCircuit(AnalogOperation):
100111
101112 """
102113
103- sequence : List [Statement ] = []
114+ sequence : List [AnalogOperationSubTypes ] = []
104115
105116 n_qreg : Union [NonNegativeInt , None ] = None
106117 n_qmode : Union [NonNegativeInt , None ] = None
0 commit comments