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

Cudaq <> Superstaq integration #2423

Merged
merged 44 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
16d3fad
poc infleqtion server files
bharat-thotakura Nov 25, 2024
69818f0
c++ existing tests links for server
bharat-thotakura Nov 25, 2024
8d4fe3b
add new directory
bharat-thotakura Nov 25, 2024
0e8dfe6
some debug prints in c++ tests
bharat-thotakura Nov 25, 2024
d812916
draft mock qpu sketch
bharat-thotakura Nov 25, 2024
fcb33cf
add license header
bharat-thotakura Nov 25, 2024
bc10bec
Add infleqtion python test with mockserver
vtomole Nov 25, 2024
285720c
fix merge conflict
vtomole Nov 26, 2024
6f444dd
Ready to built testing wheel
vtomole Nov 26, 2024
7f3f673
Merge branch 'NVIDIA:main' into testing-server
vtomole Nov 26, 2024
64463c1
Revert testIonQ
vtomole Nov 26, 2024
68e02c7
Merge branch 'testing-server' of github.com:bharat-thotakura/cuda-qua…
vtomole Nov 26, 2024
ad36074
More reversions
vtomole Nov 26, 2024
832100a
DCO Remediation Commit for vtomole <[email protected]>
vtomole Nov 26, 2024
f7d8435
Run clang formatter
vtomole Nov 27, 2024
b0aa9c1
Format with yapf
vtomole Nov 27, 2024
2f35823
Run yapf with Google style
vtomole Nov 27, 2024
4995726
add newline at end of some new files
bharat-thotakura Nov 27, 2024
846df29
remove debug bell test
bharat-thotakura Nov 27, 2024
3a5bb09
Merge branch 'main' into testing-server
bharat-thotakura Nov 27, 2024
900fe75
Merge branch 'main' into testing-server
vtomole Nov 27, 2024
ec0d78c
Merge branch 'main' into testing-server
bharat-thotakura Nov 27, 2024
4bc6fb1
Update infleqtion.yml
vtomole Nov 28, 2024
99b7086
Merge branch 'testing-server' of github.com:bharat-thotakura/cuda-qua…
vtomole Nov 28, 2024
3d1802a
* Fix a typo in cmake
khalatepradnya Dec 2, 2024
aa8bd65
Merge branch 'main' into testing-server
khalatepradnya Dec 4, 2024
66e1813
some review responses + updates
bharat-thotakura Dec 5, 2024
65dc65a
fix: commit format
bharat-thotakura Dec 5, 2024
3621aeb
Merge branch 'main' into testing-server
khalatepradnya Dec 5, 2024
eda0882
Merge branch 'main' into testing-server
khalatepradnya Dec 5, 2024
ea7d179
* Test dor all gates, modifiers
khalatepradnya Dec 6, 2024
f12c620
* Skip the `observe` tests on C++ since the mock server returns
khalatepradnya Dec 6, 2024
12d1f75
Merge pull request #2 from khalatepradnya/infleqtion-updates
bharat-thotakura Dec 6, 2024
0d4e131
Merge branch 'main' into testing-server
bharat-thotakura Dec 6, 2024
511d502
* Updated C++ tests
khalatepradnya Dec 6, 2024
a31833d
Merge branch 'main' into testing-server
khalatepradnya Dec 6, 2024
2806714
* Fix symbolic links
khalatepradnya Dec 7, 2024
a27c1d3
update backend name
bharat-thotakura Dec 7, 2024
0988d0e
remove unused shots assignment
bharat-thotakura Dec 7, 2024
8cc2d14
override polling seconds and error for canceled job
bharat-thotakura Dec 7, 2024
0d8ee7d
Merge branch 'main' into testing-server
khalatepradnya Dec 9, 2024
8057f55
* Additional tests for multiple qvectors and multiple measurements
khalatepradnya Dec 9, 2024
f265276
Merge branch 'main' into testing-server
khalatepradnya Dec 9, 2024
d987b5c
Merge branch 'main' into testing-server
bettinaheim Dec 10, 2024
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 lib/Optimizer/CodeGen/TranslateToOpenQASM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static LogicalResult translateOperatorName(quake::OperatorInterface optor,
.Case("ry", "cry")
.Case("rz", "crz")
.Case("swap", "cswap")
.Case("u3", "cu3")
.Default(qkeName);
} else if (optor.getControls().size() == 2) {
name = StringSwitch<StringRef>(qkeName).Case("x", "ccx").Default("");
Expand Down
35 changes: 35 additions & 0 deletions lib/Optimizer/Transforms/DecompositionPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,40 @@ struct R1ToU3 : public OpRewritePattern<quake::R1Op> {
}
};

// quake.r1<adj> (θ) target
// ─────────────────────────────────
// quake.r1(-θ) target
struct R1AdjToR1 : public OpRewritePattern<quake::R1Op> {
using OpRewritePattern<quake::R1Op>::OpRewritePattern;

void initialize() { setDebugName("R1AdjToR1"); }

LogicalResult matchAndRewrite(quake::R1Op op,
PatternRewriter &rewriter) const override {
if (!op.getControls().empty())
return failure();
if (!op.isAdj())
return failure();

// Op info
Location loc = op->getLoc();
Value target = op.getTarget();
Value angle = op.getParameter();
angle = rewriter.create<arith::NegFOp>(loc, angle);

// Necessary/Helpful constants
SmallVector<Value> noControls;
SmallVector<Value> parameters = {angle};

QuakeOperatorCreator qRewriter(rewriter);
qRewriter.create<quake::R1Op>(loc, parameters, noControls, target);

qRewriter.selectWiresAndReplaceUses(op, target);
rewriter.eraseOp(op);
return success();
}
};

