Skip to content

Commit

Permalink
Merge branch 'main' into fix_dialects_double_install
Browse files Browse the repository at this point in the history
  • Loading branch information
schweitzpgi authored Dec 18, 2024
2 parents 09111e6 + 1a4f99e commit d5c9a04
Show file tree
Hide file tree
Showing 68 changed files with 1,118 additions and 934 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ jobs:
fi
image_tag=`docker inspect $cudaq_image --format='{{json .Config.Labels}}' | jq -r '."org.opencontainers.image.version"'`
docs_version="CUDA_QUANTUM_VERSION=${image_tag%-base}"
docs_version="CUDA_QUANTUM_VERSION=$(echo $image_tag | sed -re 's/^(cu[0-9]+-)?(.*)-base$/\2/')"
docker image rm $cudaq_image
docker image prune --force
Expand Down
58 changes: 48 additions & 10 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
options:
- nightly
- anyon
- infleqtion
- ionq
- iqm
- oqc
Expand Down Expand Up @@ -335,11 +336,7 @@ jobs:
fi
- name: Setup anyon account
# This step is currently bypassed during nightly runs due to
# maintenance. Restore the if check to the original value when
# maintenance is complete.
#if: github.event_name == 'schedule' || inputs.target == 'nightly' || inputs.target == 'anyon'
if: inputs.target == 'anyon'
if: github.event_name == 'schedule' || inputs.target == 'nightly' || inputs.target == 'anyon'
run: |
curl -X POST --user "${{ secrets.ANYON_USERNAME }}:${{ secrets.ANYON_PASSWORD }}" -H "Content-Type: application/json" https://api.anyon.cloud:5000/login > credentials.json
id_token=`cat credentials.json | jq -r '."id_token"'`
Expand All @@ -348,11 +345,7 @@ jobs:
echo "refresh: $refresh_token" >> ~/.anyon_config
- name: QIR syntax check (Anyon)
# This step is currently bypassed during nightly runs due to
# maintenance. Restore the if check to the original value when
# maintenance is complete.
#if: github.event_name == 'schedule' || inputs.target == 'nightly' || inputs.target == 'anyon'
if: inputs.target == 'anyon'
if: github.event_name == 'schedule' || inputs.target == 'nightly' || inputs.target == 'anyon'
run: |
echo "### QIR syntax check (Anyon)" >> $GITHUB_STEP_SUMMARY
export CUDAQ_LOG_LEVEL="info"
Expand Down Expand Up @@ -650,6 +643,51 @@ jobs:
fi
shell: bash

- name: Submit to Infleqtion test server
if: (success() || failure()) && (inputs.target == 'infleqtion' || github.event_name == 'schedule' || inputs.target == 'nightly')
run: |
echo "### Submit to Infleqtion server" >> $GITHUB_STEP_SUMMARY
export SUPERSTAQ_API_KEY='${{ secrets.SUPERSTAQ_API_KEY }}'
set +e # Allow script to keep going through errors
test_err_sum=0
cpp_tests="docs/sphinx/targets/cpp/infleqtion.cpp"
for filename in $cpp_tests; do
[ -e "$filename" ] || echo "::error::Couldn't find file ($filename)"
nvq++ --target infleqtion $filename
test_status=$?
if [ $test_status -eq 0 ]; then
./a.out
test_status=$?
if [ $test_status -eq 0 ]; then
echo ":white_check_mark: Successfully ran test: $filename" >> $GITHUB_STEP_SUMMARY
else
echo ":x: Test failed (failed to execute): $filename" >> $GITHUB_STEP_SUMMARY
test_err_sum=$((test_err_sum+1))
fi
else
echo ":x: Test failed (failed to compile): $filename" >> $GITHUB_STEP_SUMMARY
test_err_sum=$((test_err_sum+1))
fi
done
python_tests="docs/sphinx/targets/python/infleqtion.py"
for filename in $python_tests; do
[ -e "$filename" ] || echo "::error::Couldn't find file ($filename)"
python3 $filename 1> /dev/null
test_status=$?
if [ $test_status -eq 0 ]; then
echo ":white_check_mark: Successfully ran test: $filename" >> $GITHUB_STEP_SUMMARY
else
echo ":x: Test failed (failed to execute): $filename" >> $GITHUB_STEP_SUMMARY
test_err_sum=$((test_err_sum+1))
fi
done
set -e # Re-enable exit code error checking
if [ ! $test_err_sum -eq 0 ]; then
echo "::error::${test_err_sum} tests failed. See step summary for a list of failures"
exit 1
fi
shell: bash

