Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7f451e6
Initial commit.
m-meller Apr 30, 2026
f54a930
[WIP]: implemented communication of device control params for verbosi…
m-meller May 1, 2026
8331eb1
[WIP]: Implemented sending of device control parameters back to the h…
m-meller May 5, 2026
df2b074
WIP: Modifying the design of the comms.
m-meller May 6, 2026
26b594b
[WIP]: Implemented cq initialise and finalise under new MPI comms des…
m-meller May 7, 2026
c2f68d0
Implemented allocation and deallocation operations.
m-meller May 7, 2026
8174b87
[WIP]: Implementing executors.
m-meller May 7, 2026
3cba275
Executors and synchronisation work... Now need to implement kernel re…
m-meller May 7, 2026
002526e
Implemented executors with MPI communication.
m-meller May 8, 2026
d359dcf
Cleaned up and restructured code.
m-meller May 11, 2026
fea761e
Added executor halting and sync. Resolved memory leak when handling e…
m-meller May 11, 2026
5a1137b
Fixed memory leak.
m-meller May 12, 2026
896c95c
Finalised ring buffer on device side which handles the queuing execut…
m-meller May 13, 2026
2ea381f
[WIP]: started work on handling MPI on quantum workers. This commit c…
m-meller May 13, 2026
ba3b190
Updated build options for conditional compilation.
m-meller May 13, 2026
11d2c43
[WIP]: seems that the most issues are resolved and now I need to impl…
m-meller May 14, 2026
03f88ce
Implemented full MPI-based CQ
m-meller May 14, 2026
e6dd7fe
Restructured project and created comms module.
m-meller May 15, 2026
a3f078f
Removed old files.
m-meller May 15, 2026
ed240b1
Cleaned up code, added extra process validation when built with MPI.
m-meller May 18, 2026
bc0de31
Removed unused files. Modified conditional compilation for the debug …
m-meller May 18, 2026
646e0f0
Removed unused file.
m-meller May 19, 2026
b4f7ec9
Removed some comments, modified functions signature to use const more…
m-meller May 22, 2026
34b635b
Added support for sending params with executor.
m-meller May 22, 2026
e135f29
Added extra input validation in comms.
m-meller Jun 17, 2026
5b7484f
Removed commented out code. Added logic for handling parameterised qu…
m-meller Jun 30, 2026
7e9ccd5
Added macros for wrapping up code when running MPI built. Updated exa…
m-meller Jul 13, 2026
63e0309
Removed unused example.
m-meller Jul 13, 2026
c6abbca
Added new function to initialise CQ with user owned MPI. Updated MPI …
m-meller Jul 13, 2026
610ec59
Cleaned up code.
m-meller Jul 13, 2026
e970ff8
Updated MPI example.
m-meller Jul 13, 2026
884863b
Modified MPI comms to pass all tests.
m-meller Jul 13, 2026
9a39a06
Added fortran wrappers and interface to use new macros and user-owned…
m-meller Jul 14, 2026
a4e66e8
Fixed bug when initialising MPI.
m-meller Jul 14, 2026
51968f4
Updated code formating of vqe example.
m-meller Jul 14, 2026
bce8020
Added Fortran MPI example using CQ with subcommunicator.
m-meller Jul 14, 2026
763a8f6
Updated include to be compatible with upcoming QuEST v4.3.
m-meller Jul 21, 2026
121d77f
Updated Fortran targets properties to ensure builds with Ninja genera…
m-meller Jul 21, 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
build/*
.cache
.clang-format*
38 changes: 35 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ cmake_minimum_required(VERSION 3.21)
project(CQ-SIMBE
VERSION 0.1.0
DESCRIPTION "CQ compliant simulated backend."
LANGUAGES C
)
LANGUAGES C Fortran)

# User configure options

Expand Down Expand Up @@ -41,19 +40,48 @@ option(
OFF
)

option(
BUILD_WITH_MPI
"Build with MPI-based communication. Turned ON by default."
OFF
)
message(STATUS "BUILD_WITH_MPI turned ${BUILD_WITH_MPI}.")

option(
QUEST_BUILT_WITH_MPI
"Flag to define if QuEST was built with MPI. This will affect how we do the communication."
OFF
)
message(STATUS "QUEST_BUILT_WITH_MPI turned ${QUEST_BUILT_WITH_MPI}.")

# Dependencies

find_package(Threads REQUIRED)
find_package(QuEST 4.0 REQUIRED)
find_package(QuEST REQUIRED)

# CQ-SimBE Library

add_library(cq-simbe)
add_library(CQ-SIMBE::cq-simbe ALIAS cq-simbe)

if (BUILD_WITH_MPI)
find_package(MPI COMPONENTS Fortran C REQUIRED)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
target_compile_definitions(cq-simbe PUBLIC
CQ_WITH_MPI_COMMS=1
$<$<CONFIG:Debug>:DEBUG_MODE>
)
endif()

if (BUILD_WITH_MPI AND QUEST_BUILT_WITH_MPI)
target_compile_definitions(cq-simbe PRIVATE CQ_CONF_QUEST_WITH_MPI=1)
endif()


target_compile_features(cq-simbe PRIVATE c_std_99)
target_compile_options(cq-simbe PRIVATE -Wall)


target_include_directories(cq-simbe
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
Expand All @@ -64,6 +92,10 @@ target_include_directories(cq-simbe

target_link_libraries(cq-simbe PRIVATE Threads::Threads QuEST::QuEST)

if (BUILD_WITH_MPI)
target_link_libraries(cq-simbe PRIVATE ${MPI_C_LIBRARIES})
endif()

if (BUILD_FORTRAN_INTERFACE)
enable_language(Fortran)

Expand Down
32 changes: 30 additions & 2 deletions examples/fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ target_link_libraries(zero-qft
${MATHS_LIBRARY}
)

set_target_properties(zero-qft PROPERTIES Fortran_PREPROCESS ON)
set_target_properties(zero-qft
PROPERTIES
Fortran_PREPROCESS ON
Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mod/zero-qft"
)

add_executable(plus-qft
plus_qft.f90
Expand All @@ -24,4 +28,28 @@ target_link_libraries(plus-qft
${MATHS_LIBRARY}
)

set_target_properties(plus-qft PROPERTIES Fortran_PREPROCESS ON)
set_target_properties(plus-qft
PROPERTIES
Fortran_PREPROCESS ON
Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mod/plus-qft"
)

if (BUILD_WITH_MPI)
add_executable(mpi-plus-qft
mpi_plus_qft.f90
utils.f90
)

target_link_libraries(mpi-plus-qft
PRIVATE
CQ-SIMBE::cq-simbe
${MATHS_LIBRARY}
${MPI_Fortran_LIBRARIES}
)

set_target_properties(mpi-plus-qft
PROPERTIES
Fortran_PREPROCESS ON
Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mod/mpi-plus-qft"
)
endif()
129 changes: 129 additions & 0 deletions examples/fortran/mpi_plus_qft.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
program plus_qft
use mpi
use cq
#include "cqf.h"
use example_utils
implicit none

integer :: ireturn, freturn, alloc_status, free_status, reg_status, qrun_status, ierr
integer(kind=8) :: NQUBITS, NSHOTS, NMEASURE
type(qubit) :: qrc
integer(kind=2), allocatable, target :: cr(:)

integer :: id, nproc, split_cond, cq_comm

call MPI_Init(ierr)
call MPI_Comm_size(MPI_COMM_WORLD, nproc, ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, id, ierr)

if (id >= 3) then
split_cond = 1
else
split_cond = 0
end if

call MPI_Comm_split(MPI_COMM_WORLD, split_cond, id, cq_comm, ierr)

NQUBITS = 10
NSHOTS = 10
NMEASURE = NQUBITS

write(*,'(A)') 'before init'

if (split_cond == 1) then
ireturn = cq_init_custom_mpi_comm(cq_comm, 1)

write(*,'(A,I4)') 'cq_init returned: ',ireturn

reg_status = cq_register_qkern(plus_state_qft)

write(*,'(A,I4)') 'after register_qkern: ', reg_status

CQ_PROG_BEGIN()

alloc_status = cq_alloc_qureg(qrc, NQUBITS)

write(*,'(A,I4)') 'alloc_qureg returned: ', alloc_status

allocate(cr(NMEASURE * NSHOTS))

CALL cq_init_creg(NMEASURE * NSHOTS, -1, cr)

write(*,'(A)') 'after init_creg'

qrun_status = cq_sm_qrun(plus_state_qft, qrc, NQUBITS, cr, NMEASURE, NSHOTS)

write(*,'(A,I4)') 'after sm_qrun: ', qrun_status

CALL report_results(cr, NMEASURE, NSHOTS)

write(*,'(A)') 'after report results'

free_status = cq_free_qureg(qrc)

write(*,'(A,I4)') 'free_status returned: ', free_status

CQ_PROG_END()

freturn = cq_finalise(0)

write(*,'(A,I4)') 'cq_finalise returned: ',freturn

write(*,'(A)') 'after finalise'

end if

if (split_cond == 0) then
write(*,*) 'I am user-owned rank doing something unrelated to CQ'
end if

call MPI_Barrier(MPI_COMM_WORLD, ierr)
call MPI_Finalize(ierr)

contains

subroutine qft(NQUBITS, qr)
implicit none
integer(kind=8), value :: NQUBITS
type(qubit), value :: qr
integer(kind=8) :: i, j
integer :: status
real(8), parameter :: PI = 3.1415926535897932384626433832795028841971694
real(8) :: angle

do i = 0, NQUBITS - 1
status = cq_hadamard(qr, i)
do j = i + 1, NQUBITS - 1
angle = PI / (2.0 ** j)
status = cq_cphase(qr, j, i, angle)
end do
end do

do i = 0, (NQUBITS / 2) - 1
j = NQUBITS - (i + 1)
status = cq_swap(qr, i, j)
end do
end subroutine qft

function plus_state_qft(NQUBITS, qr, NMEASURE, cr, reg) bind(C) result(status)
implicit none
integer(kind=8), value :: NQUBITS
type(qubit), value :: qr
integer(kind=8), value :: NMEASURE
integer(kind=2), intent(inout) :: cr(0:NMEASURE)
type(qkern_map), value :: reg
integer(kind=8) :: i
integer :: status
integer(kind=8) :: STATE_IDX = 0
CQ_REGISTER_KERNEL("plus_state_qft", reg)
status = cq_set_qureg(qr, STATE_IDX, NQUBITS)

do i = 0, NQUBITS-1
status = cq_hadamard(qr, i)
end do

call qft(NQUBITS, qr)
status = cq_measure_qureg(qr, NQUBITS, cr)
end function plus_state_qft

end program
12 changes: 8 additions & 4 deletions examples/fortran/plus_qft.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ program plus_qft

write(*,'(A,I4)') 'cq_init returned: ',ireturn

reg_status = cq_register_qkern(plus_state_qft)

write(*,'(A,I4)') 'after register_qkern: ', reg_status

CQ_PROG_BEGIN()

alloc_status = cq_alloc_qureg(qrc, NQUBITS)

write(*,'(A,I4)') 'alloc_qureg returned: ', alloc_status
Expand All @@ -29,10 +35,6 @@ program plus_qft

write(*,'(A)') 'after init_creg'

reg_status = cq_register_qkern(plus_state_qft)

write(*,'(A,I4)') 'after register_qkern: ', reg_status

qrun_status = cq_sm_qrun(plus_state_qft, qrc, NQUBITS, cr, NMEASURE, NSHOTS)

write(*,'(A,I4)') 'after sm_qrun: ', qrun_status
Expand All @@ -45,6 +47,8 @@ program plus_qft

write(*,'(A,I4)') 'free_status returned: ', free_status

CQ_PROG_END()

freturn = cq_finalise(0)

write(*,'(A,I4)') 'cq_finalise returned: ',freturn
Expand Down
17 changes: 10 additions & 7 deletions examples/fortran/zero_qft.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ program zero_qft

write(*,'(A)') 'before init'

ireturn = cq_init(0)
ireturn = cq_init(1)

write(*,'(A,I4)') 'cq_init returned: ',ireturn

reg_status = cq_register_qkern(zero_state_qft)

write(*,'(A,I4)') 'after register_qkern: ', reg_status

CQ_PROG_BEGIN()

alloc_status = cq_alloc_qureg(qrc, NQUBITS)

write(*,'(A,I4)') 'alloc_qureg returned: ', alloc_status
Expand All @@ -29,11 +35,6 @@ program zero_qft

write(*,'(A)') 'after init_creg'


reg_status = cq_register_qkern(zero_state_qft)

write(*,'(A,I4)') 'after register_qkern: ', reg_status

qrun_status = cq_sm_qrun(zero_state_qft, qrc, NQUBITS, cr, NMEASURE, NSHOTS)

write(*,'(A,I4)') 'after sm_qrun: ', qrun_status
Expand All @@ -46,7 +47,9 @@ program zero_qft

write(*,'(A,I4)') 'free_status returned: ', free_status

freturn = cq_finalise(0)
CQ_PROG_END()

freturn = cq_finalise(1)

write(*,'(A,I4)') 'cq_finalise returned: ',freturn

Expand Down
18 changes: 17 additions & 1 deletion examples/qft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,20 @@ target_link_libraries(aqft
PRIVATE
CQ-SIMBE::cq-simbe
${MATHS_LIBRARY}
)
)

if (BUILD_WITH_MPI)
add_executable(mpi_aqft
mpi_aqft.c
qft-utils.c
)

find_library(MATHS_LIBRARY m REQUIRED)

target_link_libraries(mpi_aqft
PRIVATE
CQ-SIMBE::cq-simbe
${MATHS_LIBRARY}
${MPI_C_LIBRARIES}
)
endif()
Loading
Loading