Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dialects: (qft) initialise dialect #67

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions inconspiquous/dialects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def get_qec():

return QEC

def get_qft():
from inconspiquous.dialects.qft import QFT

return QFT

def get_qref():
from inconspiquous.dialects.qref import Qref

Expand Down Expand Up @@ -107,6 +112,7 @@ def get_varith():
"measurement": get_measurement,
"prob": get_prob,
"qec": get_qec,
"qft": get_qft,
"qref": get_qref,
"qubit": get_qubit,
"qssa": get_qssa,
Expand Down
40 changes: 40 additions & 0 deletions inconspiquous/dialects/qft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from xdsl.dialects.builtin import IntAttr
from xdsl.ir import Dialect
from xdsl.irdl import irdl_attr_definition, ParameterDef
from xdsl.parser import AttrParser
from xdsl.printer import Printer

from inconspiquous.gates import GateAttr


@irdl_attr_definition
class QFTAttr(GateAttr):
name = "qft.n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative to this would be to have an algorithm or algo dialect and put qft inside. Do you see anything else being in this dialect?


num_qubits_param: ParameterDef[IntAttr]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
num_qubits_param: ParameterDef[IntAttr]
qubits: ParameterDef[IntAttr]

Would this be simpler?


@property
def num_qubits(self) -> int:
return self.num_qubits_param.data

def __init__(self, num_qubits: int | IntAttr):
if not isinstance(num_qubits, IntAttr):
num_qubits = IntAttr(num_qubits)

super().__init__((num_qubits,))

@classmethod
def parse_parameters(cls, parser: AttrParser) -> tuple[IntAttr]:
with parser.in_angle_brackets():
num_qubits = parser.parse_integer(allow_negative=False, allow_boolean=False)
return (IntAttr.new(num_qubits),)

def print_parameters(self, printer: Printer) -> None:
return self.num_qubits_param.print_parameter(printer)


QFT = Dialect(
"qft",
[],
[QFTAttr],
)
5 changes: 5 additions & 0 deletions tests/filecheck/dialects/qft/ops.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: QUOPT_ROUNDTRIP

"test.op"() {gate = #qft.n<5>} : () -> ()

// CHECK: "test.op"() {gate = #qft.n<5>} : () -> ()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have a test with a use of the gate to check that number of qubits is working correctly

Loading