Skip to content

Commit

Permalink
everything but IsolatedFromAbove working
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Lou authored and Joshua Lou committed Jul 31, 2023
1 parent aa59038 commit d9b0f86
Show file tree
Hide file tree
Showing 11 changed files with 917 additions and 140 deletions.
4 changes: 2 additions & 2 deletions include/Dialect/Pulse/IR/PulseOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ include "Dialect/Pulse/IR/PulseInterfaces.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/CallInterfaces.td"
include "mlir/Interfaces/ControlFlowInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
// include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/IR/BuiltinTypes.td"
include "mlir/IR/FunctionInterfaces.td"
include "mlir/IR/OpAsmInterface.td"
Expand Down Expand Up @@ -596,7 +596,7 @@ def Pulse_MixOp : Pulse_Op<"mix", [SequenceAllowed]> {
}


def Pulse_SumOp : Pulse_Op<"sum", [SameOperandsAndResultType, SequenceAllowed]> {
def Pulse_SumOp : Pulse_Op<"sum", [SequenceAllowed]> {
let summary = "Add pulse waveforms sample by sample. The waveforms must be the same length.";
let description = [{
The `pulse.sum` operation adds two waveforms together, ie `s(t_i) = s1(t_i)+s2(t_i)` for
Expand Down
7 changes: 3 additions & 4 deletions python_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ add_subdirectory(qss_compiler)
add_custom_target(copy_python_files DEPENDS ${PY_LIB_FILES})
add_dependencies(py_qssc copy_python_files)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include/Dialect/Pulse/IR)
# link to where _mlir_libs is
link_directories(~/llvm-project/build/tools/mlir/python_packages/mlir_core/mlir/_mlir_libs)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include/Dialect/Pulse/IR/)
link_directories(/Users/joshualou/llvm-project/build/tools/mlir/python_packages/mlir_core/mlir/_mlir_libs)

declare_mlir_python_sources(QSSPythonSources)
declare_mlir_python_sources(QSSPythonSources.Dialects
Expand Down Expand Up @@ -178,4 +177,4 @@ add_mlir_python_modules(QSSPythonModules
QSSPythonSources
COMMON_CAPI_LINK_LIBS
MLIRPythonCAPI
)
)
2 changes: 1 addition & 1 deletion python_lib/qss_compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set(SOURCES

pybind11_add_module(py_qssc SHARED ${SOURCES})

target_link_libraries(py_qssc PRIVATE QSSCLib)
#target_link_libraries(py_qssc PRIVATE QSSCLib)

# collect python package files from this directory
# into a variable PY_QSSC_FILES
Expand Down
44 changes: 21 additions & 23 deletions python_lib/qss_compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,26 @@
from ._version import version as __version__ # noqa: F401
from .py_qssc import __doc__ # noqa: F401

from .compile import ( # noqa: F401
compile_file,
compile_file_async,
compile_str,
compile_str_async,
InputType,
OutputType,
CompileOptions,
)
# from .compile import ( # noqa: F401
# compile_file,
# compile_file_async,
# compile_str,
# compile_str_async,
# InputType,
# OutputType,
# CompileOptions,
# QSSCompilationFailure,
# QSSCompilerError,
# )

from .exceptions import ( # noqa: F401
QSSCompilationFailure,
QSSCompilerError,
)
# from .py_qssc import ( # noqa: F401
# Diagnostic,
# ErrorCategory,
# Severity,
# )

from .py_qssc import ( # noqa: F401
Diagnostic,
ErrorCategory,
Severity,
)

from .link import ( # noqa: F401
link_file,
LinkOptions,
)
# from .link import ( # noqa: F401
# link_file,
# LinkOptions,
# QSSLinkingFailure,
# )
530 changes: 530 additions & 0 deletions python_lib/qss_compiler/examples/Pulse Bindings Demo.ipynb

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions python_lib/qss_compiler/examples/parse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python
# coding: utf-8

# Using this notebook requires manual install of MLIR python bindings:
# 1. Copy or link to `qss-compiler/third_party/mlir/pyproject.toml` from `~/.conan/data/llvm/qss/stable/<hash>/python_packages/mlir_core`
# 2. Run `pip install -e .`
# 3. Copy or link to `~/.conan/data/llvm/qss/stable/<hash>/python_packages/mlir_core/mlir/_mlir_libs/libMLIRPythonCAPI.dylib` from `<python>/lib`
# 4. build compiler
# 5. cd `qss_compiler/python_lib`
# 6. run `bash setup_mlir.sh`
# 7. run `pip install -e .`

# In[1]:


from mlir.ir import Context, InsertionPoint, Location, Module
from mlir.ir import F64Type, IntegerType, IndexType
from mlir.dialects import arith, builtin, std, scf


# In[2]:


from qss_compiler.mlir.dialects import pulse, quir, complex # noqa: F401, E402


# In[4]:


import numpy as np
import sys


# In[5]:



with Context() as ctx:

pulse.pulse.register_dialect()
quir.quir.register_dialect()

with open(sys.argv[1]) as f:
data = f.read()
print(data)
module = Module.parse(data)



print(str(module))


103 changes: 103 additions & 0 deletions python_lib/qss_compiler/examples/pulse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env python
# coding: utf-8

# Using this notebook requires manual install of MLIR python bindings:
# 1. Copy or link to `qss-compiler/third_party/mlir/pyproject.toml` from `~/.conan/data/llvm/qss/stable/<hash>/python_packages/mlir_core`
# 2. Run `pip install -e .`
# 3. Copy or link to `~/.conan/data/llvm/qss/stable/<hash>/python_packages/mlir_core/mlir/_mlir_libs/libMLIRPythonCAPI.dylib` from `<python>/lib`
# 4. build compiler
# 5. cd `qss_compiler/python_lib`
# 6. run `bash setup_mlir.sh`
# 7. run `pip install -e .`

from mlir.ir import Context, InsertionPoint, Location, Module
from mlir.ir import F64Type, IntegerType, IndexType
from mlir.dialects import arith, builtin, std, scf

from qss_compiler.mlir.dialects import pulse, quir, complex # noqa: F401, E402

import numpy as np


num_samples = 3
samples = np.arange(0,num_samples) + np.arange(0+1,num_samples+1) * 1j
samples_2d = np.zeros((samples.shape[0],2))
samples_2d[:,0] = np.real(samples)
samples_2d[:,1] = np.imag(samples)


with Context() as ctx:

pulse.pulse.register_dialect()
quir.quir.register_dialect()

f64 = F64Type.get(ctx)
i32 = IntegerType.get_signless(32)
i1 = IntegerType.get_signless(1)

idx = IndexType.get()

mf = pulse.MixedFrameType.get(ctx)
wf = pulse.WaveformType.get(ctx)

with Location.unknown(ctx) as loc:
module = Module.create(loc)

with InsertionPoint(module.body):
func = builtin.FuncOp("main", ([], [i32]))
func.add_entry_block()

with InsertionPoint(module.body):

seq1 = pulse.SequenceOp("seq_1",[wf, wf, mf, mf],[i1])
seq1.add_entry_block()

# with InsertionPoint(seq1.entry_block):
# gs, dg, mf1, mf2 = seq1.arguments
# c0 = arith.ConstantOp(i32, 656)
# pulse.DelayOp(mf1, c0)
# pulse.PlayOp(mf1, dg, 1.4, 5.25, 1.0)
# zero = arith.ConstantOp(i1, 0)
# ret = pulse.ReturnOp(zero)


with InsertionPoint(func.entry_block):
# quir.SystemInitOp()

c0 = arith.ConstantOp(f64, 0.0)
c1_r = arith.ConstantOp(f64, 0.0)
c1_i = arith.ConstantOp(f64, 0.0)
c1_c = complex.CreateOp(c1_r, c1_i)

# ph0 = quir.ConstantOp("angle", 0.0)
p0 = pulse.Port_CreateOp("Q0")

# fM0 = pulse.Frame_CreateOp(c1_c, c0, ph0)
# mfM0 = pulse.MixFrameOp("drive" ,p0, fM0)

# fMTRIGOUT = pulse.Frame_CreateOp(c1_c, c0, ph0)
# mfMTRIGOUT = pulse.MixFrameOp("measure", p0, fMTRIGOUT)

# c2 = arith.ConstantOp(idx, 0)
# c3 = arith.ConstantOp(idx, 1000)
# c4 = arith.ConstantOp(idx, 1)

# loop = quir.ShotLoop(c2,c3,c4)

# with InsertionPoint(loop.body):
# dur = quir.ConstantOp("duration","150us")
# quir.DelayOp(dur)
# si = quir.ShotInitOp(1000, False)
# gaussian_square_ice0 = pulse.Waveform_CreateOp(samples_2d)
# drag0 = pulse.Waveform_CreateOp(2* samples_2d)

# res0 = pulse.CallSequenceOp([i1], "seq_1", [drag0, gaussian_square_ice0, mfM0, mfMTRIGOUT ])
# scf.YieldOp(loop.inner_iter_args)

# quir.SystemFinalizeOp()
zero = arith.ConstantOp(i32, 0)
std.ReturnOp(zero)

print(str(module))


92 changes: 92 additions & 0 deletions python_lib/qss_compiler/examples/test_out.mlir

Large diffs are not rendered by default.

Loading

0 comments on commit d9b0f86

Please sign in to comment.