Skip to content

Commit

Permalink
fix: include barriers under OpType
Browse files Browse the repository at this point in the history
  • Loading branch information
qartik committed Jan 30, 2024
1 parent d92d6c0 commit f8d5e1b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 48 deletions.
44 changes: 22 additions & 22 deletions phir/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ class ExportVar(Data):

DataMgmt: TypeAlias = CVarDefine | QVarDefine | ExportVar

# Meta Instructions


class Meta(BaseModel, abc.ABC):
"""Meta instructions base class."""

model_config = ConfigDict(extra="forbid")

meta: str


class Barrier(Meta):
"""Barrier instruction."""

meta: Literal["barrier"]
args: list[Bit]


# Operations


Expand Down Expand Up @@ -243,7 +261,7 @@ class MOp(Op):


QOp: TypeAlias = MeasOp | SQOp | TQOp
OpType: TypeAlias = FFCall | COp | QOp | MOp
OpType: TypeAlias = FFCall | COp | QOp | MOp | Barrier


# Blocks
Expand Down Expand Up @@ -277,8 +295,8 @@ class IfBlock(Block):

block: Literal["if"]
condition: COp
true_branch: list[OpType]
false_branch: list[OpType] | None = None
true_branch: list[OpType] | Barrier
false_branch: list[OpType] | Barrier | None = None


BlockType: TypeAlias = SeqBlock | QParBlock | IfBlock
Expand All @@ -295,25 +313,7 @@ class Comment(BaseModel):
c: str = Field(..., alias="//", min_length=3)


# Meta Instructions


class Meta(BaseModel, abc.ABC):
"""Meta instructions base class."""

model_config = ConfigDict(extra="forbid")

meta: str


class Barrier(Meta):
"""Barrier instruction."""

meta: Literal["barrier"]
args: list[Bit]


Cmd: TypeAlias = DataMgmt | OpType | BlockType | Comment | Barrier
Cmd: TypeAlias = DataMgmt | OpType | BlockType | Comment


class PHIRModel(BaseModel):
Expand Down
71 changes: 45 additions & 26 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,30 +389,40 @@
"$ref": "#/$defs/COp"
},
"true_branch": {
"items": {
"anyOf": [
{
"$ref": "#/$defs/FFCall"
},
{
"$ref": "#/$defs/COp"
},
{
"$ref": "#/$defs/MeasOp"
},
{
"$ref": "#/$defs/SQOp"
},
{
"$ref": "#/$defs/TQOp"
"anyOf": [
{
"items": {
"anyOf": [
{
"$ref": "#/$defs/FFCall"
},
{
"$ref": "#/$defs/COp"
},
{
"$ref": "#/$defs/MeasOp"
},
{
"$ref": "#/$defs/SQOp"
},
{
"$ref": "#/$defs/TQOp"
},
{
"$ref": "#/$defs/MOp"
},
{
"$ref": "#/$defs/Barrier"
}
]
},
{
"$ref": "#/$defs/MOp"
}
]
},
"title": "True Branch",
"type": "array"
"type": "array"
},
{
"$ref": "#/$defs/Barrier"
}
],
"title": "True Branch"
},
"false_branch": {
"anyOf": [
Expand All @@ -436,11 +446,17 @@
},
{
"$ref": "#/$defs/MOp"
},
{
"$ref": "#/$defs/Barrier"
}
]
},
"type": "array"
},
{
"$ref": "#/$defs/Barrier"
},
{
"type": "null"
}
Expand Down Expand Up @@ -810,6 +826,9 @@
{
"$ref": "#/$defs/MOp"
},
{
"$ref": "#/$defs/Barrier"
},
{
"$ref": "#/$defs/SeqBlock"
},
Expand Down Expand Up @@ -1000,6 +1019,9 @@
{
"$ref": "#/$defs/MOp"
},
{
"$ref": "#/$defs/Barrier"
},
{
"$ref": "#/$defs/SeqBlock"
},
Expand All @@ -1011,9 +1033,6 @@
},
{
"$ref": "#/$defs/Comment"
},
{
"$ref": "#/$defs/Barrier"
}
]
},
Expand Down

0 comments on commit f8d5e1b

Please sign in to comment.