Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
063683a
init dialect boilerplate
paul0403 Dec 21, 2025
3c0eb80
Add basic gate class and interfaces, and add some of the methods.
paul0403 Dec 22, 2025
b3b42e4
finish interface methods; unit test for interface methods
paul0403 Dec 30, 2025
686a6a4
save
paul0403 Dec 31, 2025
2a500a2
add observable type; add namedobs op
paul0403 Jan 2, 2026
1d29786
Isolate quantum dialect enum definitions into its own file
paul0403 Jan 2, 2026
1ede392
Merge branch 'paul0403/move_quantum_enums_to_base_file' into temp
paul0403 Jan 2, 2026
448e7ba
burn all types and enums in ref quantum dialect
paul0403 Jan 2, 2026
80bdd3c
Isolate quantum dialect's enums and traits into "include" files
paul0403 Jan 2, 2026
345e515
Merge branch 'paul0403/move_quantum_enums_to_base_file' into temp
paul0403 Jan 2, 2026
e2a84c1
traits
paul0403 Jan 2, 2026
5dde1c3
add Quantum as dependent dialect
paul0403 Jan 2, 2026
2e8275d
can use quantum dialect observable type
paul0403 Jan 2, 2026
c739add
use NamedObservable enum and attr from core quantum dialect
paul0403 Jan 2, 2026
8515954
verifier test for bad attribute on namedobs
paul0403 Jan 2, 2026
1da57b1
burn unnecessary stuff
paul0403 Jan 2, 2026
843c939
add a small end-to-end unit test on hadamard(0)-expval(X(0))
paul0403 Jan 2, 2026
fe9e8ee
Merge remote-tracking branch 'origin/main' into RefQ_dialect_base
paul0403 Jan 15, 2026
1c9100c
migrate to Joey's new system
paul0403 Jan 15, 2026
56e6377
set state and basis state
paul0403 Jan 15, 2026
85cda40
gphase op
paul0403 Jan 15, 2026
b68e2a2
multirzop
paul0403 Jan 15, 2026
e8c569e
add duplicate wire verifier test for multirz
paul0403 Jan 15, 2026
18d6a4c
pcphase op
paul0403 Jan 16, 2026
614c603
unitary op
paul0403 Jan 16, 2026
e28114c
left shift instead of std::pow(2, N)
paul0403 Jan 16, 2026
3c71fc7
format
paul0403 Jan 16, 2026
249b764
paulirot op
paul0403 Jan 16, 2026
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
1 change: 1 addition & 0 deletions mlir/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ add_subdirectory(Mitigation)
add_subdirectory(PauliFrame)
add_subdirectory(QEC)
add_subdirectory(Quantum)
add_subdirectory(RefQuantum)
add_subdirectory(RTIO)
add_subdirectory(Test)
1 change: 1 addition & 0 deletions mlir/include/Quantum/IR/QuantumAttrDefs.td
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ def NamedObservable : I32EnumAttr<"NamedObservable",

def NamedObservableAttr : EnumAttr<QuantumDialect, NamedObservable, "named_observable">;

def PauliWord : TypedArrayAttrBase<StrAttr, "A product of Pauli operators, aka a Pauli word.">;

#endif // QUANTUM_ATTR_DEFS
2 changes: 0 additions & 2 deletions mlir/include/Quantum/IR/QuantumOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,6 @@ def CustomOp : UnitaryGate_Op<"custom", [DifferentiableGate, NoMemoryEffect,
let hasVerifier = 1;
}

def PauliWord : TypedArrayAttrBase<StrAttr, "A product of Pauli operators, aka a Pauli word.">;

