Skip to content

Commit

Permalink
Updates for 0.52.0
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-naveh committed Oct 8, 2024
1 parent 0c4dc44 commit f073698
Show file tree
Hide file tree
Showing 69 changed files with 477 additions and 1,627 deletions.
55 changes: 0 additions & 55 deletions .github/actions/run-tests/action.yml

This file was deleted.

10 changes: 0 additions & 10 deletions .github/scripts/get_m2m_token.sh

This file was deleted.

46 changes: 9 additions & 37 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
name: "Test notebooks old"
name: "Test notebooks"

on:
pull_request:
push:
branches:
- dev
on: [pull_request]

jobs:
tests:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: "Install dependencies"
run: |
python -m pip install -U -r requirements.txt
python -m pip install -U -r requirements_tests.txt
- name: Get changed files - all
id: changed-files-all
Expand All @@ -29,51 +26,26 @@ jobs:
files: |
**.ipynb
- uses: aws-actions/[email protected]
with:
role-to-assume: ${{ secrets.AWS_ROLE }}
aws-region: us-east-1
mask-aws-account-id: true

- name: Set environment variables
run: |
set -ex
echo "CLASSIQ_TEXT_ONLY=true" >> $GITHUB_ENV
if [ "${{ github.event_name }}" == 'pull_request' ]; then
echo "SHOULD_TEST_ALL_FILES=false" >> $GITHUB_ENV
echo "HAS_ANY_FILE_CHANGED=${{ steps.changed-files-all.outputs.any_changed }}" >> $GITHUB_ENV
echo "LIST_OF_FILE_CHANGED=${{ steps.changed-files-all.outputs.all_changed_files }}" >> $GITHUB_ENV
echo "HAS_ANY_IPYNB_CHANGED=${{ steps.changed-files-ipynb.outputs.any_changed }}" >> $GITHUB_ENV
echo "LIST_OF_IPYNB_CHANGED=${{ steps.changed-files-ipynb.outputs.all_changed_files }}" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == 'workflow_dispatch' || "${{ github.head_ref || github.ref_name }}" == "dev" ]]; then
elif [ "${{ github.event_name }}" == 'workflow_dispatch' ]; then
echo "SHOULD_TEST_ALL_FILES=true" >> $GITHUB_ENV
echo "HAS_ANY_FILE_CHANGED=None" >> $GITHUB_ENV
echo "LIST_OF_FILE_CHANGED=None" >> $GITHUB_ENV
echo "HAS_ANY_IPYNB_CHANGED=None" >> $GITHUB_ENV
echo "LIST_OF_IPYNB_CHANGED=None" >> $GITHUB_ENV
fi
if [ "${{ github.head_ref || github.ref_name }}" == "dev" ]; then
echo "CLASSIQ_IDE=https://nightly.platform.classiq.io" >> $GITHUB_ENV
echo "CLASSIQ_HOST=https://staging.api.classiq.io" >> $GITHUB_ENV
echo "IS_DEV=true" >> $GITHUB_ENV
fi
- name: Set authentication
run: .github/scripts/get_m2m_token.sh
env:
PROD_M2M_SECRET_ARN: "${{ secrets.PROD_M2M_SECRET_ARN }}"
NIGHTLY_M2M_SECRET_ARN: "${{ secrets.NIGHTLY_M2M_SECRET_ARN }}"

- name: Install dependencies
run: |
set -e
# Pre is needed for Dev pre releases
python -m pip install --extra-index-url https://pypi.org/simple --pre -U -r requirements.txt
python -m pip install --extra-index-url https://pypi.org/simple -U -r requirements_tests.txt
run: echo "${{ secrets.CLASSIQ_CREDENTIALS_B64 }}" | base64 --decode > "${HOME}/.classiq-credentials"

- name: "Run tests"
run: python -m pytest --log-cli-level=INFO tests
run: python -m pytest tests
env:
JUPYTER_PLATFORM_DIRS: "1"
108 changes: 0 additions & 108 deletions .github/workflows/test-CI.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ show(quantum_program)

