Skip to content

Commit

Permalink
Merge branch 'main' into first_shot_memory
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlietz authored Feb 7, 2025
2 parents 2bda463 + de09379 commit d9df01f
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .cudaq_version
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"cudaq": {
"repository": "NVIDIA/cuda-quantum",
"ref": "bd499151326950ffb163b2afb928ca882f926ab4"
"ref": "d8930461128a9c564d636d7531d21f836eb1a59e"
}
}
179 changes: 179 additions & 0 deletions .github/workflows/build_dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
name: Build dev images

on:
workflow_dispatch:
inputs:
force_rebuild:
type: boolean
required: true
description: 'Force rebuild even if image tags already exist'
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-cudaqx-dev:
name: Build CUDA-QX Dev Image
if: ${{ github.repository == 'NVIDIA/cudaqx' }}
strategy:
matrix:
platform: [amd64, arm64]
fail-fast: false
runs-on: linux-${{ matrix.platform }}-cpu8
steps:
- name: Login to GitHub CR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Get code
uses: actions/checkout@v4
with:
set-safe-directory: true

- name: Get required CUDA-Q version
id: get-cudaq-version
uses: ./.github/actions/get-cudaq-version

- name: Get additional metadata
id: get-cudaq-version-short
run: |
shortref=$(echo "${{ steps.get-cudaq-version.outputs.ref }}" | head -c8)
commit_date=$(curl -s "https://api.github.com/repos/NVIDIA/cuda-quantum/commits/${{ steps.get-cudaq-version.outputs.ref }}" | jq -r '.commit.committer.date' | cut -dT -f1)
echo "shortref=$shortref" >> $GITHUB_OUTPUT
echo "commit_date=$commit_date" >> $GITHUB_OUTPUT
- name: Check if image already exists
id: check-image
run: |
IMAGE_TAG="${{ steps.get-cudaq-version-short.outputs.commit_date }}-${{ steps.get-cudaq-version-short.outputs.shortref }}-${{ matrix.platform }}"
CONTAINER_VERSION_METADATA=$(curl -s -L -H "Accept: applicat/vnd.github+json" -H "Authorization: Bearer ${{ github.token }}" "https://api.github.com/orgs/NVIDIA/packages/container/cudaqx-dev/versions")
CONTAINER_TAGS=$(echo $CONTAINER_VERSION_METADATA | jq -r '.[] | .metadata.container.tags[]')
if echo "$CONTAINER_TAGS" | grep -qx "$IMAGE_TAG"; then
echo "Image tag $IMAGE_TAG already exists. Skipping build."
echo "IMAGE_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "Image tag $IMAGE_TAG does not exist. Proceeding with build."
echo "IMAGE_EXISTS=false" >> $GITHUB_OUTPUT
fi
- name: Set up context for buildx
if: ${{ inputs.force_rebuild || steps.check-image.outputs.IMAGE_EXISTS == 'false' }}
run: |
docker context create builder_context
shell: bash --noprofile --norc -euo pipefail {0}

- name: Set up buildx runner
if: ${{ inputs.force_rebuild ||steps.check-image.outputs.IMAGE_EXISTS == 'false' }}
uses: docker/setup-buildx-action@v3
with:
endpoint: builder_context
driver-opts: network=host

- name: Build dev image
if: ${{ inputs.force_rebuild ||steps.check-image.outputs.IMAGE_EXISTS == 'false' }}
uses: docker/build-push-action@v5
with:
file: ./docker/build_env/cudaqx.dev.Dockerfile
tags: |
ghcr.io/nvidia/cudaqx-dev:${{ steps.get-cudaq-version-short.outputs.commit_date }}-${{ steps.get-cudaq-version-short.outputs.shortref }}-${{ matrix.platform }}
ghcr.io/nvidia/cudaqx-dev:${{ steps.get-cudaq-version-short.outputs.shortref }}-${{ matrix.platform }}
ghcr.io/nvidia/cudaqx-dev:latest-${{ matrix.platform }}
platforms: linux/${{ matrix.platform }}
push: true

build-cudaqx-pydev:
name: Build CUDA-QX Python Dev Image
if: ${{ github.repository == 'NVIDIA/cudaqx' }}
strategy:
matrix:
python: ['3.10', '3.11', '3.12']
platform: ['amd64', 'arm64']
fail-fast: false
runs-on: linux-${{ matrix.platform }}-cpu8
steps:
- name: Login to GitHub CR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Get code
uses: actions/checkout@v4
with:
set-safe-directory: true

