Skip to content

Commit 5a82186

Browse files
committed
Merge branch 'main' into python-bridge
Signed-off-by: Bettina Heim <[email protected]>
2 parents 64c6d60 + a3ac400 commit 5a82186

23 files changed

+260
-710
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
nvidia-mgpu-repo: cuda-quantum/cuquantum-mgpu.git
2-
nvidia-mgpu-commit: ef144598fe5beab4b80edbd30e455906373e2e0e
2+
nvidia-mgpu-commit: 8d7646431c824f8a7bf88bf3d9ba02f42746a024

.github/workflows/publishing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ jobs:
11391139
# Note: this is the version of the conda 'nvidia/label/cuda' channel.
11401140
# Specifically, 'nvidia/label/cuda-13.0.0' does not contain proper CUDA 13 packages,
11411141
# hence we need to use later channels.
1142-
cuda_version_conda: ['12.4.0', '13.0.2']
1142+
cuda_version_conda: ['12.6.0', '13.0.2']
11431143
fail-fast: false
11441144

11451145
# Must have environment to access environment secreats

docker/build/devdeps.ext.Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ ENV PIP_BREAK_SYSTEM_PACKAGES=1
172172

173173
# Install cuQuantum dependencies, including cuTensor.
174174
# Install cupy version 13.4.1
175+
# Note: for docker images, we fixed the cuquantum version (with `==`) to avoid unintentional upgrades.
176+
# e.g., API marked as deprecated in a minor version upgrade may break build.
177+
# For Python pip installations, we allow minor version upgrades with `~=`, assuming the API is stable.
175178
RUN apt-get update && apt-get install -y --no-install-recommends \
176179
python3 python3-pip && \
177180
apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* && \
@@ -180,7 +183,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
180183
else \
181184
cupy_version=13.4.1; \
182185
fi && \
183-
python3 -m pip install --break-system-packages cupy-cuda$(echo $CUDA_VERSION | cut -d . -f1)x==${cupy_version} cuquantum-cu$(echo $CUDA_VERSION | cut -d . -f1)==25.09 && \
186+
python3 -m pip install --break-system-packages cupy-cuda$(echo $CUDA_VERSION | cut -d . -f1)x==${cupy_version} cuquantum-cu$(echo $CUDA_VERSION | cut -d . -f1)==25.09.1 && \
184187
if [ "$(python3 --version | grep -o [0-9\.]* | cut -d . -f -2)" != "3.12" ]; then \
185188
echo "expecting Python version 3.12"; \
186189
fi

include/cudaq/Optimizer/Builder/Factory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ cudaq::cc::PointerType getIndexedObjectType(mlir::Type eleTy);
8282

8383
mlir::Type genArgumentBufferType(mlir::Type ty);
8484

85+
bool isStlVectorBoolHostType(mlir::Type ty);
86+
8587
/// Build an LLVM struct type with all the arguments and then all the results.
8688
/// If the type is a std::vector, then add an i64 to the struct for the
8789
/// length. The actual data values will be appended to the end of the

lib/Optimizer/Builder/Factory.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,27 @@ static cc::StructType stlHostVectorType(Type eleTy) {
357357
return cc::StructType::get(ctx, ArrayRef<Type>{ptrTy, padout});
358358
}
359359