result = execute(quantum_program).result()
print(result[0].value.parsed_counts)
# [{'res': 1.0}: 1000]
# [{'res': 1}: 1000]
```

Let's unravel the code above:
Expand Down
34 changes: 17 additions & 17 deletions algorithms/deutsch_jozsa/deutsch_jozsa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"tags": []
},
"source": [
"The Deutsch-Jozsa algorithm [[1](#DJWiki)], named after David Deutsch and Richard Jozsa, is one of the fundamental and first quantum algorithms showing exponential speedup over their classical counterpart$^*$. While it has no practical applicative usage, it serves as a toy model for quantum computing, demonstrating how the concepts of super-position and interference enable quantum algorithms to overperform classical ones."
"The Deutsch-Jozsa algorithm [[1](#DJWiki)], named after David Deutsch and Richard Jozsa, is one of the first fundamental quantum algorithms showing exponential speedup over its classical counterpart$^*$. While it has no practical applicative use, it serves as a toy model for quantum computing, demonstrating how the concepts of superposition and interference enable quantum algorithms to outperform classical ones."
]
},
{
Expand All @@ -36,22 +36,22 @@
"source": [
"The algorithm treats the following problem:\n",
"\n",
"* **Input:** A black-box boolean function $f(x)$ that acts on the integers in the range $[0, 2^{n}-1]$.\n",
"* **Input:** A black box Boolean function $f(x)$ that acts on the integers in the range $[0, 2^{n}-1]$.\n",
"\n",
"* **Promise:** The function is either constant or balanced (for half of the values it is 1 and for the other half it is 0).\n",
"\n",
"* **Output:** Whether the function is constant or balanced.\n",
"\n",
"\n",
"$^*$ The exponential speedup is in the oracle complexity setting. In addition, it only refers to deterministic classical machines.\n",
"$^*$ The exponential speedup is in the oracle complexity setting. It only refers to deterministic classical machines.\n",
"\n",
"***\n",
"\n",
"\n",
"Problem hardeness: If we require a deterministic answer to the problem, classically, we have to inquire the oracle $2^{n-1}+1$ times in the worst case. **The quantum approach requires a single query, thus, introducing a clear exponential speedup**. (Without requiring deterministic determination, namely, allowing application of classical probabilistic algorithm to get the result up to some error, then the exponential speedup is lost: taking $k$ classical evaluations of the function $f$ determines whether the function is constant or balanced, with a probability $1-1/2^k$).\n",
"Problem hardness: If we require a deterministic answer to the problem, classically, we have to inquire of the oracle $2^{n-1}+1$ times in the worst case. **The quantum approach requires a single query, thus, introducing a clear exponential speedup**. (Without requiring deterministic determination, namely, allowing application of the classical probabilistic algorithm to get the result up to some error, then the exponential speedup is lost: taking $k$ classical evaluations of the function $f$ determines whether the function is constant or balanced, with a probability of $1-1/2^k$).\n",
"\n",
"\n",
"Next, we define the Deutsch-Jozsa algorithm, which has a [quantum part](#The-Quantum-Part) and a [classical postprocess part](#The-Classical-Postprocess). Then, we run the algorithm on two different examples, one with a [simple](#Example:-Simple-Arithmetic-Oracle) $f(x)$ and another that is [more complex](#Example:-Complex-Arithmetic-Oracle). A [mathematical explanation](#Technical-Notes) of the algorithm is provided at the end of this notebook.\n"
"We define the Deutsch-Jozsa algorithm, which has a [quantum part](#The-Quantum-Part) and a [classical postprocess part](#The-Classical-Postprocess). Then, we run the algorithm on two different examples, one with a [simple](#Example:-Simple-Arithmetic-Oracle) $f(x)$ and another that is [more complex](#Example:-Complex-Arithmetic-Oracle). A [mathematical explanation](#Technical-Notes) of the algorithm is provided at the end of this notebook.\n"
]
},
{
Expand Down Expand Up @@ -80,7 +80,7 @@
"jp-MarkdownHeadingCollapsed": true
},
"source": [
"We start with defining a `deutsch_jozsa` quantum function, whose arguments are a quantum function for the black-box $f(x)$, and a quantum variable on which it acts, $x$. The Deutsch-Jozsa algorithm is composed of three quantum blocks (see Figure 1): a Hadamard transform, an arithmetic oracle for the black-box function, and another Hadamard transform. "
"We define a `deutsch_jozsa` quantum function whose arguments are a quantum function for the black box $f(x)$, and a quantum variable on which it acts, $x$. The Deutsch-Jozsa algorithm comprising three quantum blocks (see Figure 1): a Hadamard transform, an arithmetic oracle for the black box function, and another Hadamard transform. "
]
},
{
Expand Down Expand Up @@ -136,7 +136,7 @@
"### The Classical Postprocess\n",
"\n",
"The classical part of the algorithm reads: The probability of measuring the $|0\\rangle_n$ state is 1 if the function is constant and 0 if it is balanced. \n",
"We define a classical function that gets the execution results from running quantum part and returns whether the function is constant or balanced:"
"We define a classical function that gets the execution results from running the quantum part and returns whether the function is constant or balanced:"
]
},
{
Expand Down Expand Up @@ -185,15 +185,15 @@
"tags": []
},
"source": [
"We start with a simple example on $n=4$ qubits, and $f(x)= x >7$. Classicaly, in the worst case, the function should be evaluated $2^{n-1}+1=9$ times. However, with the Deutsch-Jozsa algorithm, this function is evaluated only once."
"We start with a simple example on $n=4$ qubits, and $f(x)= x >7$. Classically, in the worst case, the function should be evaluated $2^{n-1}+1=9$ times. However, with the Deutsch-Jozsa algorithm, this function is evaluated only once."
]
},
{
"cell_type": "markdown",
"id": "88600df9-cfb9-46a1-b710-c3706c8d99f9",
"metadata": {},
"source": [
"We need to build a predicate for the specific use case:"
"We build a predicate for this specific use case:"
]
},
{
Expand Down Expand Up @@ -255,7 +255,7 @@
"id": "ee250190-ba84-4a08-a9fa-067ea448d2f6",
"metadata": {},
"source": [
"Finally, we execute and call the classical post process:"
"Finally, we execute and call the classical postprocess:"
]
},
{
Expand Down Expand Up @@ -323,9 +323,9 @@
"id": "66e01d1f-0fb5-4a18-b44d-25b5cfe05bf2",
"metadata": {},
"source": [
"*Generalizing to more complex scenarios makes no difference for modeling*. Let us take a complicated function, working with $n=3$: a function $f(x)$ that first takes the maximum between the input Bitwise-Xor with 4 and the input Bitwise-And with 3, then checks whether the result is greater or equal to 4. Can you tell whether the function is balanced or constant?\n",
"*Generalizing to more complex scenarios makes no difference for modeling*. Let us take a complicated function, working with $n=3$: a function $f(x)$ that first takes the maximum between the input bitwise-xor with 4 and the input bitwise-and with 3, then checks whether the result is greater or equal to 4. Can you tell whether the function is balanced or constant?\n",
"\n",
"*This time we provide a width bound to the Synthesis engine.*"
"*This time we provide a width bound to the synthesis engine.*"
]
},
{
Expand Down Expand Up @@ -399,7 +399,7 @@
"id": "bd43e848-54d2-4be5-911d-1ea4d661bc5a",
"metadata": {},
"source": [
"We can visualize the circuit obtained from the synthesis engine. Figure 2 presents the complex structure of the oracle, generated automatically by the Synthesis engine."
"We can visualize the circuit obtained from the synthesis engine. Figure 2 presents the complex structure of the oracle, generated automatically by the synthesis engine."
]
},
{
Expand Down Expand Up @@ -434,15 +434,15 @@
"source": [
"## Technical Notes\n",
"\n",
"A brief summary of the linear algebra behind the Deutsch-Jozsa algorithm. The first Hadamard transformation generates an equal super-position over all the standard basis elements:\n",
"A brief summary of the linear algebra behind the Deutsch-Jozsa algorithm. The first Hadamard transformation generates an equal superposition over all the standard basis elements:\n",
"$$\n",
"|0\\rangle_n \\xrightarrow[H^{\\otimes n}]{} \\frac{1}{2^{n/2}}\\sum^{2^n-1}_{j=0}|j\\rangle_n.\n",
"$$\n",
"Arithmetic oracle gets a boolean function and adds an $e^{\\pi i}=-1$ phase to all states for which the function returns True:\n",
"The arithmetic oracle gets a Boolean function and adds an $e^{\\pi i}=-1$ phase to all states for which the function returns true:\n",
"$$\n",
"\\frac{1}{2^{n/2}}\\sum^{2^n-1}_{j=0}|j\\rangle_n \\xrightarrow[\\text{Oracle}(f(j))]{}\\frac{1}{2^{n/2}}\\sum^{2^n-1}_{j=0}(-1)^{f(j)}|j\\rangle_n.\n",
"$$\n",
"Finally, application of the Hadamard transform, which can be written as $H^{\\otimes n}\\equiv \\frac{1}{2^{n/2}}\\sum^{2^n-1}_{k,l=0}(-1)^{k\\cdot l} |k\\rangle \\langle l| $, gives\n",
"Finally, applying the Hadamard transform, which can be written as $H^{\\otimes n}\\equiv \\frac{1}{2^{n/2}}\\sum^{2^n-1}_{k,l=0}(-1)^{k\\cdot l} |k\\rangle \\langle l| $, gives\n",
"$$\n",
"\\frac{1}{2^{n/2}}\\sum^{2^n-1}_{j=0}(-1)^{f(j)}|j\\rangle \\xrightarrow[H^{\\otimes n}]{} \n",
"\\sum^{2^n-1}_{k=0} \\left(\\frac{1}{2^{n}}\\sum^{2^n-1}_{j=0}(-1)^{f(j)+j\\cdot k} \\right) |k\\rangle.\n",
Expand All @@ -454,7 +454,7 @@
"\\left\\{\n",
"\\begin{array}{l l}\n",
"1 & \\text{if } f(x) \\text{ is constant} \\\\\n",
"0 & \\text{if } f(x) \\text{ is balanced}\n",
"0 & \\text{if } f(x) \\text{ is balanced.}\n",
"\\end{array}\n",
"\\right.\n",
"$$"
Expand Down
Loading

0 comments on commit f073698

Please sign in to comment.