// quake.swap a, b
// ───────────────────────────────────
// quake.cnot b, a;
Expand Down Expand Up @@ -1575,6 +1609,7 @@ void cudaq::populateWithAllDecompositionPatterns(RewritePatternSet &patterns) {
R1ToPhasedRx,
R1ToRz,
R1ToU3,
R1AdjToR1,
// RxOp patterns
CRxToCX,
RxToPhasedRx,
Expand Down
159 changes: 159 additions & 0 deletions python/tests/backends/test_Infleqtion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# ============================================================================ #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #

import cudaq, pytest, os
from cudaq import spin
import numpy as np

## NOTE: Comment the following line which skips these tests in order to run in
# local dev environment after setting the API key
## NOTE: Superstaq costs apply
pytestmark = pytest.mark.skip("Infleqtion / Superstaq API key required")


@pytest.fixture(scope="session", autouse=True)
def do_something():
cudaq.set_target("infleqtion")
yield "Running the tests."
cudaq.__clearKernelRegistries()
cudaq.reset_target()


def assert_close(got) -> bool:
return got < -1.5 and got > -1.9


def test_simple_kernel():

@cudaq.kernel
def bell():
qubits = cudaq.qvector(2)
h(qubits[0])
x.ctrl(qubits[0], qubits[1])
mz(qubits)

counts = cudaq.sample(bell)
assert len(counts) == 2
assert "00" in counts
assert "11" in counts


def test_all_gates():

@cudaq.kernel
def all_gates():
q = cudaq.qubit()
h(q)
x(q)
y(q)
z(q)
r1(np.pi, q)
rx(np.pi, q)
ry(np.pi, q)
rz(np.pi, q)
s(q)
t(q)
u3(0.0, np.pi / 2, np.pi, q)
mz(q)

qvec = cudaq.qvector(2)
x(qvec[0])
swap(qvec[0], qvec[1])
mz(qvec)

## control modifiers
qubits = cudaq.qvector(2)
h.ctrl(qubits[0], qubits[1])
x.ctrl(qubits[1], qubits[0])
y.ctrl(qubits[0], qubits[1])
z.ctrl(qubits[1], qubits[0])
r1.ctrl(np.pi / 2, qubits[0], qubits[1])
rx.ctrl(np.pi / 4, qubits[1], qubits[0])
ry.ctrl(np.pi / 8, qubits[0], qubits[1])
rz.ctrl(np.pi, qubits[1], qubits[0])
s.ctrl(qubits[0], qubits[1])
t.ctrl(qubits[1], qubits[0])
# u3.ctrl(0.0, np.pi / 2, np.pi, qubits[0], qubits[1])
mz(qubits)

qreg = cudaq.qvector(3)
x(qreg[0])
x(qreg[1])
swap.ctrl(qreg[0], qreg[1], qreg[2])
mz(qreg)

## adjoint modifiers
r = cudaq.qubit()
r1.adj(np.pi, r)
rx.adj(np.pi / 2, r)
ry.adj(np.pi / 4, r)
rz.adj(np.pi / 8, r)
s.adj(r)
t.adj(r)
mz(r)

# Test here is that this runs
cudaq.sample(all_gates).dump()


def test_multiple_qvector():

@cudaq.kernel
def kernel():
qubits = cudaq.qvector(2)
ancilla = cudaq.qvector(2)
x(qubits)
h(ancilla)
mz(ancilla)

# Test here is that this runs
cudaq.sample(kernel).dump()


def test_multiple_measure():

@cudaq.kernel
def kernel():
q = cudaq.qvector(4)
a = cudaq.qvector(2)
h(q[0])
cx(q[0], q[1])
h(a)
cx(q[1], a[0])
mz(q[1])
mz(q[0])
mz(a)

# Test here is that this runs
cudaq.sample(kernel).dump()


def test_observe():
cudaq.set_random_seed(13)

@cudaq.kernel
def ansatz(theta: float):
qreg = cudaq.qvector(2)
x(qreg[0])
ry(theta, qreg[1])
x.ctrl(qreg[1], qreg[0])

# Define its spin Hamiltonian.
hamiltonian = 5.907 - 2.1433 * spin.x(0) * spin.x(1) - 2.1433 * spin.y(
0) * spin.y(1) + .21829 * spin.z(0) - 6.125 * spin.z(1)

res = cudaq.observe(ansatz, hamiltonian, .59, shots_count=2048)
## Need to adjust expectation value range
# assert assert_close(res.expectation())
print(res.expectation())


# leave for gdb debugging
if __name__ == "__main__":
loc = os.path.abspath(__file__)
pytest.main([loc, "-s"])
5 changes: 3 additions & 2 deletions runtime/cudaq/platform/default/rest/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #
add_subdirectory(anyon)
add_subdirectory(oqc)
add_subdirectory(infleqtion)
add_subdirectory(ionq)
add_subdirectory(quantinuum)
add_subdirectory(iqm)
add_subdirectory(oqc)
add_subdirectory(quantinuum)
if (AWSSDK_ROOT)
add_subdirectory(braket)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ============================================================================ #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #
target_sources(cudaq-rest-qpu PRIVATE InfleqtionServerHelper.cpp)
add_target_config(infleqtion)

add_library(cudaq-serverhelper-infleqtion SHARED InfleqtionServerHelper.cpp )
target_link_libraries(cudaq-serverhelper-infleqtion
PUBLIC
cudaq-common
fmt::fmt-header-only
)
install(TARGETS cudaq-serverhelper-infleqtion DESTINATION lib)
Loading
Loading