360+
bool factory::isStlVectorBoolHostType(Type ty) {
361+
auto strTy = dyn_cast<cc::StructType>(ty);
362+
if (!strTy)
363+
return false;
364+
if (strTy.getMembers().size() != 2)
365+
return false;
366+
auto ptrTy = dyn_cast<cc::PointerType>(strTy.getMember(0));
367+
if (!ptrTy)
368+
return false;
369+
if (ptrTy.getElementType() != IntegerType::get(ty.getContext(), 1))
370+
return false;
371+
auto arrTy = dyn_cast<cc::ArrayType>(strTy.getMember(1));
372+
if (!arrTy)
373+
return false;
374+
if (arrTy.getElementType() != IntegerType::get(ty.getContext(), 8))
375+
return false;
376+
if (arrTy.isUnknownSize() || (arrTy.getSize() != 32))
377+
return false;
378+
return true;
379+
}
380+
360381
// FIXME: Give these front-end names so we can disambiguate more types.
361382
cc::StructType factory::getDynamicBufferType(MLIRContext *ctx) {
362383
auto ptrTy = cc::PointerType::get(IntegerType::get(ctx, 8));
@@ -374,7 +395,7 @@ Type factory::getSRetElementType(FunctionType funcTy) {
374395
if (funcTy.getNumResults() > 1)
375396
return cc::StructType::get(ctx, funcTy.getResults());
376397
if (auto spanTy = dyn_cast<cc::SpanLikeType>(funcTy.getResult(0)))
377-
return stlVectorType(spanTy.getElementType());
398+
return stlHostVectorType(spanTy.getElementType());
378399
return funcTy.getResult(0);
379400
}
380401

@@ -775,7 +796,7 @@ factory::getOrAddFunc(mlir::Location loc, mlir::StringRef funcName,
775796
}
776797

777798
void factory::mergeModules(ModuleOp into, ModuleOp from) {
778-
for (Operation &op : *from.getBody()) {
799+
for (Operation &op : from) {
779800
auto sym = dyn_cast<SymbolOpInterface>(op);
780801
if (!sym)
781802
continue; // Only merge named symbols, avoids duplicating anonymous ops.

lib/Optimizer/Transforms/ApplyOpSpecialization.cpp

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,21 @@ struct ApplyOpPattern : public OpRewritePattern<quake::ApplyOp> {
259259

260260
LogicalResult matchAndRewrite(quake::ApplyOp apply,
261261
PatternRewriter &rewriter) const override {
262-
auto calleeName = getVariantFunctionName(
263-
apply, apply.getCallee()->getRootReference().str());
262+
std::string calleeOrigName;
263+
if (apply.getCallee()) {
264+
calleeOrigName = apply.getCallee()->getRootReference().str();
265+
} else {
266+
// Check if the first argument is a func.ConstantOp.
267+
auto calleeVals = apply.getIndirectCallee();
268+
if (calleeVals.empty())
269+
return failure();
270+
Value calleeVal = calleeVals.front();
271+
auto fc = calleeVal.getDefiningOp<func::ConstantOp>();
272+
if (!fc)
273+
return failure();
274+
calleeOrigName = fc.getValue().str();
275+
}
276+
auto calleeName = getVariantFunctionName(apply, calleeOrigName);
264277
auto *ctx = apply.getContext();
265278
auto consTy = quake::VeqType::getUnsized(ctx);
266279
SmallVector<Value> newArgs;
@@ -286,14 +299,44 @@ struct ApplyOpPattern : public OpRewritePattern<quake::ApplyOp> {
286299
const bool constProp;
287300
};
288301

302+
struct FoldCallable : public OpRewritePattern<quake::ApplyOp> {
303+
using OpRewritePattern::OpRewritePattern;
304+
305+
LogicalResult matchAndRewrite(quake::ApplyOp apply,
306+
PatternRewriter &rewriter) const override {
307+
// If we already know the callee function, there's nothing to do.
308+
if (apply.getCallee())
309+
return failure();
310+
311+
Value ind = apply.getIndirectCallee()[0];
312+
if (auto callee = ind.getDefiningOp<cudaq::cc::InstantiateCallableOp>()) {
313+
auto sym = callee.getCallee();
314+
SmallVector<Value> newArguments = {ind};
315+
newArguments.append(apply.getArgs().begin(), apply.getArgs().end());
316+
rewriter.replaceOpWithNewOp<quake::ApplyOp>(
317+
apply, apply.getResultTypes(), sym, apply.getIsAdj(),
318+
apply.getControls(), newArguments);
319+
return success();
320+
}
321+
return failure();
322+
}
323+
};
324+
289325
class ApplySpecializationPass
290326
: public cudaq::opt::impl::ApplySpecializationBase<
291327
ApplySpecializationPass> {
292328
public:
293329
using ApplySpecializationBase::ApplySpecializationBase;
294330

295331
void runOnOperation() override {
296-
ApplyOpAnalysis analysis(getOperation(), constantPropagation);
332+
ModuleOp module = getOperation();
333+
auto *ctx = module.getContext();
334+
RewritePatternSet patterns(ctx);
335+
patterns.insert<FoldCallable>(ctx);
336+
if (failed(applyPatternsAndFoldGreedily(module, std::move(patterns))))
337+
signalPassFailure();
338+
339+
ApplyOpAnalysis analysis(module, constantPropagation);
297340
const auto &applyVariants = analysis.getAnalysisInfo();
298341
if (succeeded(step1(applyVariants)))
299342
step2();

lib/Optimizer/Transforms/GlobalizeArrayValues.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ struct ReifySpanPattern : public OpRewritePattern<cudaq::cc::ReifySpanOp> {
276276
}
277277
}
278278

279+
// FIXME: get rid of this;
280+
// see https://github.com/NVIDIA/cuda-quantum/issues/3593
279281
auto hasBoolElems = false;
280282
if (auto iTy = dyn_cast<IntegerType>(eleTy)) {
281283
if (iTy.getWidth() == 1) {

pyproject.toml.cu12

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ description="Python bindings for the CUDA-Q toolkit for heterogeneous quantum-cl
1414
authors = [{name = "NVIDIA Corporation & Affiliates"}]
1515
maintainers = [{name = "NVIDIA Corporation & Affiliates"}]
1616
readme = { file="python/README.md.in", content-type = "text/markdown"}
17-
requires-python = ">=3.10"
17+
requires-python = ">=3.11"
1818
license = { file="LICENSE" }
1919
dependencies = [
2020
'astpretty ~= 3.0',
21-
'cuquantum-cu12 == 25.09',
21+
'custatevec-cu12 ~= 1.10',
22+
'cutensornet-cu12 ~= 2.9',
23+
'cudensitymat-cu12 ~= 0.3',
2224
'numpy >= 1.24',
2325
'scipy >= 1.10.1',
2426
'requests >= 2.31',

pyproject.toml.cu13

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ description="Python bindings for the CUDA-Q toolkit for heterogeneous quantum-cl
1414
authors = [{name = "NVIDIA Corporation & Affiliates"}]
1515
maintainers = [{name = "NVIDIA Corporation & Affiliates"}]
1616
readme = { file="python/README.md.in", content-type = "text/markdown"}
17-
requires-python = ">=3.10"
17+
requires-python = ">=3.11"
1818
license = { file="LICENSE" }
1919
dependencies = [
2020
'astpretty ~= 3.0',
21-
'cuquantum-cu13 == 25.09',
21+
'custatevec-cu13 ~= 1.10',
22+
'cutensornet-cu13 ~= 2.9',
23+
'cudensitymat-cu13 ~= 0.3',
2224
'numpy >= 1.24',
2325
'scipy >= 1.10.1',
2426
'requests >= 2.31',
25-
'nvidia-cublas ~= 13.1',
27+
'nvidia-cublas ~= 13.0',
2628
'nvidia-curand ~= 10.4',
2729
'nvidia-cusparse ~= 12.6',
2830
'nvidia-cuda-runtime ~= 13.0',

python/cudaq/kernel/ast_bridge.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4663,8 +4663,7 @@ def __process_binary_op(self, left, right, nodeType):
46634663
if IntegerType.isinstance(left.type):
46644664
self.pushValue(arith.RemUIOp(left, right).result)
46654665
return
4666-
if F64Type.isinstance(left.type) or \
4667-
F32Type.isinstance(left.type):
4666+
if (F64Type.isinstance(left.type) or F32Type.isinstance(left.type)):
46684667
self.pushValue(arith.RemFOp(left, right).result)
46694668
return
46704669
else:
@@ -4744,8 +4743,8 @@ def visit_AugAssign(self, node):
47444743

47454744
if not cc.PointerType.isinstance(target.type):
47464745
self.emitFatalError(
4747-
"augment-assign target variable cannot be assigned to",
4748-
node)
4746+
"augment-assign target variable is not defined or "
4747+
"cannot be assigned to.", node)
47494748

47504749
self.visit(node.value)
47514750
value = self.popValue()

0 commit comments

Comments
 (0)