- name: Submit to ${{ inputs.target }}
# The full set of tests used by this step is currently only supported on
# Quantinuum. The other supported tests are tested by the step above.
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/publishing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,11 @@ jobs:
cuda_version: ['11.8', '12.4']
fail-fast: false

# Must have environment to access environment secreats
environment:
name: ghcr-deployment
url: ${{ vars.deployment_url }}

container:
image: ubuntu:22.04
options: --user root
Expand Down Expand Up @@ -1129,13 +1134,16 @@ jobs:
rm -rf ${cudaq_metapackage} && readme=README.md
# Setup files for validate_pycudaq.sh script
# Important: Notebooks are *not* validated by validate_pycudaq.sh.
cp $GITHUB_WORKSPACE/scripts/validate_pycudaq.sh .
cp -r $GITHUB_WORKSPACE/docs/sphinx/examples/python /tmp/examples/
cp -r $GITHUB_WORKSPACE/docs/sphinx/applications/python /tmp/applications/
cp -r $GITHUB_WORKSPACE/docs/sphinx/targets/python /tmp/targets/
cp -r $GITHUB_WORKSPACE/docs/sphinx/snippets/python /tmp/snippets/
cp -r $GITHUB_WORKSPACE/python/tests /tmp/tests/
cp $GITHUB_WORKSPACE/$readme /tmp/README.md
# Target tests should not be run here either, since that requires credentials but doesn't require a GPU runner.
# The NVQC API key is needed to validate NVQC related snippets and examples.
export NVQC_API_KEY="${{ secrets.NVQC_PROD_SERVICE_KEY }}"
# Run the script w/ -q to run a shortened test
set +e # Allow script to keep going through errors (needed for skipped tests)
Expand All @@ -1158,7 +1166,7 @@ jobs:
create_release:
name: CUDA-Q Release
needs: [assets, cudaq_images, cudaq_installers, cudaq_wheels, cudaq_metapackages]
if: needs.assets.outputs.release_title && inputs.github_commit == '' && inputs.assets_from_run == '' && inputs.nvidia_mgpu_commit == ''
if: needs.assets.outputs.release_title && inputs.github_commit == '' && inputs.nvidia_mgpu_commit == ''
runs-on: ubuntu-latest