def PauliRotOp : UnitaryGate_Op<"paulirot", [DifferentiableGate, NoMemoryEffect,
AttrSizedOperandSegments, AttrSizedResultSegments]> {
let summary = "Apply a Pauli Product Rotation";
Expand Down
2 changes: 2 additions & 0 deletions mlir/include/RefQuantum/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(IR)
add_subdirectory(Transforms)
9 changes: 9 additions & 0 deletions mlir/include/RefQuantum/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_mlir_dialect(RefQuantumOps ref_quantum)
add_mlir_interface(RefQuantumInterfaces)
add_mlir_doc(RefQuantumDialect RefQuantumDialect RefQuantum/ -gen-dialect-doc -gen-op-doc)
add_mlir_doc(RefQuantumOps RefQuantumOps RefQuantum/ -gen-op-doc)
add_mlir_doc(RefQuantumInterfaces RefQuantumInterfaces RefQuantum/ -gen-op-interface-docs)

set(LLVM_TARGET_DEFINITIONS RefQuantumOps.td)
mlir_tablegen(RefQuantumAttributes.h.inc -gen-attrdef-decls -attrdefs-dialect=ref_quantum)
mlir_tablegen(RefQuantumAttributes.cpp.inc -gen-attrdef-defs -attrdefs-dialect=ref_quantum)
23 changes: 23 additions & 0 deletions mlir/include/RefQuantum/IR/RefQuantumDialect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2025 Xanadu Quantum Technologies Inc.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "mlir/IR/Dialect.h"

//===----------------------------------------------------------------------===//
// RefQuantum dialect declarations.
//===----------------------------------------------------------------------===//

#include "RefQuantum/IR/RefQuantumOpsDialect.h.inc"
57 changes: 57 additions & 0 deletions mlir/include/RefQuantum/IR/RefQuantumDialect.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2025 Xanadu Quantum Technologies Inc.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef REF_QUANTUM_DIALECT
#define REF_QUANTUM_DIALECT

include "mlir/IR/DialectBase.td"
include "mlir/IR/OpBase.td"
include "mlir/IR/AttrTypeBase.td"
include "mlir/Interfaces/SideEffectInterfaces.td"

//===----------------------------------------------------------------------===//
// RefQuantum dialect definition.
//===----------------------------------------------------------------------===//

def RefQuantumDialect : Dialect {
let summary = "Reference semantics quantum dialect.";
let description = [{
A supplemental dialect to the core quantum dialect.

Quantum operations in this dialect follow reference semantics (as opposed to qubit value
semantics in the core quantum dialect): the targets of quantum operations in this dialect
are all integer wire indices.
}];

/// This is the namespace of the dialect in MLIR, which is used as a prefix for types and ops.
let name = "ref_quantum";

/// This is the C++ namespace in which the dialect and all of its sub-components are placed.
let cppNamespace = "::catalyst::ref_quantum";

let dependentDialects = [
"quantum::QuantumDialect"
];
}


//===----------------------------------------------------------------------===//
// RefQuantum dialect base operation.
//===----------------------------------------------------------------------===//

class RefQuantum_Op<string mnemonic, list<Trait> traits = []> :
Op<RefQuantumDialect, mnemonic, traits>;


#endif // REF_QUANTUM_DIALECT
25 changes: 25 additions & 0 deletions mlir/include/RefQuantum/IR/RefQuantumInterfaces.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2025 Xanadu Quantum Technologies Inc.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <vector>

#include "mlir/IR/OpDefinition.h"

//===----------------------------------------------------------------------===//
// RefQuantum interface declarations.
//===----------------------------------------------------------------------===//

#include "RefQuantum/IR/RefQuantumInterfaces.h.inc"
136 changes: 136 additions & 0 deletions mlir/include/RefQuantum/IR/RefQuantumInterfaces.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// Copyright 2025 Xanadu Quantum Technologies Inc.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef REFQUANTUM_INTERFACES
#define REFQUANTUM_INTERFACES

include "mlir/IR/OpBase.td"

def QuantumOperation : OpInterface<"QuantumOperation"> {
let description = [{
A base class for all quantum operations that can be considered actions on wires.
The actions do not have to be unitary. For example, the SetState operations also falls
under this class.
}];

let cppNamespace = "::catalyst::ref_quantum";

let methods = [
InterfaceMethod<
"Return all operands which are considered input wires (including controls).",
"std::vector<mlir::Value>", "getWireOperands"
>,
InterfaceMethod<
"Set all operands which are considered input wires (including controls).",
"void", "setWireOperands", (ins "mlir::ValueRange":$replacements)
>
];
}

def QuantumGate : OpInterface<"QuantumGate", [QuantumOperation]> {
let description = [{
A base class for all unitary quantum operations.
These operations can be inverted and controlled.
}];

let cppNamespace = "::catalyst::ref_quantum";

let methods = [
InterfaceMethod<
"Return operands which are considered non-controlled input wire values.",
"mlir::ValueRange", "getNonCtrlWireOperands"
>,
InterfaceMethod<
"Set all operands which are considered non-controlled input wire values.",
"void", "setNonCtrlWireOperands", (ins "mlir::ValueRange":$replacements)
>,
InterfaceMethod<
"Return all operands which are considered controlling input wire values.",
"mlir::ValueRange", "getCtrlWireOperands"
>,
InterfaceMethod<
"Set all operands which are considered controlling input wire values.",
"void", "setCtrlWireOperands", (ins "mlir::ValueRange":$replacements)
>,
InterfaceMethod<
"Return all operands which are considered controlling input boolean values.",
"mlir::ValueRange", "getCtrlValueOperands"
>,
InterfaceMethod<
"Set all operands which are considered controlling input boolean values.",
"void", "setCtrlValueOperands", (ins "mlir::ValueRange":$replacements)
>,
InterfaceMethod<
"Return adjoint flag.",
"bool", "getAdjointFlag"
>,
InterfaceMethod<
"Set adjoint flag.",
"void", "setAdjointFlag", (ins "bool":$adjoint)
>
];

let verify = [{
auto gate = mlir::cast<ConcreteOp>($_op);

if (gate.getCtrlValueOperands().size() != gate.getCtrlWireOperands().size()) {
return $_op->emitError() <<
"number of controlling wires in input (" <<
gate.getCtrlWireOperands().size() << ") " <<
"and controlling values (" <<
gate.getCtrlValueOperands().size() <<
") must be the same";
}

// STL methods to check duplicates will all complain about `mlir::Value` not having a
// comparison method defined, since they all use map/set, which is hash-based
// So we just do it manually
std::vector<mlir::Value> wireOperands = gate.getWireOperands();
for (size_t i=0; i < wireOperands.size(); i++) {
for (size_t j=i+1; j < wireOperands.size(); j++) {
if (wireOperands[i] == wireOperands[j]) {
return $_op->emitError() << "all wires on a quantum gate must be " <<
"distinct (including controls)";
}
}
}

return mlir::success();
}];
}

def ParametrizedGate : OpInterface<"ParametrizedGate", [QuantumGate]> {
let description = [{
This interface provides a generic way to interact with parametrized
quantum instructions. These are quantum operations with arbitrary
classical gate parameters.
}];

let cppNamespace = "::catalyst::ref_quantum";

let methods = [
InterfaceMethod<
"Return all operands which are considered gate parameters.",
"mlir::ValueRange", "getAllParams"
>,
InterfaceMethod<
"Return the param operand at the requested index.",
"mlir::Value", "getParam", (ins "size_t":$idx), /*methodBody=*/[{}],
/*defaultImplementation=*/[{ return mlir::cast<ConcreteOp>($_op).getAllParams()[idx]; }]
>,
];
}


#endif // REFQUANTUM_INTERFACES
36 changes: 36 additions & 0 deletions mlir/include/RefQuantum/IR/RefQuantumOps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2025 Xanadu Quantum Technologies Inc.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <optional>

#include "llvm/ADT/StringRef.h"

#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Support/LogicalResult.h"

#include "Quantum/IR/QuantumDialect.h"
#include "RefQuantum/IR/RefQuantumDialect.h"
#include "RefQuantum/IR/RefQuantumInterfaces.h"

//===----------------------------------------------------------------------===//
// RefQuantum ops declarations.
//===----------------------------------------------------------------------===//

#define GET_OP_CLASSES
#include "RefQuantum/IR/RefQuantumOps.h.inc"
Loading