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

Pulse python bindings squash #276

Merged
merged 20 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})
include(TableGen)
include(AddLLVM)
include(AddMLIR)
include(AddMLIRPython)
include(HandleLLVMOptions)
include(LLVMExports)

Expand Down
2 changes: 1 addition & 1 deletion conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ requirements:
- zlib/1.2.13
- zstd/1.5.5
- nlohmann_json/3.9.1
- pybind11/2.10.1
- pybind11/2.11.1
- clang-tools-extra/17.0.5-0@
- llvm/17.0.5-0@
- qasm/0.3.0@qss/stable
6 changes: 3 additions & 3 deletions include/Dialect/Pulse/IR/PulseDialect.td
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//===- PulseDialect.td - Pulse dialect ---------------------*- tablegen -*-===//
//
// (C) Copyright IBM 2023.
// (C) Copyright IBM 2023, 2024.
//
// This code is part of Qiskit.
//
Expand Down Expand Up @@ -57,7 +57,7 @@ class Pulse_Attr<string name, string attrMnemonic, list<Trait> traits = []>
let mnemonic = attrMnemonic;
}

include "PulseTypes.td"
include "PulseOps.td"
include "Dialect/Pulse/IR/PulseTypes.td"
include "Dialect/Pulse/IR/PulseOps.td"

#endif // PULSE_DIALECT
4 changes: 2 additions & 2 deletions include/Dialect/Pulse/IR/PulseOps.td
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//===- PulseOps.td - Pulse dialect ops ---------------------*- tablegen -*-===//
//
// (C) Copyright IBM 2023.
// (C) Copyright IBM 2023, 2024.
//
// This code is part of Qiskit.
//
Expand All @@ -17,7 +17,7 @@
#ifndef PULSE_OPS
#define PULSE_OPS

include "PulseTraits.td"
include "Dialect/Pulse/IR/PulseTraits.td"