- name: Get required CUDA-Q version
id: get-cudaq-version
uses: ./.github/actions/get-cudaq-version

- name: Get additional metadata
id: get-cudaq-version-short
run: |
shortref=$(echo "${{ steps.get-cudaq-version.outputs.ref }}" | head -c8)
commit_date=$(curl -s "https://api.github.com/repos/NVIDIA/cuda-quantum/commits/${{ steps.get-cudaq-version.outputs.ref }}" | jq -r '.commit.committer.date' | cut -dT -f1)
echo "shortref=$shortref" >> $GITHUB_OUTPUT
echo "commit_date=$commit_date" >> $GITHUB_OUTPUT
- name: Check if image already exists
id: check-image
run: |
IMAGE_TAG="${{ steps.get-cudaq-version-short.outputs.commit_date }}-${{ steps.get-cudaq-version-short.outputs.shortref }}-${{ matrix.platform }}"
CONTAINER_VERSION_METADATA=$(curl -s -L -H "Accept: applicat/vnd.github+json" -H "Authorization: Bearer ${{ github.token }}" "https://api.github.com/orgs/NVIDIA/packages/container/cudaqx-dev/versions")
CONTAINER_TAGS=$(echo $CONTAINER_VERSION_METADATA | jq -r '.[] | .metadata.container.tags[]')
if echo "$CONTAINER_TAGS" | grep -qx "$IMAGE_TAG"; then
echo "Image tag $IMAGE_TAG already exists. Skipping build."
echo "IMAGE_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "Image tag $IMAGE_TAG does not exist. Proceeding with build."
echo "IMAGE_EXISTS=false" >> $GITHUB_OUTPUT
fi
- name: Set up context for buildx
if: ${{ inputs.force_rebuild ||steps.check-image.outputs.IMAGE_EXISTS == 'false' }}
run: |
docker context create builder_context
shell: bash --noprofile --norc -euo pipefail {0}

- name: Set up buildx runner
if: ${{ inputs.force_rebuild ||steps.check-image.outputs.IMAGE_EXISTS == 'false' }}
uses: docker/setup-buildx-action@v3
with:
endpoint: builder_context
driver-opts: network=host

- name: Build pydev image
if: ${{ inputs.force_rebuild ||steps.check-image.outputs.IMAGE_EXISTS == 'false' }}
uses: docker/build-push-action@v5
with:
file: ./docker/build_env/cudaqx.wheel.Dockerfile
build-args: |
base_image=ghcr.io/nvidia/cuda-quantum-devdeps:manylinux-${{ matrix.platform }}-cu12.0-gcc11-main
python_version=${{ matrix.python }}
tags: |
ghcr.io/nvidia/cudaqx-dev:${{ steps.get-cudaq-version-short.outputs.commit_date }}-${{ steps.get-cudaq-version-short.outputs.shortref }}-py${{ matrix.python }}-${{ matrix.platform }}
ghcr.io/nvidia/cudaqx-dev:${{ steps.get-cudaq-version-short.outputs.shortref }}-py${{ matrix.python }}-${{ matrix.platform }}
ghcr.io/nvidia/cudaqx-dev:latest-py${{ matrix.python }}-${{ matrix.platform }}
platforms: linux/${{ matrix.platform }}
push: true

cleanup:
name: Cleanup
needs: [build-cudaqx-dev, build-cudaqx-pydev]
runs-on: ubuntu-latest
if: ${{ github.repository == 'NVIDIA/cudaqx' }}
steps:
- name: Delete untagged images
uses: actions/delete-package-versions@v5
with:
package-name: cudaqx-dev
package-type: 'container'
min-versions-to-keep: 0
delete-only-untagged-versions: 'true'
18 changes: 15 additions & 3 deletions .github/workflows/update-cudaq-dep.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
on:
workflow_dispatch:
inputs:
cudaq_branch_name:
type: string
required: true
description: 'Branch name for upstream CUDA-Q repo (e.g. main or pull-request/2407)'
default: main

schedule:
- cron: 0 1 * * 6

Expand All @@ -22,7 +29,7 @@ jobs:

