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

[WIP] Create a runtime OQD device that generates openapl #1479

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
57 changes: 57 additions & 0 deletions frontend/catalyst/third_party/oqd/example/6_llvm_ir.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
; ModuleID = 'LLVMDialectModule'
source_filename = "LLVMDialectModule"

@"{'shots': 1000}" = internal constant [16 x i8] c"{'shots': 1000}\00"
@oqd = internal constant [4 x i8] c"oqd\00"
@"/home/paul.wang/catalyst_new/catalyst/frontend/catalyst/utils/../../catalyst/third_party/oqd/src/build/librtd_oqd.so" = internal constant [117 x i8] c"/home/paul.wang/catalyst_new/catalyst/frontend/catalyst/utils/../../catalyst/third_party/oqd/src/build/librtd_oqd.so\00"

declare void @__catalyst__oqd__greetings()

declare void @__catalyst__rt__finalize()

declare void @__catalyst__rt__initialize(ptr)

declare void @__catalyst__rt__device_release()

declare void @__catalyst__rt__device_init(ptr, ptr, ptr, i64)

define void @jit_f() {
call void @f_0()
ret void
}

define void @_catalyst_pyface_jit_f(ptr %0, ptr %1) {
call void @_catalyst_ciface_jit_f(ptr %0)
ret void
}

define void @_catalyst_ciface_jit_f(ptr %0) {
call void @jit_f()
ret void
}

define void @f_0() {
call void @__catalyst__rt__device_init(ptr @"/home/paul.wang/catalyst_new/catalyst/frontend/catalyst/utils/../../catalyst/third_party/oqd/src/build/librtd_oqd.so", ptr @oqd, ptr @"{'shots': 1000}", i64 1000)
call void @__catalyst__oqd__greetings()
call void @__catalyst__rt__device_release()
ret void
}

define void @setup() {
call void @__catalyst__rt__initialize(ptr null)
ret void
}

define void @teardown() {
call void @__catalyst__rt__finalize()
ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!llvm.module.flags = !{!0}

!0 = !{i32 2, !"Debug Info Version", i32 3}
21 changes: 21 additions & 0 deletions frontend/catalyst/third_party/oqd/example/oqd_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pennylane as qml

Check notice on line 1 in frontend/catalyst/third_party/oqd/example/oqd_run.py

View check run for this annotation

codefactor.io / CodeFactor

frontend/catalyst/third_party/oqd/example/oqd_run.py#L1

Missing module docstring (missing-module-docstring)
import pytest

Check notice on line 2 in frontend/catalyst/third_party/oqd/example/oqd_run.py

View check run for this annotation

codefactor.io / CodeFactor

frontend/catalyst/third_party/oqd/example/oqd_run.py#L2

Unused import pytest (unused-import)

import catalyst

Check notice on line 4 in frontend/catalyst/third_party/oqd/example/oqd_run.py

View check run for this annotation

codefactor.io / CodeFactor

frontend/catalyst/third_party/oqd/example/oqd_run.py#L4

Unused import catalyst (unused-import)
from catalyst import qjit
from catalyst.third_party.oqd import OQDDevice
from catalyst.debug import get_compilation_stage, replace_ir

Check notice on line 7 in frontend/catalyst/third_party/oqd/example/oqd_run.py

View check run for this annotation

codefactor.io / CodeFactor

frontend/catalyst/third_party/oqd/example/oqd_run.py#L7

Unused get_compilation_stage imported from catalyst.debug (unused-import)

dev = OQDDevice(backend="default", shots=1000, wires=8)

@qjit#(keep_intermediate=True)
@qml.qnode(dev)
def f():

Check notice on line 13 in frontend/catalyst/third_party/oqd/example/oqd_run.py

View check run for this annotation

codefactor.io / CodeFactor

frontend/catalyst/third_party/oqd/example/oqd_run.py#L13

Missing function or method docstring (missing-function-docstring)
qml.Hadamard(wires=0)
return qml.probs()

with open("6_llvm_ir.ll", "r") as file:

Check notice on line 17 in frontend/catalyst/third_party/oqd/example/oqd_run.py

View check run for this annotation

codefactor.io / CodeFactor

frontend/catalyst/third_party/oqd/example/oqd_run.py#L17

Using open without explicitly specifying an encoding (unspecified-encoding)
ir = file.read()
replace_ir(f, "llvm_ir", ir)

f()
2 changes: 1 addition & 1 deletion runtime/lib/capi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Object Lib catalyst_qir_qis_obj
##################################

add_library(catalyst_qir_qis_obj OBJECT RuntimeCAPI.cpp)
add_library(catalyst_qir_qis_obj OBJECT RuntimeCAPI.cpp OQDRuntimeCAPI.cpp)

# include external MLIR runner utils
FetchContent_MakeAvailable(MLIRRunnerUtils)
Expand Down
24 changes: 24 additions & 0 deletions runtime/lib/capi/OQDRuntimeCAPI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2025 Xanadu Quantum Technologies Inc.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

changelog


// 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.

#include <iostream>

extern "C" {

void __catalyst__oqd__greetings() {
std::cout << "Hello OQD world!" << std::endl;
}


}
Loading