include "Dialect/QUIR/IR/QUIRTypeConstraints.td"
include "Dialect/Pulse/IR/PulseInterfaces.td"
Expand Down
9 changes: 8 additions & 1 deletion include/Dialect/QUIR/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) Copyright IBM 2023.
# (C) Copyright IBM 2023, 2024.
#
# This code is part of Qiskit.
#
Expand All @@ -16,9 +16,16 @@ add_mlir_doc(QUIR QUIRDialect generated/Dialect/QUIR/ -gen-dialect-doc -dialect=
set(LLVM_TARGET_DEFINITIONS QUIR.td)
mlir_tablegen(QUIRAttributes.h.inc -gen-attrdef-decls -attrdefs-dialect=quir)
mlir_tablegen(QUIRAttributes.cpp.inc -gen-attrdef-defs -attrdefs-dialect=quir)
add_public_tablegen_target(QUIRAttributesIncGen)

set(LLVM_TARGET_DEFINITIONS QUIR.td)
mlir_tablegen(QUIREnums.h.inc -gen-enum-decls)
mlir_tablegen(QUIREnums.cpp.inc -gen-enum-defs)
add_public_tablegen_target(QUIREnumsIncGen)

# This dependency makes sure that the attributes and enums include files are
# generated before anything that requires the include files generated for the
# QUIR dialect
add_dependencies(MLIRQUIRIncGen QUIREnumsIncGen QUIRAttributesIncGen)

add_mlir_interface(QUIRInterfaces)
36 changes: 36 additions & 0 deletions include/qss-c/Dialect/OQ3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===- OQ3.h - OQ3 Dialect for C --------------------------------*- C++ -*-===//
//
// (C) Copyright IBM 2024.
//
// This code is part of Qiskit.
//
// This code is licensed under the Apache License, Version 2.0 with LLVM
// Exceptions. You may obtain a copy of this license in the LICENSE.txt
// file in the root directory of this source tree.
//
// Any modifications or derivative works of this code must retain this
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.
//
//===----------------------------------------------------------------------===//
///
/// This file declares the c interface for the OQ3 dialect
///
//===----------------------------------------------------------------------===//
#ifndef C_DIALECT_OQ3_H
#define C_DIALECT_OQ3_H

#include "mlir-c/IR.h"
#include "mlir-c/Support.h"

#ifdef __cplusplus
extern "C" {
#endif

MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(OQ3, oq3);

#ifdef __cplusplus
}
#endif

#endif // C_DIALECT_OQ3_H
85 changes: 85 additions & 0 deletions include/qss-c/Dialect/Pulse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//===- Pulse.h - Pulse Dialect for C ----------------------------*- C++ -*-===//
//
// (C) Copyright IBM 2024.
//
// This code is part of Qiskit.
//
// This code is licensed under the Apache License, Version 2.0 with LLVM
// Exceptions. You may obtain a copy of this license in the LICENSE.txt
// file in the root directory of this source tree.
//
// Any modifications or derivative works of this code must retain this
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.
//
//===----------------------------------------------------------------------===//
///
/// This file declares the c interface for the Pulse dialect
///
//===----------------------------------------------------------------------===//

#ifndef C_DIALECT_PULSE_H
#define C_DIALECT_PULSE_H

#include "mlir-c/IR.h"
#include "mlir-c/Support.h"

#ifdef __cplusplus
extern "C" {
#endif

MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(PULSE, pulse);

//===---------------------------------------------------------------------===//
// CaptureType
//===---------------------------------------------------------------------===//

MLIR_CAPI_EXPORTED bool pulseTypeIsACaptureType(MlirType type);

MLIR_CAPI_EXPORTED MlirType pulseCaptureTypeGet(MlirContext ctx);

//===---------------------------------------------------------------------===//
// FrameType
//===---------------------------------------------------------------------===//

MLIR_CAPI_EXPORTED bool pulseTypeIsAFrameType(MlirType type);

MLIR_CAPI_EXPORTED MlirType pulseFrameTypeGet(MlirContext ctx);

//===---------------------------------------------------------------------===//
// KernelType
//===---------------------------------------------------------------------===//

MLIR_CAPI_EXPORTED bool pulseTypeIsAKernelType(MlirType type);

MLIR_CAPI_EXPORTED MlirType pulseKernelTypeGet(MlirContext ctx);

//===---------------------------------------------------------------------===//
// MixedFrameType
//===---------------------------------------------------------------------===//

MLIR_CAPI_EXPORTED bool pulseTypeIsAMixedFrameType(MlirType type);

MLIR_CAPI_EXPORTED MlirType pulseMixedFrameTypeGet(MlirContext ctx);

//===---------------------------------------------------------------------===//
// PortType
//===---------------------------------------------------------------------===//

MLIR_CAPI_EXPORTED bool pulseTypeIsAPortType(MlirType type);

MLIR_CAPI_EXPORTED MlirType pulsePortTypeGet(MlirContext ctx);

//===---------------------------------------------------------------------===//
// WaveformType
//===---------------------------------------------------------------------===//

MLIR_CAPI_EXPORTED bool pulseTypeIsAWaveformType(MlirType type);

MLIR_CAPI_EXPORTED MlirType pulseWaveformTypeGet(MlirContext ctx);

#ifdef __cplusplus
}
#endif

#endif // C_DIALECT_PULSE_H
37 changes: 37 additions & 0 deletions include/qss-c/Dialect/QCS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===- QCS.h - QCS Dialect for C --------------------------------*- C++ -*-===//
//
// (C) Copyright IBM 2024.
//
// This code is part of Qiskit.
//
// This code is licensed under the Apache License, Version 2.0 with LLVM
// Exceptions. You may obtain a copy of this license in the LICENSE.txt
// file in the root directory of this source tree.
//
// Any modifications or derivative works of this code must retain this
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.
//
//===----------------------------------------------------------------------===//
///
/// This file declares the c interface for the QCS dialect
///
//===----------------------------------------------------------------------===//

#ifndef C_DIALECT_QCS_H
#define C_DIALECT_QCS_H

#include "mlir-c/IR.h"
#include "mlir-c/Support.h"

#ifdef __cplusplus
extern "C" {
#endif

MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(QCS, qcs);

#ifdef __cplusplus
}
#endif

#endif // C_DIALECT_QCS_H
53 changes: 53 additions & 0 deletions include/qss-c/Dialect/QUIR.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===- QUIR.h - QUIR Dialect for C ------------------------------*- C++ -*-===//
//
// (C) Copyright IBM 2024.
//
// This code is part of Qiskit.
//
// This code is licensed under the Apache License, Version 2.0 with LLVM
// Exceptions. You may obtain a copy of this license in the LICENSE.txt
// file in the root directory of this source tree.
//
// Any modifications or derivative works of this code must retain this
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.
//
//===----------------------------------------------------------------------===//
///
/// This file declares the c interface for the QUIR dialect
///
//===----------------------------------------------------------------------===//

#ifndef C_DIALECT_QUIR_H
#define C_DIALECT_QUIR_H

#include "mlir-c/IR.h"
#include "mlir-c/Support.h"

#ifdef __cplusplus
extern "C" {
#endif

MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(QUIR, quir);

//===---------------------------------------------------------------------===//
// AngleType
//===---------------------------------------------------------------------===//

MLIR_CAPI_EXPORTED bool quirTypeIsAAngleType(MlirType type);

MLIR_CAPI_EXPORTED MlirType quirAngleTypeGet(MlirContext ctx, unsigned width);

//===---------------------------------------------------------------------===//
// DurationType
//===---------------------------------------------------------------------===//

MLIR_CAPI_EXPORTED bool quirTypeIsADurationType(MlirType type);

MLIR_CAPI_EXPORTED MlirType quirDurationTypeGet(MlirContext ctx);

#ifdef __cplusplus
}
#endif

#endif // C_DIALECT_QUIR_H
59 changes: 59 additions & 0 deletions lib/Bindings/Python/DialectOQ3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//===- DialectOQ3.cpp - OQ3 Dialect python bindings -------------*- C++ -*-===//
//
// (C) Copyright IBM 2024.
//
// This code is part of Qiskit.
//
// This code is licensed under the Apache License, Version 2.0 with LLVM
// Exceptions. You may obtain a copy of this license in the LICENSE.txt
// file in the root directory of this source tree.
//
// Any modifications or derivative works of this code must retain this
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.
//
//===----------------------------------------------------------------------===//
///
/// This file implements the python bindings for the OQ3 dialect
///
//===----------------------------------------------------------------------===//

#include "qss-c/Dialect/OQ3.h"

#include "mlir-c/IR.h"
// NOLINTNEXTLINE(misc-include-cleaner)
#include "mlir/Bindings/Python/PybindAdaptors.h"

#include "pybind11/cast.h"
#include "pybind11/detail/common.h"
#include "pybind11/pybind11.h"
#include "pybind11/pytypes.h"

namespace py = pybind11;
using namespace llvm;
using namespace mlir;
using namespace mlir::python;
using namespace mlir::python::adaptors;

// Intentionally left blank placeholder and for a common pattern across dialects
void populateDialectOQ3Submodule(const pybind11::module &m) {}
mbhealy marked this conversation as resolved.
Show resolved Hide resolved

PYBIND11_MODULE(_qeDialectsOQ3, m) {
m.doc() = "IBM Quantum OQ3 dialect.";
populateDialectOQ3Submodule(m);

//===--------------------------------------------------------------------===//
// OQ3 dialect
//===--------------------------------------------------------------------===//
auto quir_m = m.def_submodule("oq3");

quir_m.def(
"register_dialect",
[](MlirContext context, bool load) {
const MlirDialectHandle handle = mlirGetDialectHandle__oq3__();
mlirDialectHandleRegisterDialect(handle, context);
if (load)
mlirDialectHandleLoadDialect(handle, context);
},
py::arg("context") = py::none(), py::arg("load") = true);
}
Loading
Loading