- name: Fetch the latest commit
run: |
SHA=$(curl -s "https://api.github.com/repos/NVIDIA/cuda-quantum/commits/main" | jq -r '.sha')
SHA=$(curl -s "https://api.github.com/repos/NVIDIA/cuda-quantum/commits/${{ inputs.cudaq_branch_name }}" | jq -r '.sha')
echo "Latest SHA: $SHA"
echo "sha=$SHA" >> $GITHUB_ENV
Expand Down Expand Up @@ -64,8 +71,13 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}
BRANCH_NAME: ${{ steps.commit_and_push.outputs.BRANCH_NAME }}
run: |
if [[ "${{ inputs.cudaq_branch_name }}" == "main" ]]; then
TITLE_STR="Bump CUDA-Q commit"
else
TITLE_STR="Bump CUDA-Q commit (${{ inputs.cudaq_branch_name }} DO NOT MERGE)"
fi
gh pr create \
--title "Bump CUDA-Q commit" \
--body "Auto update to the latest CUDA-Q commit" \
--title "${TITLE_STR}" \
--body "Auto update to the latest CUDA-Q commit on ${{ inputs.cudaq_branch_name }} branch" \
--head "${BRANCH_NAME}" \
--base "main"
22 changes: 0 additions & 22 deletions docker/build_env/Dockerfile

This file was deleted.

34 changes: 34 additions & 0 deletions docker/build_env/cudaqx.dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ============================================================================ #
# Copyright (c) 2025 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. #
# ============================================================================ #

FROM ghcr.io/nvidia/cuda-quantum-devdeps:ext-cu12.0-gcc11-main

LABEL org.opencontainers.image.description="Dev tools for building and testing CUDA-QX libraries"
LABEL org.opencontainers.image.source="https://github.com/NVIDIA/cudaqx"
LABEL org.opencontainers.image.title="cuda-qx-dev"
LABEL org.opencontainers.image.url="https://github.com/NVIDIA/cudaqx"