environment:
Expand Down
2 changes: 2 additions & 0 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[style]
based_on_style = google
49 changes: 24 additions & 25 deletions docs/sphinx/applications/python/deutschs_algorithm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We have a function which takes in a bit and outputs a bit. This can be represented as $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$. \n",
"Deutsch's Algorithm is a concise demonstration of the differences in computational complexity between classical and quantum algorithms for certain problems. For Desutch's algorithm, we begin with a function which takes in a bit and outputs a bit. This can be represented as $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$. \n",
"The function $f$ has the property that it either constant or balanced. The goal of Deutsch's Algorithm is to determine whether our given function is constant or whether it is balanced. \n",
"\n",
"The function $f$ has a property; either it is constant or balanced. \n",
"A constant function is \"A balanced function is a function such that the outputs are the same regardless of the inputs, i.e., if $f(0) = 0$ then $f(1) = 1$ or if $f(0) = 1$ then $f(1) = 0$.\n\", the outputs are the same regardless of the inputs, i.e., in the case of $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$, there are are two ways in which this can occur: $f(0) = f(1) = 0$ or $f(0) = f(1) = 1$.\n",
"\n",
"If constant, the outputs are the same regardless of the inputs, i.e., $f(0) = f(1) = 0$ or $f(0) = f(1) = 1$.\n",
"\n",
"If balanced, the ouputs are balanced across their possibilities, i.e, if $f(0) = 0$ then $f(1) = 1$ or if $f(0) = 1$ then $f(1) = 0$.\n",
"\n",
"The question we would like to answer is if the function is constant or balanced. \n",
"A balanced function is defined such that the ouputs are balanced across their possibilities, i.e., if $f(0) = 0$ then $f(1) = 1$ or if $f(0) = 1$ then $f(1) = 0$.\n",
" \n",
"Classically, if we are given a function $f$, we can solve to find its property via the code below: \n"
"Classically, if we are given a function $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$, we can determine if it is constant or balanced by evaluating the function at $0$ and at $1$. This is carried out in the code below: \n"
]
},
{
Expand Down Expand Up @@ -96,11 +93,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"If you step through the `if` statements above, one can see that we require 2 calls to the function to determine its property. That is, we have to query $f$ twice.\n",
"If you step through the `if` statements above, you may notice that we require 2 calls to the function to determine its property. That is, we have to query $f$ twice.\n",
"\n",
"The claim is that Deutsch's algorithm can solve for this property with 1 function evalulation, demonstrating quantum advantage. \n",
"The claim is that Deutsch's Algorithm can determine if a given function is constant or balanced with just 1 function evalulation, demonstrating quantum advantage. \n",
"\n",
"Below we first go through the math and then the implementation in CUDA Quantum. \n",
"Below we first outline Deutsch's Algorithm and work through the math to verify that it does as promised. Then, we provide the implementation in CUDA-Q. \n",
"\n"
]
},
Expand Down Expand Up @@ -130,7 +127,7 @@
"\n",
"<img src=\"images/oracle.png\" width=\"300\" height=\"150\">\n",
"\n",
"Suppose we have $f(x): \\{0,1\\} \\longrightarrow \\{0,1\\}$. We can compute this function on a quantum computer using oracles which we treat as black box functions that yield the output with an appropriate sequence of logic gates. \n",
"Suppose we have $f(x): \\{0,1\\} \\longrightarrow \\{0,1\\}$. We can compute this function on a quantum computer using oracles which we treat as black box functions that yield the output with an appropriate sequence of logical gates. \n",
"\n",
"Above you see an oracle represented as $U_f$ which allows us to transform the state $\\ket{x}\\ket{y}$ into: \n",
"\n",
Expand All @@ -140,7 +137,7 @@
"\\end{aligned}\n",
"$$\n",
"\n",
"If $y = 0$, then $U_f\\ket{x}\\ket{y} = U_f\\ket{x}\\ket{0} = \\ket{x}\\ket{0 \\oplus f(x)} = \\ket{x}\\ket{f(x)}$ since $f(x)$ can either be $0/1$ and $0 \\oplus 0 = 0$ and $0 \\oplus 1 = 1$.\n",
"If $y = 0$, then $U_f\\ket{x}\\ket{y} = U_f\\ket{x}\\ket{0} = \\ket{x}\\ket{0 \\oplus f(x)} = \\ket{x}\\ket{f(x)}$, since $f(x)$ can either be $0$ or $1$ and $0 \\oplus 0 = 0$ and $0 \\oplus 1 = 1$.\n",
"\n",
"This is remarkable because by setting $\\ket{y} = \\ket{0}$, we can extract the value of $f(x)$ by measuring the value of the second qubit. \n",
" \n",
Expand Down Expand Up @@ -213,7 +210,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Deutschs' Algorithm: \n",
"## Deutsch's Algorithm: \n",
"\n",
"Our aim is to find out if $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$ is a constant or a balanced function? If constant, $f(0) = f(1)$, and if balanced, $f(0) \\neq f(1)$.\n",
"\n",
Expand Down Expand Up @@ -296,18 +293,9 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/local/lib/python3.10/dist-packages/qutip/__init__.py:66: UserWarning: The new version of Cython, (>= 3.0.0) is not supported.\n",
" warnings.warn(\n"
]
}
],
"outputs": [],
"source": [
"# Import the CUDA-Q package and set the target to run on NVIDIA GPUs.\n",
"\n",
Expand Down Expand Up @@ -391,6 +379,17 @@
"elif np.array(result)[0] == '1':\n",
" print('f(x) is a balanced function')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This algorithm can be generalized to determine if a $n$-bit function $f:{0,1}^n\\longrightarrow {0,1}$ is constant or a balanced with only $\\frac{n}{2}$ function evaluations, for $n$ even. A function if balanced if half of the inputs map to $0$ and half map to $1$. \n",
"\n",
"Here we must assume that the function that we are given is either constant or balanced since there are $n$-bit functions that are neither constant, nor balanced. For instance the $2$-bit function $f(b_0,b_1) = \\max(b_0,b_1)$ is neither balanced, nor constant.\n",
"\n",
"A hint on how you might approach this problem is to first solve the problem for $n=2$ and see if you can then use that approach to handle $n$-bit functions for larger values of $n$."
]
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
type=str,
choices=["qpp-cpu", "nvidia", "nvidia-mgpu"],
help=
"Quantum simulator backend. Default is qpp-cpu. See https://nvidia.github.io/cuda-quantum/0.6.0/using/simulators.html for more options.",
"Quantum simulator backend. Default is qpp-cpu. See https://nvidia.github.io/cuda-quantum for more options.",
)
argparser.add_argument(
"-d",
Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/applications/python/vqe_advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[\u001b[38;2;255;000;000mwarning\u001b[0m] Target \u001b[38;2;000;000;255mnvidia-mqpu\u001b[0m: \u001b[38;2;000;000;255mThis target is deprecating. Please use the 'nvidia' target with option 'mqpu,fp32' or 'mqpu' (fp32 is the default precision option) by adding the command line option '--target-option mqpu,fp32' or passing it as cudaq.set_target('nvidia', option='mqpu,fp32') in Python. Please refer to CUDA-Q \u001b]8;;https://nvidia.github.io/cuda-quantum/latest/using/backends/platform.html#nvidia-mqpu-platform\u001b\\documentation\u001b]8;;\u001b\\ for more information.\u001b[0m\n"
"[\u001b[38;2;255;000;000mwarning\u001b[0m] Target \u001b[38;2;000;000;255mnvidia-mqpu\u001b[0m: \u001b[38;2;000;000;255mThis target is deprecating. Please use the 'nvidia' target with option 'mqpu,fp32' or 'mqpu' (fp32 is the default precision option) by adding the command line option '--target-option mqpu,fp32' or passing it as cudaq.set_target('nvidia', option='mqpu,fp32') in Python. Please refer to CUDA-Q \u001b]8;;https://nvidia.github.io/cuda-quantum/latest/using/backends/platform\u001b\\documentation\u001b]8;;\u001b\\ for more information.\u001b[0m\n"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/examples/python/building_kernels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"### Applying Gates\n",
"\n",
"\n",
"After a kernel is constructed, gates can be applied to start building out a quantum circuit. All the predefined gates in CUDA-Q can be found [here](https://nvidia.github.io/cuda-quantum/latest/api/default_ops.html#unitary-operations-on-qubits).\n",
"After a kernel is constructed, gates can be applied to start building out a quantum circuit. All the predefined gates in CUDA-Q can be found [here](https://nvidia.github.io/cuda-quantum/latest/api/default_ops).\n",
"\n",
"\n",
"Gates can be applied to all qubits in a register:"
Expand Down
4 changes: 3 additions & 1 deletion docs/sphinx/examples/python/building_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def kernel(state: cudaq.State):
# ### Applying Gates
#
#
# After a kernel is constructed, gates can be applied to start building out a quantum circuit. All the predefined gates in CUDA-Q can be found [here](https://nvidia.github.io/cuda-quantum/latest/api/default_ops.html#unitary-operations-on-qubits).
# After a kernel is constructed, gates can be applied to start building out a quantum circuit.
# All the predefined gates in CUDA-Q can be found here:
# https://nvidia.github.io/cuda-quantum/api/default_ops.
#
#
# Gates can be applied to all qubits in a register:
Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/examples/python/executing_kernels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"source": [
"Note that there is a subtle difference between how `sample` is executed with the target device set to a simulator or with the target device set to a QPU. In simulation mode, the quantum state is built once and then sampled $s$ times where $s$ equals the `shots_count`. In hardware execution mode, the quantum state collapses upon measurement and hence needs to be rebuilt over and over again.\n",
"\n",
"There are a number of helpful tools that can be found in the API [here](https://nvidia.github.io/cuda-quantum/latest/api/languages/python_api.html#cudaq.SampleResult) to process the `Sample_Result` object produced by `sample`."
"There are a number of helpful tools that can be found in the [API docs](https://nvidia.github.io/cuda-quantum/latest/api/languages/python_api) to process the `Sample_Result` object produced by `sample`."
]
},
{
Expand Down
Loading

0 comments on commit d5c9a04

Please sign in to comment.