RUN apt-get update && apt-get install -y gfortran libblas-dev jq cuda-nvtx-12-0 \
&& python3 -m pip install cmake --user \
&& apt-get autoremove -y --purge && apt-get clean && rm -rf /var/lib/apt/lists/*

COPY .cudaq_version /cudaq_version

RUN mkdir -p /workspaces/cudaq && cd /workspaces/cudaq \
&& git init \
&& CUDAQ_REPO=$(jq -r '.cudaq.repository' /cudaq_version) \
&& CUDAQ_COMMIT=$(jq -r '.cudaq.ref' /cudaq_version) \
&& git remote add origin https://github.com/${CUDAQ_REPO} \
&& git fetch -q --depth=1 origin ${CUDAQ_COMMIT} \
&& git reset --hard FETCH_HEAD \
&& bash scripts/build_cudaq.sh -v \
&& rm -rf build

#RUN mkdir -p /workspaces/cudaqx && cd /workspaces/cudaqx \
# && ~/.local/bin/cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCUDAQ_DIR=~/.cudaq/lib/cmake/cudaq .. \
# && ninja install
32 changes: 32 additions & 0 deletions docker/build_env/cudaqx.wheel.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ============================================================================ #
# Copyright (c) 2025 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. #
# ============================================================================ #

ARG base_image=ghcr.io/nvidia/cuda-quantum-devdeps:manylinux-amd64-cu12.0-gcc11-main
FROM ${base_image}

ARG python_version=3.10

LABEL org.opencontainers.image.description="Dev tools for building and testing CUDA-QX libraries"
LABEL org.opencontainers.image.source="https://github.com/NVIDIA/cudaqx"
LABEL org.opencontainers.image.title="cuda-qx-dev"
LABEL org.opencontainers.image.url="https://github.com/NVIDIA/cudaqx"

RUN dnf install -y jq
RUN mkdir -p /workspaces/cudaqx
COPY .cudaq_version /workspaces/cudaqx
COPY .github/workflows/scripts/build_cudaq.sh /workspaces/cudaqx

RUN mkdir -p /workspaces/cudaqx/cudaq && cd /workspaces/cudaqx/cudaq \
&& git init \
&& CUDAQ_REPO=$(jq -r '.cudaq.repository' /workspaces/cudaqx/.cudaq_version) \
&& CUDAQ_COMMIT=$(jq -r '.cudaq.ref' /workspaces/cudaqx/.cudaq_version) \
&& git remote add origin https://github.com/${CUDAQ_REPO} \
&& git fetch -q --depth=1 origin ${CUDAQ_COMMIT} \
&& git reset --hard FETCH_HEAD \
&& bash ../build_cudaq.sh --python-version ${python_version} \
&& rm -rf build
43 changes: 22 additions & 21 deletions libs/solvers/lib/stateprep/uccsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,10 @@ __qpu__ std::size_t getNumVirtualBeta(std::size_t numElectrons,
__qpu__ void uccsd(cudaq::qview<> qubits, const std::vector<double> &thetas,
std::size_t numElectrons, std::size_t spin) {

auto numOccAlpha = getNumOccupiedAlpha(numElectrons, spin, qubits.size());
auto numOccBeta = getNumOccupiedBeta(numElectrons, spin, qubits.size());
auto numVirtAlpha = getNumVirtualAlpha(numElectrons, spin, qubits.size());
auto numVirtBeta = getNumVirtualBeta(numElectrons, spin, qubits.size());
int numOccAlpha = getNumOccupiedAlpha(numElectrons, spin, qubits.size());
int numOccBeta = getNumOccupiedBeta(numElectrons, spin, qubits.size());
int numVirtAlpha = getNumVirtualAlpha(numElectrons, spin, qubits.size());
int numVirtBeta = getNumVirtualBeta(numElectrons, spin, qubits.size());
std::vector<std::size_t> occupiedAlpha(numOccAlpha),
virtualAlpha(numVirtAlpha), occupiedBeta(numOccBeta),
virtualBeta(numVirtBeta);
Expand All @@ -433,10 +433,11 @@ __qpu__ void uccsd(cudaq::qview<> qubits, const std::vector<double> &thetas,
occupiedBeta[counter] = i * 2 + 1;
counter++;
}
counter = 0;

counter = 0;
for (std::size_t i = 0; i < numVirtBeta; i++) {
virtualBeta[counter] = i * 2 + numElectrons - 1;
counter++;
}

} else {
Expand Down Expand Up @@ -507,18 +508,18 @@ __qpu__ void uccsd(cudaq::qview<> qubits, const std::vector<double> &thetas,
}

counter = 0;
for (std::size_t p = 0; p < numOccAlpha - 1; p++)
for (std::size_t q = p + 1; q < numOccAlpha; q++)
for (std::size_t r = 0; r < numVirtAlpha - 1; r++)
for (std::size_t s = r + 1; s < numVirtAlpha; s++)
for (int p = 0; p < numOccAlpha - 1; p++)
for (int q = p + 1; q < numOccAlpha; q++)
for (int r = 0; r < numVirtAlpha - 1; r++)
for (int s = r + 1; s < numVirtAlpha; s++)
counter++;

std::vector<std::size_t> doublesAlpha(4 * counter);
counter = 0;
for (std::size_t p = 0; p < numOccAlpha - 1; p++)
for (std::size_t q = p + 1; q < numOccAlpha; q++)
for (std::size_t r = 0; r < numVirtAlpha - 1; r++)
for (std::size_t s = r + 1; s < numVirtAlpha; s++) {
for (int p = 0; p < numOccAlpha - 1; p++)
for (int q = p + 1; q < numOccAlpha; q++)
for (int r = 0; r < numVirtAlpha - 1; r++)
for (int s = r + 1; s < numVirtAlpha; s++) {
doublesAlpha[counter] = occupiedAlpha[p];
counter++;
doublesAlpha[counter] = occupiedAlpha[q];
Expand All @@ -530,17 +531,17 @@ __qpu__ void uccsd(cudaq::qview<> qubits, const std::vector<double> &thetas,
}

counter = 0;
for (std::size_t p = 0; p < numOccBeta - 1; p++)
for (std::size_t q = p + 1; q < numOccBeta; q++)
for (std::size_t r = 0; r < numVirtBeta - 1; r++)
for (std::size_t s = r + 1; s < numVirtBeta; s++)
for (int p = 0; p < numOccBeta - 1; p++)
for (int q = p + 1; q < numOccBeta; q++)
for (int r = 0; r < numVirtBeta - 1; r++)
for (int s = r + 1; s < numVirtBeta; s++)
counter++;
std::vector<std::size_t> doublesBeta(4 * counter);
counter = 0;
for (std::size_t p = 0; p < numOccBeta - 1; p++)
for (std::size_t q = p + 1; q < numOccBeta; q++)
for (std::size_t r = 0; r < numVirtBeta - 1; r++)
for (std::size_t s = r + 1; s < numVirtBeta; s++) {
for (int p = 0; p < numOccBeta - 1; p++)
for (int q = p + 1; q < numOccBeta; q++)
for (int r = 0; r < numVirtBeta - 1; r++)
for (int s = r + 1; s < numVirtBeta; s++) {
doublesBeta[counter] = occupiedBeta[p];
counter++;
doublesBeta[counter] = occupiedBeta[q];
Expand Down
Loading

0 comments on commit d9df01f

Please sign in to comment.