diff --git a/.github/actions/run-tests/action.yml b/.github/actions/run-tests/action.yml
deleted file mode 100644
index 76030b78..00000000
--- a/.github/actions/run-tests/action.yml
+++ /dev/null
@@ -1,55 +0,0 @@
-name: "Test Notebooks Action"
-description: "Runs tests on a list of notebooks based on the specified environment."
-
-inputs:
- # diff files - set to python inside pytest
- should_test_all_files:
- description: "'true' / 'false'."
- required: true
- list_of_ipynb_changed:
- description: "The list of changed files."
- required: true
- # aws environment
- is_dev:
- description: "The secret for environment authentication."
- required: true
- m2m_secret_arn:
- description: "The secret for environment authentication."
- required: true
- aws_role:
- description: "The AWS role to assume for configuring credentials during the execution."
- required: true
- # environment
- classiq_ide:
- description: "The secret for environment authentication."
- required: true
- classiq_host:
- description: "The secret for environment authentication."
- required: true
-
-runs:
- using: "composite"
- steps:
- - uses: aws-actions/configure-aws-credentials@v4.0.2
- with:
- role-to-assume: ${{ inputs.aws_role }}
- aws-region: us-east-1
- mask-aws-account-id: true
-
- - name: Set authentication
- run: .github/scripts/get_m2m_token.sh
- shell: bash
- env:
- IS_DEV: "${{ inputs.is_dev }}"
- M2M_SECRET_ARN: "${{ inputs.m2m_secret_arn }}"
-
- - name: Run Notebooks
- run: python -m pytest --log-cli-level=INFO tests
- env:
- JUPYTER_PLATFORM_DIRS: "1"
- SHOULD_TEST_ALL_FILES: "${{ inputs.should_test_all_files }}"
- LIST_OF_IPYNB_CHANGED: "${{ inputs.list_of_ipynb_changed }}"
- CLASSIQ_IDE: "${{ inputs.classiq_ide }}"
- CLASSIQ_HOST: "${{ inputs.classiq_host }}"
-
- shell: bash
diff --git a/.github/scripts/get_m2m_token.sh b/.github/scripts/get_m2m_token.sh
deleted file mode 100755
index 55470e34..00000000
--- a/.github/scripts/get_m2m_token.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/bash
-set -e
-
-export SECRET_ARN=$M2M_SECRET_ARN
-if [ "$IS_DEV" = "true" ]; then
- aws codeartifact login --tool pip --domain classiq-cadmium --repository Pypi-Classiq-Non-Prod
-fi
-
-aws secretsmanager get-secret-value --secret-id "$SECRET_ARN" | \
-jq '{"classiqTokenAccount": .SecretString | fromjson | .access_token }' > "${HOME}/.classiq-credentials"
diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml
index db3331f9..25f55480 100644
--- a/.github/workflows/run_tests.yml
+++ b/.github/workflows/run_tests.yml
@@ -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
@@ -29,24 +26,15 @@ jobs:
files: |
**.ipynb
- - uses: aws-actions/configure-aws-credentials@v4.0.2
- 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
@@ -54,26 +42,10 @@ jobs:
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"
diff --git a/.github/workflows/test-CI.yml b/.github/workflows/test-CI.yml
deleted file mode 100644
index 742e19e4..00000000
--- a/.github/workflows/test-CI.yml
+++ /dev/null
@@ -1,108 +0,0 @@
-name: Test Library CI
-
-on:
- # Trigger the workflow on push to the specific branch
- push:
- branches:
- - dev
- - main
- -
- # Trigger the workflow on pull requests targeting the specific branch
- pull_request_target: # Note: `pull_request_target` ensures that the tests run in the context of the `main` branch, not in the user's fork. This has important security implications and should not be changed to `pull_request`
- # types: [opened, synchronize] # Triggered when PR is open or updated with new commit
- branches:
- - dev
- - main
-
- # Add a manual trigger option for running the workflow
- workflow_dispatch:
-
-jobs:
- test:
- permissions:
- id-token: write
- contents: read
-
- runs-on: ubuntu-latest
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@v4
-
- - name: Set up Python
- uses: actions/setup-python@v5
- with:
- python-version: "3.11"
-
- - 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
-
- # A bunch of if-else. Might move to an action
- # Decide environment based on the target branch (for both push and PR events)
- - name: Set environment based on target branch
- run: |
- set -ex
- if [[ "${{ github.event_name }}" == "pull_request" ]]; then
- # Use the target branch of the pull request
- target_branch="${{ github.event.pull_request.base.ref }}"
- else
- # Use the branch of the push event
- # todo: verify that dispatch works
- target_branch="${{ github.ref_name }}"
- fi
-
- if [[ "$target_branch" == "main" ]]; then
- echo "Running on prod environment."
-
- echo "M2M_SECRET_ARN=${{ secrets.PROD_M2M_SECRET_ARN }}" >> $GITHUB_ENV
-
- echo "CLASSIQ_IDE=https://platform.classiq.io" >> $GITHUB_ENV
- echo "CLASSIQ_HOST=https://api.classiq.io" >> $GITHUB_ENV
- echo "IS_DEV=false" >> $GITHUB_ENV
- else
- echo "Running on dev environment."
-
- echo "M2M_SECRET_ARN=${{ secrets.NIGHTLY_M2M_SECRET_ARN }}" >> $GITHUB_ENV
-
- 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
- shell: bash
-
- # The following 2 steps can also be grouped into one action
- # Step to detect changed .ipynb files
- - name: Get changed notebook files
- id: changed-files
- uses: tj-actions/changed-files@v44
- with:
- files: |
- **/*.ipynb
- - name: Set changed notebook into environment variables
- run: |
- set -ex
- if [ "${{ github.event_name }}" == 'pull_request' ]; then
- echo "SHOULD_TEST_ALL_FILES=false" >> $GITHUB_ENV
- elif [[ "${{ github.event_name }}" == 'workflow_dispatch' || "${{ github.head_ref || github.ref_name }}" == "dev" ]]; then
- echo "SHOULD_TEST_ALL_FILES=true" >> $GITHUB_ENV
- fi
-
- # Run notebook tests if any changed notebooks are detected
- - name: Run notebook tests
- if: steps.changed-files.outputs.any_changed == 'true'
- uses: ./.github/actions/run-tests # Calls your composite action
- with:
- # diff files - set to python inside pytest
- should_test_all_files: ${{ env.SHOULD_TEST_ALL_FILES }}
- list_of_ipynb_changed: ${{ steps.changed-files-ipynb.outputs.all_changed_files }}
- # aws environment
- m2m_secret_arn: ${{ env.M2M_SECRET_ARN }}
- aws_role: ${{ secrets.AWS_ROLE }}
- is_dev: ${{ env.IS_DEV }}
- # environment
- classiq_ide: ${{ env.CLASSIQ_IDE }}
- classiq_host: ${{ env.CLASSIQ_HOST }}
diff --git a/README.md b/README.md
index 9d1a2ba0..0bd8d351 100644
--- a/README.md
+++ b/README.md
@@ -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:
diff --git a/algorithms/deutsch_jozsa/deutsch_jozsa.ipynb b/algorithms/deutsch_jozsa/deutsch_jozsa.ipynb
index 4e5d446a..46fc9aad 100644
--- a/algorithms/deutsch_jozsa/deutsch_jozsa.ipynb
+++ b/algorithms/deutsch_jozsa/deutsch_jozsa.ipynb
@@ -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."
]
},
{
@@ -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"
]
},
{
@@ -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. "
]
},
{
@@ -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:"
]
},
{
@@ -185,7 +185,7 @@
"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."
]
},
{
@@ -193,7 +193,7 @@
"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:"
]
},
{
@@ -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:"
]
},
{
@@ -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.*"
]
},
{
@@ -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."
]
},
{
@@ -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",
@@ -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",
"$$"
diff --git a/algorithms/grover/3_sat_grover/3_sat_grover.ipynb b/algorithms/grover/3_sat_grover/3_sat_grover.ipynb
index 265e0185..467ae19d 100644
--- a/algorithms/grover/3_sat_grover/3_sat_grover.ipynb
+++ b/algorithms/grover/3_sat_grover/3_sat_grover.ipynb
@@ -13,12 +13,10 @@
"\n",
"# Demo: Solving 3-SAT Using Grover's Algorithm\n",
"\n",
- "## Introduction\n",
- "\n",
- "Grover's algorithm [[1](#Gro97),[2](#GroWiki)] is a quantum search algorithm that enables searching a dataset of $N$ items using $O(\\sqrt{N})$ queries, in contrast to classical algorithms which require $\\Omega(N)$ queries in the worst case. Using the algorithm allows us to speed-up various computations that are considered classically intractable.\n",
+ "Grover's algorithm [[1](#Gro97),[2](#GroWiki)] is a quantum search algorithm that enables searching a dataset of $N$ items using $O(\\sqrt{N})$ queries, in contrast to classical algorithms that require $\\Omega(N)$ queries in the worst case. Using the algorithm allows us to speed up various computations that are considered classically intractable.\n",
"For example, the 3-SAT problem [[3](#3SAT)] is a famous $\\text{NP-Complete}$ problem, a solution of which allows solving any problem in the complexity class $\\text{NP}$.\n",
"\n",
- "In this demo, we will show how the Classiq platform enables us to solve an instance of 3-SAT using Grover's algorithm at a higher functional level, avoiding the implementation details one is usually exposed to when using other platforms.\n"
+ "In this demo, we show how the Classiq platform enables us to solve an instance of 3-SAT using Grover's algorithm at a higher functional level, avoiding the implementation details you encounter when using other platforms.\n"
]
},
{
@@ -32,7 +30,7 @@
"source": [
"## The 3-SAT Formula\n",
"\n",
- "We now specify the 3-CNF [[4](#CNF)] formula that we wish to find a solution for:\n",
+ "We now specify the 3-CNF [[4](#CNF)] formula that requires a solution:\n",
"$$ (x_1 \\lor x_2 \\lor x_3) \\land (\\neg x_1 \\lor x_2 \\lor x_3) \\land (\\neg x_1 \\lor \\neg x_2 \\lor \\neg x_3) \\land (\\neg x_1 \\lor \\neg x_2 \\lor x_3) \\land (x_1 \\lor x_2 \\lor \\neg x_3) \\land (\\neg x_1 \\lor x_2 \\lor \\neg x_3) $$"
]
},
@@ -94,7 +92,7 @@
"id": "3832b859-65b3-4e94-8e76-cf302eea08ea",
"metadata": {},
"source": [
- "We can see that the formula has 2 possible solutions:"
+ "We can see that the formula has two possible solutions:"
]
},
{
@@ -133,15 +131,15 @@
}
},
"source": [
- "Note that since there are multiple satisfying assignments for the formula, the goal of the Grover quantum algorithm is to find one of them.\n",
+ "We note that since there are multiple satisfying assignments for the formula, the goal of the Grover quantum algorithm is to find one of them.\n",
"This is contrast to the usual description of the search problem (found in [2](#GroWiki)), in which there is a single solution (out of $N$ possibilities).\n",
"\n",
- "## Loading the Grover search model\n",
+ "## Loading the Grover Search Model\n",
"\n",
- "Next, we load the Grover search model which we use to find the solution. To specify the model, we need to define the oracle it uses. Each oracle call is analogous to a classical query. In this case, we define an oracle based on the 3-CNF formula defined earlier. We use the standard `phase_oracle` that transforms 'digital' oracle, i.e. $|x\\rangle|0\\rangle \\rightarrow |x\\rangle|f(x)\\rangle$ to a phase oracle $|x\\rangle \\rightarrow (-1)^{f(x)}|x\\rangle$.\n",
+ "We load the Grover search model for finding the solution. To specify the model, we define the oracle it uses. Each oracle call is analogous to a classical query. In this case, we define an oracle based on the 3-CNF formula defined earlier, using the standard `phase_oracle` that transforms 'digital' oracle; i.e., $|x\\rangle|0\\rangle \\rightarrow |x\\rangle|f(x)\\rangle$ to a phase oracle $|x\\rangle \\rightarrow (-1)^{f(x)}|x\\rangle$.\n",
"\n",
"\n",
- "In addition, we define the number of grover operator repetitions in the model (which is based on the frequency of solutions in the search space), this time 1 repetition is all needed."
+ "In addition, we define the number of Grover operator repetitions in the model (which is based on the frequency of solutions in the search space). This time, only one repetition is needed."
]
},
{
@@ -189,7 +187,7 @@
"source": [
"## Synthesizing the Circuit\n",
"\n",
- "We proceed by synthesizing the circuit using Classiq's synthesis engine. The synthesis should take approximately several seconds:"
+ "We synthesize the circuit using the Classiq synthesis engine. The synthesis takes several seconds:"
]
},
{
@@ -216,7 +214,7 @@
"source": [
"## Showing the Resulting Circuit\n",
"\n",
- "After Classiq's synthesis engine has finished the job, we can show the resulting circuit in the interactive GUI:"
+ "Once the Classiq synthesis engine finishes the job, we can show the resulting circuit in the interactive GUI:"
]
},
{
@@ -248,9 +246,9 @@
}
},
"source": [
- "## Executing the circuit\n",
+ "## Executing the Circuit\n",
"\n",
- "Lastly, we can execute the resulting circuit with Classiq's execute interface, using the `execute` function."
+ "Lastly, we run the resulting circuit with the Classiq execute interface using the `execute` function."
]
},
{
@@ -274,7 +272,7 @@
}
},
"source": [
- "Printing out the result, we see that our execution of Grover's algorithm successfully found the satisfying assignments for the input formula:"
+ "Upon printing the result, we see that our execution of Grover's algorithm successfully found the satisfying assignments for the input formula:"
]
},
{
@@ -315,7 +313,7 @@
"id": "d73514b2-03bb-4b05-9ee7-98a1e314e0da",
"metadata": {},
"source": [
- "# Large 3-SAT example"
+ "# Large 3-SAT Example"
]
},
{
@@ -323,7 +321,7 @@
"id": "ece3be60-21d5-49a1-9c65-8081e4ecce2d",
"metadata": {},
"source": [
- "We now domenstrate on a larger example:"
+ "We now demonstrate on a larger example:"
]
},
{
@@ -479,7 +477,7 @@
"\n",
"# References\n",
"\n",
- "[1]: [Grover, Lov K. \"Quantum mechanics helps in searching for a needle in a haystack.\" Physical review letters 79.2 (1997): 325.](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.79.325)\n",
+ "[1]: [Grover, Lov K. \"Quantum mechanics helps in searching for a needle in a haystack.\" Physical Review Letters 79.2 (1997): 325.](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.79.325)\n",
"\n",
"[2]: [Grover's algorithm (Wikipedia)](https://en.wikipedia.org/wiki/Grover%27s_algorithm)\n",
"\n",
diff --git a/algorithms/swap_test/swap_test.ipynb b/algorithms/swap_test/swap_test.ipynb
index 45a438e3..ddf14e44 100644
--- a/algorithms/swap_test/swap_test.ipynb
+++ b/algorithms/swap_test/swap_test.ipynb
@@ -81,24 +81,11 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " create_model,\n",
- " execute,\n",
- " prepare_amplitudes,\n",
- " qfunc,\n",
- " set_execution_preferences,\n",
- " swap_test,\n",
- " synthesize,\n",
- ")\n",
- "from classiq.execution import ExecutionPreferences\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
"def main(test: Output[QBit]):\n",
- "\n",
" state1 = QArray(\"state1\")\n",
" state2 = QArray(\"state2\")\n",
" prepare_amplitudes(amps1.tolist(), 0.0, state1)\n",
@@ -107,10 +94,10 @@
"\n",
"\n",
"qmod = create_model(main)\n",
- "qmod = set_execution_preferences(\n",
- " qmod, execution_preferences=ExecutionPreferences(num_shots=100_000)\n",
- ")\n",
- "qprog = synthesize(qmod)"
+ "qmod = set_execution_preferences(qmod, num_shots=100_000)\n",
+ "write_qmod(qmod, \"swap_test\", decimal_precision=15)\n",
+ "qprog = synthesize(qmod)\n",
+ "show(qprog)"
]
},
{
@@ -123,52 +110,6 @@
"Users can easily add their own functions"
]
},
- {
- "cell_type": "code",
- "execution_count": 3,
- "id": "071fefd6-0e34-441c-b4f0-7ebb86586d6e",
- "metadata": {
- "execution": {
- "iopub.execute_input": "2024-05-07T14:31:03.344383Z",
- "iopub.status.busy": "2024-05-07T14:31:03.342895Z",
- "iopub.status.idle": "2024-05-07T14:31:03.507873Z",
- "shell.execute_reply": "2024-05-07T14:31:03.507220Z"
- }
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Opening: https://platform.classiq.io/circuit/56682c53-15bf-4d1f-81e2-1121ce978b16?version=0.41.0.dev39%2B79c8fd0855\n"
- ]
- }
- ],
- "source": [
- "from classiq import show\n",
- "\n",
- "show(qprog)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "id": "53828e56-cb64-4c7d-8624-92ecfd3b7e81",
- "metadata": {
- "execution": {
- "iopub.execute_input": "2024-05-07T14:31:03.516412Z",
- "iopub.status.busy": "2024-05-07T14:31:03.511049Z",
- "iopub.status.idle": "2024-05-07T14:31:03.529974Z",
- "shell.execute_reply": "2024-05-07T14:31:03.529336Z"
- }
- },
- "outputs": [],
- "source": [
- "from classiq import write_qmod\n",
- "\n",
- "write_qmod(qmod, \"swap_test\", decimal_precision=15)"
- ]
- },
{
"cell_type": "markdown",
"id": "7df3372c-02dd-4026-ac7b-042492e3cb31",
@@ -191,7 +132,7 @@
},
"outputs": [],
"source": [
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -224,7 +165,7 @@
"outputs": [],
"source": [
"overlap_from_swap_test = np.sqrt(\n",
- " 2 * res[0].value.counts[\"0\"] / sum(res[0].value.counts.values()) - 1\n",
+ " 2 * result.counts[\"0\"] / sum(result.counts.values()) - 1\n",
")\n",
"exact_overlap = np.abs(amps1 @ amps2)"
]
diff --git a/applications/chemistry/molecular_energy_curve/molecular_energy_curve.ipynb b/applications/chemistry/molecular_energy_curve/molecular_energy_curve.ipynb
index 2d515409..11339bd4 100644
--- a/applications/chemistry/molecular_energy_curve/molecular_energy_curve.ipynb
+++ b/applications/chemistry/molecular_energy_curve/molecular_energy_curve.ipynb
@@ -299,9 +299,7 @@
"outputs": [],
"source": [
"# save the last model to a qmod file\n",
- "from classiq import write_qmod\n",
- "\n",
- "write_qmod(qmod, name=\"molecular_energy_curve\")"
+ "write_qmod(qmod, \"molecular_energy_curve\")"
]
},
{
diff --git a/applications/chemistry/molecule_eigensolver/molecule_eigensolver.ipynb b/applications/chemistry/molecule_eigensolver/molecule_eigensolver.ipynb
index 7f618e70..f16f8597 100644
--- a/applications/chemistry/molecule_eigensolver/molecule_eigensolver.ipynb
+++ b/applications/chemistry/molecule_eigensolver/molecule_eigensolver.ipynb
@@ -297,28 +297,10 @@
" execution_preferences=ExecutionPreferences(\n",
" num_shots=1000, backend_preferences=backend_preferences\n",
" ),\n",
+ " out_file=\"molecule_eigensolver\",\n",
")"
]
},
- {
- "cell_type": "code",
- "execution_count": 6,
- "id": "f13599d2-e8e7-4165-aa26-8ae8d4bdafaa",
- "metadata": {
- "execution": {
- "iopub.execute_input": "2024-05-07T15:22:03.663419Z",
- "iopub.status.busy": "2024-05-07T15:22:03.663167Z",
- "iopub.status.idle": "2024-05-07T15:22:03.686164Z",
- "shell.execute_reply": "2024-05-07T15:22:03.685472Z"
- }
- },
- "outputs": [],
- "source": [
- "from classiq import write_qmod\n",
- "\n",
- "write_qmod(qmod, name=\"molecule_eigensolver\")"
- ]
- },
{
"cell_type": "code",
"execution_count": 7,
diff --git a/applications/finance/credit_card_fraud/credit_card_fraud.ipynb b/applications/finance/credit_card_fraud/credit_card_fraud.ipynb
index 2dd11c19..6ca6b527 100644
--- a/applications/finance/credit_card_fraud/credit_card_fraud.ipynb
+++ b/applications/finance/credit_card_fraud/credit_card_fraud.ipynb
@@ -208,7 +208,7 @@
"source": [
"## Classiq imports\n",
"\n",
- "from classiq import Pauli, construct_qsvm_model, execute, show, synthesize\n",
+ "from classiq import *\n",
"from classiq.applications.qsvm import QSVMFeatureMapEntanglement"
]
},
@@ -1184,6 +1184,7 @@
" feature_map_function_name=pauli_zz_feature_map_function_name,\n",
" **pauli_zz_kwargs\n",
")\n",
+ "write_qmod(QSVM_FRAUD_PAULI_ZZ, \"credit_card_fraud\")\n",
"\n",
"QSVM_FRAUD_BLOCH_SHPERE = construct_qsvm_model(\n",
" train_data=FRAUD_TRAIN_DATA.tolist(),\n",
@@ -1206,25 +1207,6 @@
"For this we will use `classiq` built-in `synthesize` and `show` functions:"
]
},
- {
- "cell_type": "code",
- "execution_count": 21,
- "id": "fccf5210-84ee-4a9f-bc66-20ac655b6f93",
- "metadata": {
- "execution": {
- "iopub.execute_input": "2024-05-07T15:06:36.508303Z",
- "iopub.status.busy": "2024-05-07T15:06:36.507102Z",
- "iopub.status.idle": "2024-05-07T15:06:36.516205Z",
- "shell.execute_reply": "2024-05-07T15:06:36.515481Z"
- }
- },
- "outputs": [],
- "source": [
- "from classiq import write_qmod\n",
- "\n",
- "write_qmod(QSVM_FRAUD_PAULI_ZZ, \"credit_card_fraud\")"
- ]
- },
{
"cell_type": "code",
"execution_count": 22,
@@ -1304,7 +1286,7 @@
},
"outputs": [],
"source": [
- "results = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -1332,10 +1314,7 @@
}
],
"source": [
- "print(\n",
- " \"quantum kernel classification test score: %0.2f\"\n",
- " % (results[0].value[\"test_score\"])\n",
- ")"
+ "print(\"quantum kernel classification test score: %0.2f\" % (result[\"test_score\"]))"
]
},
{
@@ -1448,7 +1427,7 @@
],
"source": [
"true_labels = np.array(selected_prediction_true_labels.values.tolist())\n",
- "sklearn.metrics.accuracy_score(results[0].value[\"predicted_labels\"], true_labels)"
+ "sklearn.metrics.accuracy_score(result[\"predicted_labels\"], true_labels)"
]
},
{
diff --git a/applications/finance/option_pricing/option_pricing.ipynb b/applications/finance/option_pricing/option_pricing.ipynb
index a95a3919..44249c76 100644
--- a/applications/finance/option_pricing/option_pricing.ipynb
+++ b/applications/finance/option_pricing/option_pricing.ipynb
@@ -440,9 +440,12 @@
"metadata": {},
"outputs": [],
"source": [
- "constraints = Constraints(max_width=20)\n",
- "qmod = create_model(main, constraints=constraints, classical_execution_function=cmain)\n",
- "write_qmod(qmod, \"option_pricing\")"
+ "qmod = create_model(\n",
+ " main,\n",
+ " constraints=Constraints(max_width=20),\n",
+ " classical_execution_function=cmain,\n",
+ " out_file=\"option_pricing\",\n",
+ ")"
]
},
{
@@ -454,9 +457,7 @@
{
"name": "stdout",
"output_type": "stream",
- "text": [
- ""
- ]
+ "text": []
}
],
"source": [
@@ -479,8 +480,7 @@
"metadata": {},
"outputs": [],
"source": [
- "res = execute(qprog).result()\n",
- "iqae_res = res[0].value"
+ "result_iqae = execute(qprog).result_value()"
]
},
{
@@ -508,8 +508,8 @@
}
],
"source": [
- "measured_payoff = iqae_res.estimation * scaling_factor\n",
- "condidence_interval = np.array(iqae_res.confidence_interval) * scaling_factor\n",
+ "measured_payoff = result_iqae.estimation * scaling_factor\n",
+ "condidence_interval = np.array(result_iqae.confidence_interval) * scaling_factor\n",
"\n",
"print(\"Measured Payoff:\", measured_payoff)\n",
"print(\"Confidence Interval:\", condidence_interval)"
diff --git a/applications/finance/portfolio_optimization/portfolio_optimization.ipynb b/applications/finance/portfolio_optimization/portfolio_optimization.ipynb
index cfa4ee45..938fcaab 100644
--- a/applications/finance/portfolio_optimization/portfolio_optimization.ipynb
+++ b/applications/finance/portfolio_optimization/portfolio_optimization.ipynb
@@ -188,7 +188,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=1)"
@@ -279,14 +279,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
- "\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -303,8 +300,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"portfolio_optimization\")"
]
},
@@ -344,8 +339,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -373,9 +366,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -414,10 +405,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -531,7 +519,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " portfolio_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " portfolio_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=True).head(5)"
diff --git a/applications/logistics/task_scheduling_problem/task_scheduling_problem.ipynb b/applications/logistics/task_scheduling_problem/task_scheduling_problem.ipynb
index a011aac3..13694080 100644
--- a/applications/logistics/task_scheduling_problem/task_scheduling_problem.ipynb
+++ b/applications/logistics/task_scheduling_problem/task_scheduling_problem.ipynb
@@ -581,7 +581,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=8, penalty_energy=20)"
@@ -672,14 +672,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
- "\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -696,8 +693,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"task_scheduling_problem\")"
]
},
@@ -739,8 +734,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -768,9 +761,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -817,10 +808,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -934,7 +922,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " tasks_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " tasks_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=True).head(5)"
@@ -1506,13 +1494,6 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " construct_combinatorial_optimization_model,\n",
- " execute,\n",
- " set_execution_preferences,\n",
- " show,\n",
- " synthesize,\n",
- ")\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"from classiq.execution import ExecutionPreferences, IBMBackendPreferences\n",
"\n",
@@ -1526,29 +1507,9 @@
" optimizer_config=optimizer_config,\n",
")\n",
"\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
")\n",
- "\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 24,
- "id": "16b36025-9e47-4401-9c19-ab3ea07a342c",
- "metadata": {
- "execution": {
- "iopub.execute_input": "2024-05-07T14:54:53.389274Z",
- "iopub.status.busy": "2024-05-07T14:54:53.388010Z",
- "iopub.status.idle": "2024-05-07T14:54:53.769824Z",
- "shell.execute_reply": "2024-05-07T14:54:53.769083Z"
- }
- },
- "outputs": [],
- "source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"task_scheduling_problem_large\")"
]
},
@@ -1597,7 +1558,7 @@
},
"outputs": [],
"source": [
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -1727,7 +1688,7 @@
"\n",
"solution = get_optimization_solution_from_pyo(\n",
" tasks_model_large,\n",
- " vqe_result=res[0].value,\n",
+ " vqe_result=result,\n",
" penalty_energy=qaoa_config.penalty_energy,\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
diff --git a/applications/logistics/traveling_salesman_problem/traveling_salesman_problem.ipynb b/applications/logistics/traveling_salesman_problem/traveling_salesman_problem.ipynb
index dc8d7aae..d69ef2f5 100644
--- a/applications/logistics/traveling_salesman_problem/traveling_salesman_problem.ipynb
+++ b/applications/logistics/traveling_salesman_problem/traveling_salesman_problem.ipynb
@@ -169,8 +169,6 @@
},
"outputs": [],
"source": [
- "from typing import List, Tuple, cast # noqa\n",
- "\n",
"import numpy as np # noqa\n",
"import pyomo.core as pyo"
]
@@ -192,8 +190,6 @@
"outputs": [],
"source": [
"## We define a function which gets the matrix of distances and returns a Pyomo model\n",
- "\n",
- "\n",
"def PyomoTSP(dis_mat: np.ndarray) -> pyo.ConcreteModel:\n",
" model = pyo.ConcreteModel(\"TSP\")\n",
"\n",
@@ -266,7 +262,7 @@
],
"source": [
"# We generate a graph which defines our problem\n",
- "import networkx as nx # noqa\n",
+ "import networkx as nx\n",
"\n",
"graph = nx.DiGraph()\n",
"graph.add_nodes_from([0, 1, 2, 3])\n",
@@ -335,7 +331,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=10)"
@@ -426,14 +422,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
- "\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -450,8 +443,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"traveling_saleman_problem\")"
]
},
@@ -491,8 +482,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -520,9 +509,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -561,10 +548,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -695,7 +679,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " tsp_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " tsp_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=True).head(5)"
diff --git a/applications/optimization/electric_grid_optimization/electric_grid_optimization.ipynb b/applications/optimization/electric_grid_optimization/electric_grid_optimization.ipynb
index 0bdba387..2bc91a2c 100644
--- a/applications/optimization/electric_grid_optimization/electric_grid_optimization.ipynb
+++ b/applications/optimization/electric_grid_optimization/electric_grid_optimization.ipynb
@@ -160,8 +160,6 @@
},
"outputs": [],
"source": [
- "from typing import List, Tuple, cast # noqa\n",
- "\n",
"import pyomo.environ as pyo\n",
"from IPython.display import Markdown, display\n",
"\n",
@@ -243,11 +241,7 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Preferences,\n",
- " construct_combinatorial_optimization_model,\n",
- " set_preferences,\n",
- ")\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=5, penalty_energy=3.0)\n",
@@ -310,10 +304,8 @@
" optimizer_config=optimizer_config,\n",
")\n",
"\n",
- "# defining cosntraint such as computer and parameters for a quicker and more optimized circuit.\n",
- "preferences = Preferences(timeout_seconds=3000)\n",
- "\n",
- "qmod = set_preferences(qmod, preferences)"
+ "# defining constraint such as computer and parameters for a quicker and more optimized circuit.\n",
+ "qmod = set_preferences(qmod, timeout_seconds=3000)"
]
},
{
@@ -338,8 +330,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"electric_grid_optimization\")"
]
},
@@ -365,8 +355,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -393,9 +381,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -433,10 +419,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -549,7 +532,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " opt_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " opt_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
diff --git a/applications/optimization/integer_linear_programming/integer_linear_programming.ipynb b/applications/optimization/integer_linear_programming/integer_linear_programming.ipynb
index 93f7b4ae..62a5e07f 100644
--- a/applications/optimization/integer_linear_programming/integer_linear_programming.ipynb
+++ b/applications/optimization/integer_linear_programming/integer_linear_programming.ipynb
@@ -60,8 +60,6 @@
},
"outputs": [],
"source": [
- "from typing import cast\n",
- "\n",
"import networkx as nx\n",
"import numpy as np\n",
"import pyomo.core as pyo\n",
@@ -230,7 +228,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=3)"
@@ -321,14 +319,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
- "\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -345,8 +340,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"integer_linear_programming\")"
]
},
@@ -386,8 +379,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -415,9 +406,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -456,10 +445,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -583,7 +569,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " ilp_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " ilp_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
diff --git a/applications/optimization/knapsack_binary/knapsack_binary.ipynb b/applications/optimization/knapsack_binary/knapsack_binary.ipynb
index a6ca876d..077e929a 100644
--- a/applications/optimization/knapsack_binary/knapsack_binary.ipynb
+++ b/applications/optimization/knapsack_binary/knapsack_binary.ipynb
@@ -156,7 +156,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=5)"
@@ -247,14 +247,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
- "\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -271,8 +268,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"knapsack_binary\")"
]
},
@@ -312,8 +307,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -341,9 +334,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -382,10 +373,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -509,7 +497,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " knapsack_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " knapsack_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=False).head(5)"
diff --git a/applications/optimization/knapsack_integer/knapsack_integer.ipynb b/applications/optimization/knapsack_integer/knapsack_integer.ipynb
index 4f2c0075..fd682877 100644
--- a/applications/optimization/knapsack_integer/knapsack_integer.ipynb
+++ b/applications/optimization/knapsack_integer/knapsack_integer.ipynb
@@ -172,7 +172,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=5, penalty_energy=20.0)"
@@ -263,14 +263,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
- "\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -297,8 +294,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"knapsack_integer\")"
]
},
@@ -328,8 +323,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -357,9 +350,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -398,10 +389,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -525,7 +513,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " knapsack_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " knapsack_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=False).head(5)"
diff --git a/applications/optimization/max_clique/max_clique.ipynb b/applications/optimization/max_clique/max_clique.ipynb
index b90d89ba..f4d1fba3 100644
--- a/applications/optimization/max_clique/max_clique.ipynb
+++ b/applications/optimization/max_clique/max_clique.ipynb
@@ -156,7 +156,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=20)"
@@ -247,14 +247,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
- "\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -271,8 +268,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"max_clique\")"
]
},
@@ -312,8 +307,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -341,9 +334,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -467,7 +458,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " max_clique_model, vqe_result=res[0].value, penalty_energy=qaoa_config.penalty_energy\n",
+ " max_clique_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=False).head(5)"
diff --git a/applications/optimization/max_cut/max_cut.ipynb b/applications/optimization/max_cut/max_cut.ipynb
index e5c6bbc8..127d5fcd 100644
--- a/applications/optimization/max_cut/max_cut.ipynb
+++ b/applications/optimization/max_cut/max_cut.ipynb
@@ -44,8 +44,6 @@
},
"outputs": [],
"source": [
- "from typing import cast\n",
- "\n",
"import networkx as nx\n",
"import numpy as np\n",
"import pyomo.core as pyo\n",
@@ -179,7 +177,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=4)"
@@ -270,14 +268,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
- "\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -294,8 +289,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"max_cut\")"
]
},
@@ -335,8 +328,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -364,9 +355,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -405,10 +394,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -532,7 +518,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " maxcut_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " maxcut_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=False).head(5)"
diff --git a/applications/optimization/max_independent_set/max_independent_set.ipynb b/applications/optimization/max_independent_set/max_independent_set.ipynb
index cc5e0e16..f1191d06 100644
--- a/applications/optimization/max_independent_set/max_independent_set.ipynb
+++ b/applications/optimization/max_independent_set/max_independent_set.ipynb
@@ -49,8 +49,6 @@
},
"outputs": [],
"source": [
- "from typing import cast\n",
- "\n",
"import networkx as nx\n",
"import numpy as np\n",
"import pyomo.core as pyo\n",
@@ -83,10 +81,6 @@
},
"outputs": [],
"source": [
- "import networkx as nx\n",
- "import pyomo.core as pyo\n",
- "\n",
- "\n",
"def mis(graph: nx.Graph) -> pyo.ConcreteModel:\n",
" model = pyo.ConcreteModel()\n",
" model.x = pyo.Var(graph.nodes, domain=pyo.Binary)\n",
@@ -138,8 +132,6 @@
}
],
"source": [
- "import networkx as nx\n",
- "\n",
"num_nodes = 8\n",
"p_edge = 0.4\n",
"graph = nx.fast_gnp_random_graph(n=num_nodes, p=p_edge, seed=12345)\n",
@@ -244,7 +236,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=3)"
@@ -335,14 +327,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
- "\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -359,8 +348,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"max_independent_set\")"
]
},
@@ -400,8 +387,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -429,9 +414,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -470,10 +453,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -597,7 +577,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " mis_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " mis_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=False).head(5)"
diff --git a/applications/optimization/max_induced_k_color_subgraph/max_induced_k_color_subgraph.ipynb b/applications/optimization/max_induced_k_color_subgraph/max_induced_k_color_subgraph.ipynb
index a5d78c0e..8c23cb09 100644
--- a/applications/optimization/max_induced_k_color_subgraph/max_induced_k_color_subgraph.ipynb
+++ b/applications/optimization/max_induced_k_color_subgraph/max_induced_k_color_subgraph.ipynb
@@ -245,7 +245,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=8)"
@@ -336,14 +336,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
- "\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -360,8 +357,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"max_induced_k_color_subgraph\")"
]
},
@@ -401,8 +396,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -430,9 +423,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -471,10 +462,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -598,7 +586,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " coloring_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " coloring_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=False).head(5)"
diff --git a/applications/optimization/max_k_vertex_cover/max_k_vertex_cover.ipynb b/applications/optimization/max_k_vertex_cover/max_k_vertex_cover.ipynb
index 50fb1612..23e165fe 100644
--- a/applications/optimization/max_k_vertex_cover/max_k_vertex_cover.ipynb
+++ b/applications/optimization/max_k_vertex_cover/max_k_vertex_cover.ipynb
@@ -60,8 +60,6 @@
},
"outputs": [],
"source": [
- "from typing import cast\n",
- "\n",
"import networkx as nx\n",
"import numpy as np\n",
"import pyomo.core as pyo\n",
@@ -94,10 +92,6 @@
},
"outputs": [],
"source": [
- "import networkx as nx\n",
- "import pyomo.core as pyo\n",
- "\n",
- "\n",
"def mvc(graph: nx.Graph, k: int) -> pyo.ConcreteModel:\n",
" model = pyo.ConcreteModel()\n",
" model.x = pyo.Var(graph.nodes, domain=pyo.Binary)\n",
@@ -150,8 +144,6 @@
}
],
"source": [
- "import networkx as nx\n",
- "\n",
"K = 5\n",
"num_nodes = 10\n",
"p_edge = 0.5\n",
@@ -243,7 +235,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=3)"
@@ -334,14 +326,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
- "\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -358,8 +347,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"max_k_vertex_cover\")"
]
},
@@ -399,8 +386,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -428,9 +413,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -469,10 +452,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -596,7 +576,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " mvc_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " mvc_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=True).head(5)"
diff --git a/applications/optimization/min_graph_coloring/min_graph_coloring.ipynb b/applications/optimization/min_graph_coloring/min_graph_coloring.ipynb
index 6b5be50b..930b0a11 100644
--- a/applications/optimization/min_graph_coloring/min_graph_coloring.ipynb
+++ b/applications/optimization/min_graph_coloring/min_graph_coloring.ipynb
@@ -277,7 +277,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=6, penalty_energy=10.0)"
@@ -368,14 +368,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
- "\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -392,8 +389,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"min_graph_coloring\")"
]
},
@@ -433,8 +428,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -462,9 +455,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -503,10 +494,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -630,7 +618,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " coloring_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " coloring_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=True).head(5)"
diff --git a/applications/optimization/minimum_dominating_set/minimum_dominating_set.ipynb b/applications/optimization/minimum_dominating_set/minimum_dominating_set.ipynb
index 2cc5bb24..d952401b 100644
--- a/applications/optimization/minimum_dominating_set/minimum_dominating_set.ipynb
+++ b/applications/optimization/minimum_dominating_set/minimum_dominating_set.ipynb
@@ -65,8 +65,6 @@
},
"outputs": [],
"source": [
- "from typing import cast\n",
- "\n",
"import networkx as nx\n",
"import numpy as np\n",
"import pyomo.core as pyo\n",
@@ -99,10 +97,6 @@
},
"outputs": [],
"source": [
- "import networkx as nx\n",
- "import pyomo.core as pyo\n",
- "\n",
- "\n",
"def mds(graph: nx.Graph) -> pyo.ConcreteModel:\n",
" model = pyo.ConcreteModel()\n",
" model.x = pyo.Var(graph.nodes, domain=pyo.Binary)\n",
@@ -249,7 +243,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=6, penalty_energy=8)"
@@ -340,14 +334,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
- "\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -364,8 +355,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"minimum_dominating_set\")"
]
},
@@ -405,8 +394,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -434,9 +421,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -475,10 +460,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -602,7 +584,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " mds_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " mds_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=True).head(5)"
diff --git a/applications/optimization/rectangles_packing/rectangles_packing_grid.ipynb b/applications/optimization/rectangles_packing/rectangles_packing_grid.ipynb
index 7eccc000..01774cb7 100644
--- a/applications/optimization/rectangles_packing/rectangles_packing_grid.ipynb
+++ b/applications/optimization/rectangles_packing/rectangles_packing_grid.ipynb
@@ -1,15 +1,5 @@
{
"cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "id": "77758877-fc68-48cd-a365-97da74aef5c0",
- "metadata": {},
- "outputs": [],
- "source": [
- "import classiq"
- ]
- },
{
"cell_type": "code",
"execution_count": 2,
@@ -22,12 +12,8 @@
},
"outputs": [],
"source": [
- "import itertools # noqa\n",
- "from typing import List, Tuple, cast # noqa\n",
- "\n",
"import matplotlib.pyplot as plt\n",
"import networkx as nx\n",
- "import numpy as np # noqa\n",
"import pandas as pd\n",
"import pyomo.environ as pyo\n",
"from IPython.display import Markdown, display\n",
@@ -365,7 +351,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=10, penalty_energy=100)"
@@ -429,16 +415,13 @@
"metadata": {},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "backend_preferences = ExecutionPreferences(\n",
+ "qmod = set_execution_preferences(\n",
+ " qmod,\n",
" num_shots=10000,\n",
" backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\"),\n",
- ")\n",
- "\n",
- "\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ ")"
]
},
{
@@ -448,8 +431,6 @@
"metadata": {},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"rectangles_packing\")"
]
},
@@ -500,8 +481,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -529,9 +508,7 @@
"metadata": {},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -562,10 +539,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = VQESolverResult.parse_obj(res[0].value)\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -678,7 +652,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=True).head(5)"
@@ -971,22 +945,6 @@
"visualize_packing(CONTAINER_WIDTH,CONTAINER_HEIGHT, RECTANGLES, placement)\n",
"\"\"\""
]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "85d9bbba-47b9-4b8f-9c99-2390d6a80d25",
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "020ac70b-dafb-4838-b3c8-8305d101e2cb",
- "metadata": {},
- "outputs": [],
- "source": []
}
],
"metadata": {
diff --git a/applications/optimization/set_cover/set_cover.ipynb b/applications/optimization/set_cover/set_cover.ipynb
index 9afbff69..fdf65e2f 100644
--- a/applications/optimization/set_cover/set_cover.ipynb
+++ b/applications/optimization/set_cover/set_cover.ipynb
@@ -44,8 +44,6 @@
},
"outputs": [],
"source": [
- "from typing import cast\n",
- "\n",
"import networkx as nx\n",
"import numpy as np\n",
"import pyomo.core as pyo\n",
@@ -81,8 +79,6 @@
"import itertools\n",
"from typing import List\n",
"\n",
- "import pyomo.core as pyo\n",
- "\n",
"\n",
"def set_cover(sub_sets: List[List[int]]) -> pyo.ConcreteModel:\n",
" entire_set = set(itertools.chain(*sub_sets))\n",
@@ -237,7 +233,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=3, penalty_energy=10)"
@@ -328,14 +324,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
- "\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -352,8 +345,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"set_cover\")"
]
},
@@ -393,8 +384,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -422,9 +411,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -463,10 +450,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -590,7 +574,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " set_cover_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " set_cover_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=True).head(5)"
diff --git a/applications/optimization/set_partition/set_partition.ipynb b/applications/optimization/set_partition/set_partition.ipynb
index 6361c5bb..2e21044d 100644
--- a/applications/optimization/set_partition/set_partition.ipynb
+++ b/applications/optimization/set_partition/set_partition.ipynb
@@ -44,8 +44,6 @@
},
"outputs": [],
"source": [
- "from typing import cast\n",
- "\n",
"import networkx as nx\n",
"import numpy as np\n",
"import pyomo.core as pyo\n",
@@ -79,8 +77,6 @@
"outputs": [],
"source": [
"# we define a matrix which gets a set of integers s and returns a pyomo model for the partitioning problem\n",
- "\n",
- "\n",
"def partite(s) -> pyo.ConcreteModel:\n",
" model = pyo.ConcreteModel()\n",
" SetSize = len(s) # the set size\n",
@@ -203,7 +199,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=3)"
@@ -294,14 +290,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
- "\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -318,8 +311,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"set_partition\")"
]
},
@@ -359,8 +350,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -388,9 +377,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -429,10 +416,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -557,7 +541,7 @@
"\n",
"solution = get_optimization_solution_from_pyo(\n",
" set_partition_model,\n",
- " vqe_result=vqe_result,\n",
+ " vqe_result=result,\n",
" penalty_energy=qaoa_config.penalty_energy,\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
diff --git a/applications/physical_systems/ising_model/ising_model.ipynb b/applications/physical_systems/ising_model/ising_model.ipynb
index 395fe68b..0c6ba98c 100644
--- a/applications/physical_systems/ising_model/ising_model.ipynb
+++ b/applications/physical_systems/ising_model/ising_model.ipynb
@@ -154,7 +154,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_combinatorial_optimization_model\n",
+ "from classiq import *\n",
"from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig\n",
"\n",
"qaoa_config = QAOAConfig(num_layers=5)\n",
@@ -194,14 +194,11 @@
},
"outputs": [],
"source": [
- "from classiq import set_execution_preferences\n",
- "from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
+ "from classiq.execution import ClassiqBackendPreferences\n",
"\n",
- "backend_preferences = ExecutionPreferences(\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
- ")\n",
- "\n",
- "qmod = set_execution_preferences(qmod, backend_preferences)"
+ "qmod = set_execution_preferences(\n",
+ " qmod, backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator\")\n",
+ ")"
]
},
{
@@ -218,8 +215,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"ising_model\")"
]
},
@@ -257,8 +252,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -286,9 +279,7 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -327,10 +318,7 @@
}
],
"source": [
- "from classiq.execution import VQESolverResult\n",
- "\n",
- "vqe_result = res[0].value\n",
- "vqe_result.convergence_graph"
+ "result.convergence_graph"
]
},
{
@@ -448,7 +436,7 @@
")\n",
"\n",
"solution = get_optimization_solution_from_pyo(\n",
- " ising_model, vqe_result=vqe_result, penalty_energy=qaoa_config.penalty_energy\n",
+ " ising_model, vqe_result=result, penalty_energy=qaoa_config.penalty_energy\n",
")\n",
"optimization_result = pd.DataFrame.from_records(solution)\n",
"optimization_result.sort_values(by=\"cost\", ascending=True).head(5)"
diff --git a/built_in_apps/chemistry/chemistry.ipynb b/built_in_apps/chemistry/chemistry.ipynb
index 926299ba..c9dc7619 100644
--- a/built_in_apps/chemistry/chemistry.ipynb
+++ b/built_in_apps/chemistry/chemistry.ipynb
@@ -33,7 +33,7 @@
"source": [
"import numpy as np\n",
"\n",
- "from classiq import QuantumProgram, construct_chemistry_model, execute, show, synthesize\n",
+ "from classiq import *\n",
"from classiq.applications.chemistry import (\n",
" ChemistryExecutionParameters,\n",
" Molecule,\n",
@@ -165,7 +165,7 @@
}
],
"source": [
- "chemistry_model = construct_chemistry_model(\n",
+ "qmod = construct_chemistry_model(\n",
" chemistry_problem=chemistry_problem,\n",
" use_hartree_fock=True,\n",
" ansatz_parameters=UCCParameters(excitations=[1, 2]),\n",
@@ -176,40 +176,19 @@
" ),\n",
")\n",
"\n",
- "backend_preferences = ClassiqBackendPreferences(\n",
- " backend_name=ClassiqSimulatorBackendNames.SIMULATOR\n",
- ")\n",
- "\n",
- "chemistry_model = set_execution_preferences(\n",
- " chemistry_model,\n",
- " execution_preferences=ExecutionPreferences(\n",
- " num_shots=1000, backend_preferences=backend_preferences\n",
+ "qmod = set_execution_preferences(\n",
+ " qmod,\n",
+ " num_shots=1000,\n",
+ " backend_preferences=ClassiqBackendPreferences(\n",
+ " backend_name=ClassiqSimulatorBackendNames.SIMULATOR\n",
" ),\n",
")\n",
+ "write_qmod(qmod, \"chemistry\")\n",
"\n",
- "qprog = synthesize(chemistry_model)\n",
+ "qprog = synthesize(qmod)\n",
"show(qprog)"
]
},
- {
- "cell_type": "code",
- "execution_count": 5,
- "id": "bfd18189-3798-4b0c-9e6d-58c739ff078c",
- "metadata": {
- "execution": {
- "iopub.execute_input": "2024-05-07T13:21:14.439866Z",
- "iopub.status.busy": "2024-05-07T13:21:14.438700Z",
- "iopub.status.idle": "2024-05-07T13:21:14.464526Z",
- "shell.execute_reply": "2024-05-07T13:21:14.463766Z"
- }
- },
- "outputs": [],
- "source": [
- "from classiq import write_qmod\n",
- "\n",
- "write_qmod(chemistry_model, \"chemistry\")"
- ]
- },
{
"cell_type": "markdown",
"id": "f12c9a32-f271-4892-8515-bd9e6b9fcf8b",
diff --git a/built_in_apps/option_pricing/option_pricing.ipynb b/built_in_apps/option_pricing/option_pricing.ipynb
index 18718159..ace23709 100644
--- a/built_in_apps/option_pricing/option_pricing.ipynb
+++ b/built_in_apps/option_pricing/option_pricing.ipynb
@@ -142,7 +142,7 @@
},
"outputs": [],
"source": [
- "from classiq import construct_finance_model\n",
+ "from classiq import *\n",
"\n",
"qmod = construct_finance_model(\n",
" finance_model_input=log_normal_model,\n",
@@ -165,8 +165,6 @@
},
"outputs": [],
"source": [
- "from classiq import write_qmod\n",
- "\n",
"write_qmod(qmod, \"option_pricing\")"
]
},
@@ -205,8 +203,6 @@
}
],
"source": [
- "from classiq import show, synthesize\n",
- "\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
]
@@ -238,8 +234,6 @@
},
"outputs": [],
"source": [
- "from classiq import execute\n",
- "\n",
"results = execute(qprog).result()"
]
},
diff --git a/functions/function_declarations/core_lib_decls.qmod b/functions/function_declarations/core_lib_decls.qmod
index be5f1b7e..b8db3559 100644
--- a/functions/function_declarations/core_lib_decls.qmod
+++ b/functions/function_declarations/core_lib_decls.qmod
@@ -42,6 +42,8 @@ qfunc unitary(elements: real[][], target: qbit[log(elements[0].len, 2)]);
qfunc add(left: qbit[], right: qbit[], output result: qbit[Max(left.len, right.len) + 1]);
qfunc modular_add(left: qbit[], right: qbit[]);
qfunc integer_xor(left: qbit[], right: qbit[]);
+qfunc modular_add_constant(left: real, right: qnum);
+qfunc real_xor_constant(left: real, right: qnum);
qfunc U(theta: real, phi: real, lam: real, gam: real, target: qbit);
qfunc CCX(control: qbit[2], target: qbit);
qfunc allocate(num_qubits: int, output out: qbit[num_qubits]);
diff --git a/functions/function_usage_examples/arithmetic/arithmetic_expression/arithmetic_expression_example.ipynb b/functions/function_usage_examples/arithmetic/arithmetic_expression/arithmetic_expression_example.ipynb
index 0517bc1c..d7724c88 100644
--- a/functions/function_usage_examples/arithmetic/arithmetic_expression/arithmetic_expression_example.ipynb
+++ b/functions/function_usage_examples/arithmetic/arithmetic_expression/arithmetic_expression_example.ipynb
@@ -73,7 +73,7 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, QNum, create_model, prepare_int, qfunc\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -85,7 +85,7 @@
" res |= (a + b + c & 15) % 8 ^ 3 & a ^ 10 == 4\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"arithmetic_expression_example\")"
]
},
{
@@ -113,12 +113,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"arithmetic_expression_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"result.parsed_counts"
]
}
diff --git a/functions/function_usage_examples/arithmetic/bitwise_and/bitwise_and_example.ipynb b/functions/function_usage_examples/arithmetic/bitwise_and/bitwise_and_example.ipynb
index 16831c80..d66cfdf0 100644
--- a/functions/function_usage_examples/arithmetic/bitwise_and/bitwise_and_example.ipynb
+++ b/functions/function_usage_examples/arithmetic/bitwise_and/bitwise_and_example.ipynb
@@ -61,7 +61,7 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, QNum, create_model, prepare_int, qfunc\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -71,7 +71,7 @@
" res |= a & b\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"bitwise_and_2vars_example\")"
]
},
{
@@ -99,12 +99,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"bitwise_and_2vars_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"result.parsed_counts"
]
},
@@ -134,16 +131,13 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, QNum, create_model, prepare_int, qfunc\n",
- "\n",
- "\n",
"@qfunc\n",
"def main(a: Output[QNum], res: Output[QNum]) -> None:\n",
" prepare_int(5, a)\n",
" res |= 3 & a\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"bitwise_and_integer_example\")"
]
},
{
@@ -171,12 +165,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"bitwise_and_integer_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"result.parsed_counts"
]
}
diff --git a/functions/function_usage_examples/arithmetic/bitwise_invert/bitwise_invert_example.ipynb b/functions/function_usage_examples/arithmetic/bitwise_invert/bitwise_invert_example.ipynb
index a87b1795..1b770e6e 100644
--- a/functions/function_usage_examples/arithmetic/bitwise_invert/bitwise_invert_example.ipynb
+++ b/functions/function_usage_examples/arithmetic/bitwise_invert/bitwise_invert_example.ipynb
@@ -33,7 +33,7 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, QNum, create_model, prepare_int, qfunc\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -43,7 +43,7 @@
" y |= ~x\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"bitwise_invert_example\")"
]
},
{
@@ -68,12 +68,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"bitwise_invert_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"print(result.counts_of_multiple_outputs([\"x\", \"y\"]))"
]
}
diff --git a/functions/function_usage_examples/arithmetic/bitwise_or/bitwise_or_example.ipynb b/functions/function_usage_examples/arithmetic/bitwise_or/bitwise_or_example.ipynb
index e5ca6e13..93cd98d9 100644
--- a/functions/function_usage_examples/arithmetic/bitwise_or/bitwise_or_example.ipynb
+++ b/functions/function_usage_examples/arithmetic/bitwise_or/bitwise_or_example.ipynb
@@ -62,16 +62,7 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " QNum,\n",
- " allocate_num,\n",
- " create_model,\n",
- " inplace_prepare_int,\n",
- " qfunc,\n",
- ")\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -83,7 +74,7 @@
" res |= a | b\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"bitwise_or_2vars_example\")"
]
},
{
@@ -109,12 +100,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"bitwise_or_2vars_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"print(result.parsed_counts)\n",
"print(result.counts_of_multiple_outputs([\"a\", \"b\", \"res\"]))"
]
@@ -145,16 +133,13 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, QNum, create_model, prepare_int, qfunc\n",
- "\n",
- "\n",
"@qfunc\n",
"def main(a: Output[QNum], res: Output[QNum]) -> None:\n",
" prepare_int(4, a)\n",
" res |= 3 | a\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"bitwise_or_integer_example\")"
]
},
{
@@ -182,12 +167,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"bitwise_or_integer_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"result.parsed_counts"
]
}
diff --git a/functions/function_usage_examples/arithmetic/bitwise_xor/bitwise_xor_example.ipynb b/functions/function_usage_examples/arithmetic/bitwise_xor/bitwise_xor_example.ipynb
index d28ca7cf..adee8399 100644
--- a/functions/function_usage_examples/arithmetic/bitwise_xor/bitwise_xor_example.ipynb
+++ b/functions/function_usage_examples/arithmetic/bitwise_xor/bitwise_xor_example.ipynb
@@ -62,16 +62,7 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " QNum,\n",
- " allocate_num,\n",
- " create_model,\n",
- " inplace_prepare_int,\n",
- " qfunc,\n",
- ")\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -83,7 +74,7 @@
" res |= a ^ b\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"bitwise_xor_2vars_example\")"
]
},
{
@@ -109,12 +100,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"bitwise_xor_2vars_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"print(result.parsed_counts)\n",
"print(result.counts_of_multiple_outputs([\"a\", \"b\", \"res\"]))"
]
@@ -145,16 +133,13 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, QNum, create_model, prepare_int, qfunc\n",
- "\n",
- "\n",
"@qfunc\n",
"def main(a: Output[QNum], res: Output[QNum]) -> None:\n",
" prepare_int(4, a)\n",
" res |= 3 ^ a\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"bitwise_xor_integer_example\")"
]
},
{
@@ -182,12 +167,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"bitwise_xor_integer_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"result.parsed_counts"
]
}
diff --git a/functions/function_usage_examples/arithmetic/comparator/comparator_example.ipynb b/functions/function_usage_examples/arithmetic/comparator/comparator_example.ipynb
index fe872536..3d9077f7 100644
--- a/functions/function_usage_examples/arithmetic/comparator/comparator_example.ipynb
+++ b/functions/function_usage_examples/arithmetic/comparator/comparator_example.ipynb
@@ -59,7 +59,7 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, QNum, allocate_num, create_model, qfunc\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -70,7 +70,7 @@
" res |= a == b\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"comparator_2vars_example\")"
]
},
{
@@ -87,9 +87,6 @@
},
"outputs": [],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"comparator_2vars_example\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -118,18 +115,6 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " QNum,\n",
- " allocate,\n",
- " create_model,\n",
- " hadamard_transform,\n",
- " qfunc,\n",
- ")\n",
- "\n",
- "\n",
"@qfunc\n",
"def main(a: Output[QNum], res: Output[QNum]) -> None:\n",
" allocate(3, a)\n",
@@ -137,7 +122,7 @@
" res |= a <= 2\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"comparator_integer_example\")"
]
},
{
@@ -172,12 +157,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"comparator_integer_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"result.parsed_counts"
]
}
diff --git a/functions/function_usage_examples/arithmetic/extremum/extremum_example.ipynb b/functions/function_usage_examples/arithmetic/extremum/extremum_example.ipynb
index 364daf95..dac40a40 100644
--- a/functions/function_usage_examples/arithmetic/extremum/extremum_example.ipynb
+++ b/functions/function_usage_examples/arithmetic/extremum/extremum_example.ipynb
@@ -38,17 +38,7 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " QNum,\n",
- " allocate,\n",
- " create_model,\n",
- " hadamard_transform,\n",
- " prepare_int,\n",
- " qfunc,\n",
- ")\n",
+ "from classiq import *\n",
"from classiq.qmod.symbolic import min\n",
"\n",
"\n",
@@ -61,7 +51,7 @@
" res |= min(a, b)\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"minimum_2vars_example\")"
]
},
{
@@ -96,12 +86,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"minimum_2vars_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"result.parsed_counts"
]
},
@@ -131,16 +118,6 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " QNum,\n",
- " allocate,\n",
- " create_model,\n",
- " hadamard_transform,\n",
- " qfunc,\n",
- ")\n",
"from classiq.qmod.symbolic import max\n",
"\n",
"\n",
@@ -152,7 +129,7 @@
" res |= max(3.5, a)\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"maximum_float_example\")"
]
},
{
@@ -187,12 +164,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"maximum_float_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"result.parsed_counts"
]
}
diff --git a/functions/function_usage_examples/arithmetic/modulo/modulo_example.ipynb b/functions/function_usage_examples/arithmetic/modulo/modulo_example.ipynb
index 34389d94..1ecc1637 100644
--- a/functions/function_usage_examples/arithmetic/modulo/modulo_example.ipynb
+++ b/functions/function_usage_examples/arithmetic/modulo/modulo_example.ipynb
@@ -55,16 +55,7 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " QNum,\n",
- " allocate,\n",
- " create_model,\n",
- " inplace_prepare_int,\n",
- " qfunc,\n",
- ")\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -78,7 +69,7 @@
" res |= (a + b) % 4\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"modulo_example\")"
]
},
{
@@ -103,12 +94,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"modulo_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"print(result.parsed_counts)"
]
}
diff --git a/functions/function_usage_examples/arithmetic/multiplication/multiplication.ipynb b/functions/function_usage_examples/arithmetic/multiplication/multiplication.ipynb
index 09f29d11..8b3f2c03 100644
--- a/functions/function_usage_examples/arithmetic/multiplication/multiplication.ipynb
+++ b/functions/function_usage_examples/arithmetic/multiplication/multiplication.ipynb
@@ -61,7 +61,7 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, QNum, create_model, prepare_int, qfunc\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -71,7 +71,7 @@
" res |= a * b\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"multiplication_2vars_example\")"
]
},
{
@@ -99,12 +99,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"multiplication_2vars_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"result.parsed_counts"
]
},
@@ -134,18 +131,6 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " QNum,\n",
- " allocate,\n",
- " create_model,\n",
- " hadamard_transform,\n",
- " qfunc,\n",
- ")\n",
- "\n",
- "\n",
"@qfunc\n",
"def main(a: Output[QNum], res: Output[QNum]) -> None:\n",
" allocate(2, a)\n",
@@ -154,7 +139,7 @@
" res |= 3.5 * a\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"multiplication_float_example\")"
]
},
{
@@ -185,12 +170,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"multiplication_float_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"result.parsed_counts"
]
}
diff --git a/functions/function_usage_examples/arithmetic/negation/negation_example.ipynb b/functions/function_usage_examples/arithmetic/negation/negation_example.ipynb
index d67653a3..db135f3b 100644
--- a/functions/function_usage_examples/arithmetic/negation/negation_example.ipynb
+++ b/functions/function_usage_examples/arithmetic/negation/negation_example.ipynb
@@ -35,16 +35,7 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " QNum,\n",
- " allocate_num,\n",
- " create_model,\n",
- " hadamard_transform,\n",
- " qfunc,\n",
- ")\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -54,7 +45,7 @@
" b |= -a\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"negation_example\")"
]
},
{
@@ -89,12 +80,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"negation_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"result.parsed_counts"
]
}
diff --git a/functions/function_usage_examples/arithmetic/subtraction/subtraction_example.ipynb b/functions/function_usage_examples/arithmetic/subtraction/subtraction_example.ipynb
index 9793c2cf..e73b7a33 100644
--- a/functions/function_usage_examples/arithmetic/subtraction/subtraction_example.ipynb
+++ b/functions/function_usage_examples/arithmetic/subtraction/subtraction_example.ipynb
@@ -55,7 +55,7 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, QNum, create_model, prepare_int, qfunc\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -65,7 +65,7 @@
" res |= a - b\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"subtraction_2vars_example\")"
]
},
{
@@ -90,12 +90,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"subtraction_2vars_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"print(result.parsed_counts)"
]
},
@@ -124,16 +121,13 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, QNum, create_model, prepare_int, qfunc\n",
- "\n",
- "\n",
"@qfunc\n",
"def main(a: Output[QNum], res: Output[QNum]) -> None:\n",
" prepare_int(4, a)\n",
" res |= a - 3.5\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"subtraction_float_example\")"
]
},
{
@@ -158,12 +152,9 @@
}
],
"source": [
- "from classiq import execute, synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"subtraction_float_example\")\n",
"qprog = synthesize(qmod)\n",
"\n",
- "result = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"print(result.parsed_counts)"
]
}
diff --git a/functions/function_usage_examples/mcx/mcx_example.ipynb b/functions/function_usage_examples/mcx/mcx_example.ipynb
index b350bfc5..796719c2 100644
--- a/functions/function_usage_examples/mcx/mcx_example.ipynb
+++ b/functions/function_usage_examples/mcx/mcx_example.ipynb
@@ -51,17 +51,7 @@
"metadata": {},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " X,\n",
- " allocate,\n",
- " control,\n",
- " create_model,\n",
- " prepare_bell_state,\n",
- " qfunc,\n",
- ")\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -78,7 +68,7 @@
"metadata": {},
"outputs": [],
"source": [
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"mcx_example\")"
]
},
{
@@ -88,9 +78,6 @@
"metadata": {},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"mcx_example\")\n",
"qprog = synthesize(qmod)"
]
},
diff --git a/functions/qmod_library_reference/classiq_open_library/grover_operator/grover_operator.ipynb b/functions/qmod_library_reference/classiq_open_library/grover_operator/grover_operator.ipynb
index c419385a..f0521037 100644
--- a/functions/qmod_library_reference/classiq_open_library/grover_operator/grover_operator.ipynb
+++ b/functions/qmod_library_reference/classiq_open_library/grover_operator/grover_operator.ipynb
@@ -74,22 +74,7 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Constraints,\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " QCallable,\n",
- " QNum,\n",
- " allocate,\n",
- " bind,\n",
- " create_model,\n",
- " grover_operator,\n",
- " hadamard_transform,\n",
- " phase_oracle,\n",
- " power,\n",
- " qfunc,\n",
- ")\n",
+ "from classiq import *\n",
"from classiq.qmod.symbolic import logical_and\n",
"\n",
"VAR_SIZE = 2\n",
@@ -123,8 +108,9 @@
" bind(packed_vars, [x, y])\n",
"\n",
"\n",
- "constraints = Constraints(max_width=15)\n",
- "qmod_grover = create_model(main, constraints=constraints)"
+ "qmod_grover = create_model(\n",
+ " main, constraints=Constraints(max_width=15), out_file=\"grover_operator\"\n",
+ ")"
]
},
{
@@ -141,9 +127,6 @@
},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod_grover, \"grover_operator\")\n",
"qprog = synthesize(qmod_grover)"
]
},
@@ -195,10 +178,8 @@
}
],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()[0].value\n",
- "res.parsed_counts"
+ "result = execute(qprog).result_value()\n",
+ "result.parsed_counts"
]
},
{
diff --git a/functions/qmod_library_reference/classiq_open_library/hadamard_transform/hadamard_transform.ipynb b/functions/qmod_library_reference/classiq_open_library/hadamard_transform/hadamard_transform.ipynb
index 2cab4b45..ac9ac5e2 100644
--- a/functions/qmod_library_reference/classiq_open_library/hadamard_transform/hadamard_transform.ipynb
+++ b/functions/qmod_library_reference/classiq_open_library/hadamard_transform/hadamard_transform.ipynb
@@ -40,25 +40,16 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " allocate,\n",
- " create_model,\n",
- " hadamard_transform,\n",
- " qfunc,\n",
- ")\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
"def main(x: Output[QArray[QBit]]):\n",
- "\n",
" allocate(3, x)\n",
" hadamard_transform(x)\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"hadamard_transform\")"
]
},
{
@@ -75,9 +66,6 @@
},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"hadamard_transform\")\n",
"qprog = synthesize(qmod)"
]
}
diff --git a/functions/qmod_library_reference/classiq_open_library/linear_pauli_rotations/linear_pauli_rotations.ipynb b/functions/qmod_library_reference/classiq_open_library/linear_pauli_rotations/linear_pauli_rotations.ipynb
index 223d403b..8dfb8876 100644
--- a/functions/qmod_library_reference/classiq_open_library/linear_pauli_rotations/linear_pauli_rotations.ipynb
+++ b/functions/qmod_library_reference/classiq_open_library/linear_pauli_rotations/linear_pauli_rotations.ipynb
@@ -86,16 +86,7 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " Pauli,\n",
- " QArray,\n",
- " QBit,\n",
- " allocate,\n",
- " create_model,\n",
- " linear_pauli_rotations,\n",
- " qfunc,\n",
- ")\n",
+ "from classiq import *\n",
"\n",
"NUM_STATE_QUBITS = 6\n",
"BASES = [Pauli.Y.value] * 3\n",
@@ -110,7 +101,7 @@
" linear_pauli_rotations(BASES, SLOPES, OFFSETS, x, ind)\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"linear_pauli_rotations\")"
]
},
{
@@ -127,9 +118,6 @@
},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"linear_pauli_rotations\")\n",
"qprog = synthesize(qmod)"
]
}
diff --git a/functions/qmod_library_reference/classiq_open_library/qct_qst/qct_qst.ipynb b/functions/qmod_library_reference/classiq_open_library/qct_qst/qct_qst.ipynb
index 0f40a150..60cb28ed 100644
--- a/functions/qmod_library_reference/classiq_open_library/qct_qst/qct_qst.ipynb
+++ b/functions/qmod_library_reference/classiq_open_library/qct_qst/qct_qst.ipynb
@@ -92,16 +92,7 @@
"source": [
"import numpy as np\n",
"\n",
- "from classiq import (\n",
- " H,\n",
- " Output,\n",
- " QNum,\n",
- " allocate,\n",
- " create_model,\n",
- " execute,\n",
- " qct_qst_type1,\n",
- " qfunc,\n",
- ")\n",
+ "from classiq import *\n",
"from classiq.execution import (\n",
" ClassiqBackendPreferences,\n",
" ClassiqSimulatorBackendNames,\n",
@@ -133,17 +124,14 @@
"metadata": {},
"outputs": [],
"source": [
- "from classiq import prepare_amplitudes\n",
- "\n",
- "\n",
"@qfunc\n",
"def main(x: Output[QNum]):\n",
- "\n",
" prepare_amplitudes(combined_data.tolist(), 0.0, x)\n",
" qct_qst_type1(x)\n",
"\n",
"\n",
- "qmod = create_model(main, execution_preferences=execution_preferences)"
+ "qmod = create_model(main, execution_preferences=execution_preferences)\n",
+ "write_qmod(qmod, \"qct_qst_type1\", decimal_precision=15)"
]
},
{
@@ -153,9 +141,6 @@
"metadata": {},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"qct_qst_type1\", decimal_precision=15)\n",
"qprog = synthesize(qmod)"
]
},
@@ -166,7 +151,7 @@
"metadata": {},
"outputs": [],
"source": [
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -178,7 +163,7 @@
"source": [
"qct_data = np.zeros(2 ** (NUM_QUBITS - 1) + 1).astype(complex)\n",
"qst_data = np.zeros(2 ** (NUM_QUBITS - 1) - 1).astype(complex)\n",
- "for sample in res[0].value.parsed_state_vector:\n",
+ "for sample in result.parsed_state_vector:\n",
" value = int(sample.state[\"x\"])\n",
" if value < 2 ** (NUM_QUBITS - 1) + 1:\n",
" qct_data[value] += sample.amplitude\n",
@@ -328,25 +313,6 @@
"metadata": {},
"outputs": [],
"source": [
- "import numpy as np\n",
- "\n",
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " create_model,\n",
- " execute,\n",
- " invert,\n",
- " prepare_amplitudes,\n",
- " qct_qst_type2,\n",
- " qfunc,\n",
- ")\n",
- "from classiq.execution import (\n",
- " ClassiqBackendPreferences,\n",
- " ClassiqSimulatorBackendNames,\n",
- " ExecutionPreferences,\n",
- ")\n",
- "\n",
"NUM_QUBITS = 4\n",
"cos_sin_data = np.random.rand(2 ** (NUM_QUBITS - 1))\n",
"cos_sin_data = cos_sin_data / np.linalg.norm(cos_sin_data)"
@@ -368,7 +334,8 @@
" qct_qst_type2(x, q)\n",
"\n",
"\n",
- "qmod = create_model(main, execution_preferences=execution_preferences)"
+ "qmod = create_model(main, execution_preferences=execution_preferences)\n",
+ "write_qmod(qmod, \"qct_qst_type2\", decimal_precision=15)"
]
},
{
@@ -378,7 +345,6 @@
"metadata": {},
"outputs": [],
"source": [
- "write_qmod(qmod, \"qct_qst_type2\", decimal_precision=15)\n",
"qprog = synthesize(qmod)"
]
},
@@ -389,7 +355,7 @@
"metadata": {},
"outputs": [],
"source": [
- "res = execute(qprog).result()"
+ "result = execute(qprog).result_value()"
]
},
{
@@ -401,7 +367,7 @@
"source": [
"qct_data = np.zeros(2 ** (NUM_QUBITS - 1)).astype(complex)\n",
"qst_data = np.zeros(2 ** (NUM_QUBITS - 1)).astype(complex)\n",
- "for sample in res[0].value.parsed_state_vector:\n",
+ "for sample in result.parsed_state_vector:\n",
" if sample.state[\"q\"] == 0:\n",
" qct_data[int(sample.state[\"x\"])] += sample.amplitude\n",
" else:\n",
@@ -514,24 +480,21 @@
}
],
"source": [
- "from classiq import qct_type2\n",
- "\n",
- "\n",
"@qfunc\n",
"def main(x: Output[QNum]):\n",
- "\n",
" prepare_amplitudes(cos_sin_data.tolist(), 0.0, x)\n",
" qct_type2(x)\n",
"\n",
"\n",
"qmod = create_model(main, execution_preferences=execution_preferences)\n",
- "\n",
"write_qmod(qmod, \"qct_type2\", decimal_precision=15)\n",
+ "\n",
"qprog = synthesize(qmod)\n",
- "res = execute(qprog).result()\n",
+ "\n",
+ "result = execute(qprog).result_value()\n",
"qct_data = np.zeros(2 ** (NUM_QUBITS - 1)).astype(complex)\n",
"\n",
- "for sample in res[0].value.parsed_state_vector:\n",
+ "for sample in result.parsed_state_vector:\n",
" qct_data[int(sample.state[\"x\"])] += sample.amplitude\n",
"\n",
"global_phase = np.exp(1j * np.angle(qct_data[0]))\n",
@@ -561,9 +524,6 @@
}
],
"source": [
- "from classiq import qst_type2\n",
- "\n",
- "\n",
"@qfunc\n",
"def main(x: Output[QNum]):\n",
" prepare_amplitudes(cos_sin_data.tolist(), 0.0, x)\n",
@@ -571,13 +531,13 @@
"\n",
"\n",
"qmod = create_model(main, execution_preferences=execution_preferences)\n",
- "\n",
"write_qmod(qmod, \"qst_type2\", decimal_precision=15)\n",
+ "\n",
"qprog = synthesize(qmod)\n",
- "res = execute(qprog).result()\n",
+ "result = execute(qprog).result_value()\n",
"qst_data = np.zeros(2 ** (NUM_QUBITS - 1)).astype(complex)\n",
"\n",
- "for sample in res[0].value.parsed_state_vector:\n",
+ "for sample in result.parsed_state_vector:\n",
" qst_data[int(sample.state[\"x\"])] += sample.amplitude\n",
"\n",
"global_phase = np.exp(1j * np.angle(qst_data[0]))\n",
diff --git a/functions/qmod_library_reference/classiq_open_library/qft/qft.ipynb b/functions/qmod_library_reference/classiq_open_library/qft/qft.ipynb
index c0c8c0df..6556408b 100644
--- a/functions/qmod_library_reference/classiq_open_library/qft/qft.ipynb
+++ b/functions/qmod_library_reference/classiq_open_library/qft/qft.ipynb
@@ -47,17 +47,16 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, allocate, create_model, qft, qfunc\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
"def main(x: Output[QArray[QBit]]):\n",
- "\n",
" allocate(4, x)\n",
" qft(x)\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"qft\")"
]
},
{
@@ -74,9 +73,6 @@
},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"qft\")\n",
"qprog = synthesize(qmod)"
]
}
diff --git a/functions/qmod_library_reference/classiq_open_library/qpe/qpe.ipynb b/functions/qmod_library_reference/classiq_open_library/qpe/qpe.ipynb
index 9e6fe140..69b4c934 100644
--- a/functions/qmod_library_reference/classiq_open_library/qpe/qpe.ipynb
+++ b/functions/qmod_library_reference/classiq_open_library/qpe/qpe.ipynb
@@ -78,19 +78,7 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " CRZ,\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " QNum,\n",
- " allocate,\n",
- " allocate_num,\n",
- " create_model,\n",
- " inplace_prepare_int,\n",
- " qfunc,\n",
- " qpe,\n",
- ")\n",
+ "from classiq import *\n",
"from classiq.qmod.symbolic import pi\n",
"\n",
"QPE_RESOLUTION = 2\n",
@@ -105,7 +93,7 @@
" qpe(unitary=lambda: CRZ(pi, state[0], state[1]), phase=phase)\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"qpe\")"
]
},
{
@@ -122,9 +110,6 @@
},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"qpe\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -158,10 +143,8 @@
}
],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()[0].value\n",
- "print(\"Results:\", res.parsed_counts)"
+ "result = execute(qprog).result_value()\n",
+ "print(\"Results:\", result.parsed_counts)"
]
},
{
@@ -202,23 +185,6 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " Pauli,\n",
- " PauliTerm,\n",
- " QArray,\n",
- " QBit,\n",
- " QNum,\n",
- " allocate,\n",
- " allocate_num,\n",
- " create_model,\n",
- " hadamard_transform,\n",
- " qfunc,\n",
- " qpe_flexible,\n",
- " suzuki_trotter,\n",
- ")\n",
- "from classiq.qmod.symbolic import pi\n",
- "\n",
"QPE_RESOLUTION = 2\n",
"\n",
"HAMILTONIAN = [\n",
@@ -246,7 +212,7 @@
" )\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"qpe_flexible\")"
]
},
{
@@ -263,9 +229,6 @@
},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"qpe_flexible\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -299,10 +262,8 @@
}
],
"source": [
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()[0].value\n",
- "print(\"Results:\", res.parsed_counts)"
+ "result = execute(qprog).result_value()\n",
+ "print(\"Results:\", result.parsed_counts)"
]
},
{
diff --git a/functions/qmod_library_reference/classiq_open_library/qsvt/qsvt.ipynb b/functions/qmod_library_reference/classiq_open_library/qsvt/qsvt.ipynb
index 4b65e996..9ad5a898 100644
--- a/functions/qmod_library_reference/classiq_open_library/qsvt/qsvt.ipynb
+++ b/functions/qmod_library_reference/classiq_open_library/qsvt/qsvt.ipynb
@@ -73,30 +73,8 @@
"from numpy.polynomial import Polynomial\n",
"from pyqsp.angle_sequence import QuantumSignalProcessingPhases\n",
"\n",
- "from classiq import (\n",
- " Constraints,\n",
- " execute,\n",
- " set_execution_preferences,\n",
- " synthesize,\n",
- " write_qmod,\n",
- ")\n",
+ "from classiq import *\n",
"from classiq.execution import ClassiqBackendPreferences, ExecutionPreferences\n",
- "from classiq.qmod import (\n",
- " CArray,\n",
- " CReal,\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " QNum,\n",
- " X,\n",
- " allocate,\n",
- " bind,\n",
- " control,\n",
- " create_model,\n",
- " hadamard_transform,\n",
- " qfunc,\n",
- " qsvt,\n",
- ")\n",
"\n",
"\n",
"@qfunc\n",
@@ -183,8 +161,8 @@
" return adjust_qsvt_convetions(phases).tolist()\n",
"\n",
"\n",
- "def parse_qsvt_results(res) -> Tuple[np.ndarray, np.ndarray]:\n",
- " parsed_state_vector = res[0].value.parsed_state_vector\n",
+ "def parse_qsvt_results(result) -> Tuple[np.ndarray, np.ndarray]:\n",
+ " parsed_state_vector = result.parsed_state_vector\n",
"\n",
" d: Dict = {x: [] for x in range(2**NUM_QUBITS)}\n",
" for parsed_state in parsed_state_vector:\n",
@@ -274,16 +252,17 @@
" qsvt_sqrt_polynomial(QSVT_PHASES, state, ref, ind, qsvt_aux)\n",
"\n",
"\n",
- "execution_preferences = ExecutionPreferences(\n",
- " num_shots=1,\n",
- " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator_statevector\"),\n",
+ "qmod = create_model(\n",
+ " main,\n",
+ " constraints=Constraints(max_width=13),\n",
+ " execution_preferences=ExecutionPreferences(\n",
+ " num_shots=1,\n",
+ " backend_preferences=ClassiqBackendPreferences(\n",
+ " backend_name=\"simulator_statevector\"\n",
+ " ),\n",
+ " ),\n",
+ " out_file=\"qsvt\",\n",
")\n",
- "\n",
- "constraints = Constraints(max_width=13)\n",
- "qmod = create_model(main, constraints=constraints)\n",
- "qmod = set_execution_preferences(qmod, execution_preferences)\n",
- "\n",
- "write_qmod(qmod, \"qsvt\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -312,9 +291,9 @@
}
],
"source": [
- "res = execute(qprog).result()\n",
+ "result = execute(qprog).result_value()\n",
"\n",
- "measured, target = parse_qsvt_results(res)\n",
+ "measured, target = parse_qsvt_results(result)\n",
"assert np.allclose(measured, target, atol=0.02)"
]
},
diff --git a/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_bell_state.ipynb b/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_bell_state.ipynb
index 7d1058a9..d657261d 100644
--- a/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_bell_state.ipynb
+++ b/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_bell_state.ipynb
@@ -68,7 +68,7 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, create_model, prepare_bell_state, qfunc\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -76,7 +76,7 @@
" prepare_bell_state(2, x)\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"prepare_bell_state\")"
]
},
{
@@ -93,9 +93,6 @@
},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"prepare_bell_state\")\n",
"qprog = synthesize(qmod)"
]
}
diff --git a/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_exponential_state.ipynb b/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_exponential_state.ipynb
index da0f64d5..c45fcec7 100644
--- a/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_exponential_state.ipynb
+++ b/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_exponential_state.ipynb
@@ -60,15 +60,7 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " allocate,\n",
- " create_model,\n",
- " prepare_exponential_state,\n",
- " qfunc,\n",
- ")\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -77,7 +69,7 @@
" prepare_exponential_state(0.1, x)\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"prepare_exponential_state\")"
]
},
{
@@ -95,9 +87,6 @@
},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"prepare_exponential_state\")\n",
"qprog = synthesize(qmod)"
]
}
diff --git a/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_ghz_state.ipynb b/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_ghz_state.ipynb
index 00f41911..1d0f8087 100644
--- a/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_ghz_state.ipynb
+++ b/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_ghz_state.ipynb
@@ -61,7 +61,7 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, create_model, prepare_ghz_state, qfunc\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -69,7 +69,7 @@
" prepare_ghz_state(5, x)\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"prepare_ghz_state\")"
]
},
{
@@ -86,9 +86,6 @@
},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"prepare_ghz_state\")\n",
"qprog = synthesize(qmod)"
]
}
diff --git a/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_int.ipynb b/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_int.ipynb
index 1a868979..9e02fc0a 100644
--- a/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_int.ipynb
+++ b/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_int.ipynb
@@ -63,7 +63,7 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, create_model, prepare_int, qfunc\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -71,7 +71,7 @@
" prepare_int(3, x)\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"prepare_int\")"
]
},
{
@@ -89,9 +89,6 @@
},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"prepare_int\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -119,24 +116,13 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QArray,\n",
- " QBit,\n",
- " allocate,\n",
- " create_model,\n",
- " inplace_prepare_int,\n",
- " qfunc,\n",
- ")\n",
- "\n",
- "\n",
"@qfunc\n",
"def main(x: Output[QArray[QBit]]):\n",
" allocate(5, x)\n",
" inplace_prepare_int(3, x)\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"inplace_prepare_int\")"
]
},
{
@@ -154,9 +140,6 @@
},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"inplace_prepare_int\")\n",
"qprog = synthesize(qmod)"
]
}
diff --git a/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_partial_uniform_state.ipynb b/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_partial_uniform_state.ipynb
index bc9ad820..8114166c 100644
--- a/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_partial_uniform_state.ipynb
+++ b/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_partial_uniform_state.ipynb
@@ -51,8 +51,7 @@
" prepare_uniform_trimmed_state(3, x)\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"prepare_uniform_trimmed_state\")\n",
+ "qmod = create_model(main, out_file=\"prepare_uniform_trimmed_state\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -63,8 +62,8 @@
"metadata": {},
"outputs": [],
"source": [
- "res = execute(qprog).result()\n",
- "counts = res[0].value.parsed_counts"
+ "result = execute(qprog).result_value()\n",
+ "counts = result.parsed_counts"
]
},
{
@@ -145,19 +144,13 @@
"metadata": {},
"outputs": [],
"source": [
- "import matplotlib.pyplot as plt\n",
- "\n",
- "from classiq import *\n",
- "\n",
- "\n",
"@qfunc\n",
"def main(x: Output[QNum]):\n",
" allocate(5, x)\n",
" prepare_uniform_interval_state(2, 8, x)\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"prepare_uniform_interval_state\")\n",
+ "qmod = create_model(main, out_file=\"prepare_uniform_interval_state\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -168,8 +161,8 @@
"metadata": {},
"outputs": [],
"source": [
- "res = execute(qprog).result()\n",
- "counts = res[0].value.parsed_counts"
+ "result = execute(qprog).result_value()\n",
+ "counts = result.parsed_counts"
]
},
{
diff --git a/functions/qmod_library_reference/qmod_core_library/hamiltonian_evolution/exponentiation/exponentiation.ipynb b/functions/qmod_library_reference/qmod_core_library/hamiltonian_evolution/exponentiation/exponentiation.ipynb
index d8f4ad5b..9f898d51 100644
--- a/functions/qmod_library_reference/qmod_core_library/hamiltonian_evolution/exponentiation/exponentiation.ipynb
+++ b/functions/qmod_library_reference/qmod_core_library/hamiltonian_evolution/exponentiation/exponentiation.ipynb
@@ -76,19 +76,7 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " Pauli,\n",
- " PauliTerm,\n",
- " QArray,\n",
- " QBit,\n",
- " allocate,\n",
- " create_model,\n",
- " exponentiation_with_depth_constraint,\n",
- " qfunc,\n",
- " synthesize,\n",
- " write_qmod,\n",
- ")\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -108,8 +96,7 @@
" )\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"exponentiation\")\n",
+ "qmod = create_model(main, out_file=\"exponentiation\")\n",
"qprog = synthesize(qmod)"
]
},
diff --git a/functions/qmod_library_reference/qmod_core_library/hamiltonian_evolution/qdrift/qdrift.ipynb b/functions/qmod_library_reference/qmod_core_library/hamiltonian_evolution/qdrift/qdrift.ipynb
index a4cbcc72..5386de92 100644
--- a/functions/qmod_library_reference/qmod_core_library/hamiltonian_evolution/qdrift/qdrift.ipynb
+++ b/functions/qmod_library_reference/qmod_core_library/hamiltonian_evolution/qdrift/qdrift.ipynb
@@ -42,24 +42,11 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " Pauli,\n",
- " PauliTerm,\n",
- " QArray,\n",
- " QBit,\n",
- " allocate,\n",
- " create_model,\n",
- " qdrift,\n",
- " qfunc,\n",
- " synthesize,\n",
- " write_qmod,\n",
- ")\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
"def main(qba: Output[QArray[QBit]]):\n",
- "\n",
" allocate(2, qba)\n",
" qdrift(\n",
" [\n",
@@ -72,8 +59,7 @@
" )\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"qdrift\")\n",
+ "qmod = create_model(main, out_file=\"qdrift\")\n",
"qprog = synthesize(qmod)"
]
},
diff --git a/functions/qmod_library_reference/qmod_core_library/hamiltonian_evolution/suzuki_trotter/suzuki_trotter.ipynb b/functions/qmod_library_reference/qmod_core_library/hamiltonian_evolution/suzuki_trotter/suzuki_trotter.ipynb
index f4c9df64..213b4b07 100644
--- a/functions/qmod_library_reference/qmod_core_library/hamiltonian_evolution/suzuki_trotter/suzuki_trotter.ipynb
+++ b/functions/qmod_library_reference/qmod_core_library/hamiltonian_evolution/suzuki_trotter/suzuki_trotter.ipynb
@@ -42,20 +42,7 @@
},
"outputs": [],
"source": [
- "from classiq import (\n",
- " CReal,\n",
- " Output,\n",
- " Pauli,\n",
- " PauliTerm,\n",
- " QArray,\n",
- " QBit,\n",
- " allocate,\n",
- " create_model,\n",
- " qfunc,\n",
- " suzuki_trotter,\n",
- " synthesize,\n",
- " write_qmod,\n",
- ")\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -73,8 +60,7 @@
" )\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"suzuki_trotter\")\n",
+ "qmod = create_model(main, out_file=\"suzuki_trotter\")\n",
"qprog = synthesize(qmod)"
]
},
diff --git a/functions/qmod_library_reference/qmod_core_library/prepare_state_and_amplitudes/prepare_state_and_amplitudes.ipynb b/functions/qmod_library_reference/qmod_core_library/prepare_state_and_amplitudes/prepare_state_and_amplitudes.ipynb
index 99a2a4e5..749d2aad 100644
--- a/functions/qmod_library_reference/qmod_core_library/prepare_state_and_amplitudes/prepare_state_and_amplitudes.ipynb
+++ b/functions/qmod_library_reference/qmod_core_library/prepare_state_and_amplitudes/prepare_state_and_amplitudes.ipynb
@@ -120,17 +120,7 @@
"metadata": {},
"outputs": [],
"source": [
- "from classiq import (\n",
- " Output,\n",
- " QNum,\n",
- " create_model,\n",
- " execute,\n",
- " prepare_amplitudes,\n",
- " prepare_state,\n",
- " qfunc,\n",
- " synthesize,\n",
- " write_qmod,\n",
- ")\n",
+ "from classiq import *\n",
"\n",
"\n",
"@qfunc\n",
@@ -139,7 +129,7 @@
" prepare_state(probabilities=probabilities, bound=0.01, out=x)\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"prepare_state\")"
]
},
{
@@ -149,7 +139,6 @@
"metadata": {},
"outputs": [],
"source": [
- "write_qmod(qmod, \"prepare_state\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -180,11 +169,11 @@
"source": [
"import numpy as np\n",
"\n",
- "res = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"\n",
"probs = np.zeros(8)\n",
- "for sample in res.parsed_counts:\n",
- " probs[int(sample.state[\"x\"])] = sample.shots / res.num_shots\n",
+ "for sample in result.parsed_counts:\n",
+ " probs[int(sample.state[\"x\"])] = sample.shots / result.num_shots\n",
"print(\"Resulting probabilities:\", probs)"
]
},
@@ -216,11 +205,13 @@
" prepare_amplitudes(amplitudes=amps.tolist(), bound=0, out=x)\n",
"\n",
"\n",
- "backend_preferences = ClassiqBackendPreferences(backend_name=\"simulator_statevector\")\n",
- "execution_preferences = ExecutionPreferences(\n",
- " num_shots=1, backend_preferences=backend_preferences\n",
+ "qmod = create_model(main)\n",
+ "qmod = set_execution_preferences(\n",
+ " qmod,\n",
+ " num_shots=1,\n",
+ " backend_preferences=ClassiqBackendPreferences(backend_name=\"simulator_statevector\"),\n",
")\n",
- "qmod = create_model(main, execution_preferences=execution_preferences)"
+ "write_qmod(qmod, \"prepare_amplitudes\", decimal_precision=15)"
]
},
{
@@ -230,9 +221,6 @@
"metadata": {},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"prepare_amplitudes\", decimal_precision=15)\n",
"qprog = synthesize(qmod)"
]
},
@@ -264,12 +252,10 @@
"source": [
"import numpy as np\n",
"\n",
- "from classiq import execute\n",
- "\n",
- "res = execute(qprog).result()[0].value\n",
+ "result = execute(qprog).result_value()\n",
"\n",
"amps = np.zeros(8, dtype=complex)\n",
- "for sample in res.parsed_state_vector:\n",
+ "for sample in result.parsed_state_vector:\n",
" amps[int(sample.state[\"x\"])] = sample.amplitude\n",
"\n",
"# remove global phase\n",
diff --git a/functions/qmod_library_reference/qmod_core_library/standard_gates/standard_gates.ipynb b/functions/qmod_library_reference/qmod_core_library/standard_gates/standard_gates.ipynb
index c1e2fbb5..1696d323 100644
--- a/functions/qmod_library_reference/qmod_core_library/standard_gates/standard_gates.ipynb
+++ b/functions/qmod_library_reference/qmod_core_library/standard_gates/standard_gates.ipynb
@@ -26,8 +26,7 @@
},
"outputs": [],
"source": [
- "# Generic imports\n",
- "from classiq import QArray, QBit, allocate, create_model, qfunc, synthesize, write_qmod"
+ "from classiq import *"
]
},
{
@@ -67,9 +66,6 @@
},
"outputs": [],
"source": [
- "from classiq import X\n",
- "\n",
- "\n",
"@qfunc\n",
"def main():\n",
" q = QBit(\"q\")\n",
@@ -78,8 +74,7 @@
" X(q)\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"X\")\n",
+ "qmod = create_model(main, out_file=\"X\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -135,9 +130,6 @@
},
"outputs": [],
"source": [
- "from classiq import RZ\n",
- "\n",
- "\n",
"@qfunc\n",
"def main():\n",
" q = QBit(\"q\")\n",
@@ -147,8 +139,7 @@
" RZ(theta, q)\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"RZ\")\n",
+ "qmod = create_model(main, out_file=\"RZ\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -189,9 +180,6 @@
},
"outputs": [],
"source": [
- "from classiq import R\n",
- "\n",
- "\n",
"@qfunc\n",
"def main():\n",
" q = QBit(\"q\")\n",
@@ -202,8 +190,7 @@
" R(theta, phi, q)\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"R\")\n",
+ "qmod = create_model(main, out_file=\"R\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -240,9 +227,6 @@
},
"outputs": [],
"source": [
- "from classiq import PHASE\n",
- "\n",
- "\n",
"@qfunc\n",
"def main():\n",
" q = QBit(\"q\")\n",
@@ -252,8 +236,7 @@
" PHASE(theta, q)\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"PHASE\")\n",
+ "qmod = create_model(main, out_file=\"PHASE\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -300,9 +283,6 @@
},
"outputs": [],
"source": [
- "from classiq import RZZ\n",
- "\n",
- "\n",
"@qfunc\n",
"def main():\n",
" q = QArray(\"q\")\n",
@@ -312,8 +292,7 @@
" RZZ(theta, q)\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"RZZ\")\n",
+ "qmod = create_model(main, out_file=\"RZZ\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -365,9 +344,6 @@
},
"outputs": [],
"source": [
- "from classiq import CX\n",
- "\n",
- "\n",
"@qfunc\n",
"def main():\n",
" q_target = QBit(\"q_t\")\n",
@@ -379,8 +355,7 @@
" CX(q_control, q_target)\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"CX\")\n",
+ "qmod = create_model(main, out_file=\"CX\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -427,9 +402,6 @@
},
"outputs": [],
"source": [
- "from classiq import CRX\n",
- "\n",
- "\n",
"@qfunc\n",
"def main():\n",
" q_target = QBit(\"q_t\")\n",
@@ -442,8 +414,7 @@
" CRX(theta, q_control, q_target)\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"CRX\")\n",
+ "qmod = create_model(main, out_file=\"CRX\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -485,9 +456,6 @@
},
"outputs": [],
"source": [
- "from classiq import SWAP\n",
- "\n",
- "\n",
"@qfunc\n",
"def main():\n",
" q1 = QBit(\"q1\")\n",
@@ -499,8 +467,7 @@
" SWAP(q1, q2)\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"SWAP\")\n",
+ "qmod = create_model(main, out_file=\"SWAP\")\n",
"qprog = synthesize(qmod)"
]
},
@@ -545,9 +512,6 @@
},
"outputs": [],
"source": [
- "from classiq import U\n",
- "\n",
- "\n",
"@qfunc\n",
"def main():\n",
" q = QBit(\"q\")\n",
@@ -560,8 +524,7 @@
" U(theta, phi, lam, gam, q)\n",
"\n",
"\n",
- "qmod = create_model(main)\n",
- "write_qmod(qmod, \"U\")\n",
+ "qmod = create_model(main, out_file=\"U\")\n",
"qprog = synthesize(qmod)"
]
}
diff --git a/functions/qmod_library_reference/qmod_core_library/unitary/unitary.ipynb b/functions/qmod_library_reference/qmod_core_library/unitary/unitary.ipynb
index 538ea0c4..360beac1 100644
--- a/functions/qmod_library_reference/qmod_core_library/unitary/unitary.ipynb
+++ b/functions/qmod_library_reference/qmod_core_library/unitary/unitary.ipynb
@@ -45,7 +45,7 @@
},
"outputs": [],
"source": [
- "from classiq import Output, QArray, QBit, allocate, create_model, qfunc, unitary\n",
+ "from classiq import *\n",
"\n",
"UNITARY = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, -1j, 0], [0, 0, 0, 1j]]\n",
"\n",
@@ -56,7 +56,7 @@
" unitary(UNITARY, x)\n",
"\n",
"\n",
- "qmod = create_model(main)"
+ "qmod = create_model(main, out_file=\"unitary\")"
]
},
{
@@ -74,9 +74,6 @@
},
"outputs": [],
"source": [
- "from classiq import synthesize, write_qmod\n",
- "\n",
- "write_qmod(qmod, \"unitary\")\n",
"qprog = synthesize(qmod)"
]
},
diff --git a/requirements_tests.txt b/requirements_tests.txt
index 0cb8469b..6cce43af 100644
--- a/requirements_tests.txt
+++ b/requirements_tests.txt
@@ -1,4 +1,3 @@
pytest
testbook
-torch
diff --git a/research/rainbow_options/rainbow_options_bruteforce_method.ipynb b/research/rainbow_options/rainbow_options_bruteforce_method.ipynb
index 00586962..f197152b 100644
--- a/research/rainbow_options/rainbow_options_bruteforce_method.ipynb
+++ b/research/rainbow_options/rainbow_options_bruteforce_method.ipynb
@@ -281,7 +281,6 @@
"source": [
"from functools import reduce\n",
"\n",
- "from classiq import *\n",
"from classiq.qmod.symbolic import max as qmax\n",
"\n",
"a = STEP_X / SCALING_FACTOR\n",
@@ -378,7 +377,6 @@
},
"outputs": [],
"source": [
- "from classiq import *\n",
"from classiq.qmod.symbolic import exp, sqrt\n",
"\n",
"\n",
@@ -431,9 +429,7 @@
{
"name": "stdout",
"output_type": "stream",
- "text": [
- ""
- ]
+ "text": []
}
],
"source": [
@@ -491,7 +487,6 @@
},
"outputs": [],
"source": [
- "from classiq import Z, cfunc\n",
"from classiq.qmod.builtins.classical_execution_primitives import iqae, save\n",
"\n",
"\n",
@@ -518,9 +513,6 @@
},
"outputs": [],
"source": [
- "from classiq import CInt, QArray, QCallable, grover_operator, power\n",
- "\n",
- "\n",
"@qfunc\n",
"def grover_algorithm(\n",
" k: CInt,\n",
@@ -548,24 +540,21 @@
},
"outputs": [],
"source": [
- "def get_main():\n",
- " @qfunc\n",
- " def main(\n",
- " k: CInt,\n",
- " ind: Output[QBit],\n",
- " ) -> None:\n",
- " qvars = EstimationVars(\"qvars\")\n",
- " allocate(qvars.size, qvars)\n",
- " grover_algorithm(\n",
- " k,\n",
- " qmci_oracle,\n",
- " rainbow_brute_force,\n",
- " qvars,\n",
- " )\n",
- " state_reg = QArray(\"state_reg\")\n",
- " bind(qvars, [state_reg, ind])\n",
- "\n",
- " return main"
+ "@qfunc\n",
+ "def main(\n",
+ " k: CInt,\n",
+ " ind: Output[QBit],\n",
+ ") -> None:\n",
+ " qvars = EstimationVars(\"qvars\")\n",
+ " allocate(qvars.size, qvars)\n",
+ " grover_algorithm(\n",
+ " k,\n",
+ " qmci_oracle,\n",
+ " rainbow_brute_force,\n",
+ " qvars,\n",
+ " )\n",
+ " state_reg = QArray(\"state_reg\")\n",
+ " bind(qvars, [state_reg, ind])"
]
},
{
@@ -580,27 +569,17 @@
},
"outputs": [],
"source": [
- "from classiq import execute, write_qmod\n",
- "from classiq.execution import ExecutionPreferences\n",
- "\n",
- "\n",
- "def synthesize_and_execute(post_process):\n",
- " constraints = Constraints(max_width=25)\n",
- " qmod = create_model(\n",
- " get_main(),\n",
- " constraints=constraints,\n",
- " classical_execution_function=cmain,\n",
- " )\n",
- " write_qmod(qmod, \"rainbow_options_bruteforce_method\")\n",
- " print(\"Starting synthesis\")\n",
- " qprog = synthesize(qmod)\n",
- " show(qprog)\n",
- " print(\"Starting execution\")\n",
- " res = execute(qprog).result()\n",
- " iqae_res = res[0].value\n",
- " parsed_res = post_process(res[0].value)\n",
- "\n",
- " return (qmod, qprog, iqae_res, parsed_res)"
+ "qmod = create_model(\n",
+ " main,\n",
+ " constraints=Constraints(max_width=25),\n",
+ " classical_execution_function=cmain,\n",
+ " out_file=\"rainbow_options_bruteforce_method\",\n",
+ ")\n",
+ "print(\"Starting synthesis\")\n",
+ "qprog = synthesize(qmod)\n",
+ "show(qprog)\n",
+ "print(\"Starting execution\")\n",
+ "result = execute(qprog).result_value()"
]
},
{
@@ -667,7 +646,6 @@
"output_type": "stream",
"text": [
"Starting synthesis\n",
- "",
"Starting execution\n",
"raw iqae results: 0.513 with confidence interval (0.4677543120163805, 0.5582456879836195)\n",
"option estimated value: 26.756022317711 with confidence interval [ 7.6385265 45.87351814]\n"
@@ -675,14 +653,13 @@
}
],
"source": [
- "qmod_brute_force, qprog_brute_force, iqae_res_brute_force, parsed_res_brute_force = (\n",
- " synthesize_and_execute(parse_result_bruteforce)\n",
- ")\n",
- "result, conf_interval = parsed_res_brute_force\n",
+ "parsed_result, conf_interval = parse_result_bruteforce(result)\n",
"print(\n",
- " f\"raw iqae results: {iqae_res_brute_force.estimation} with confidence interval {iqae_res_brute_force.confidence_interval}\"\n",
+ " f\"raw iqae results: {result.estimation} with confidence interval {result.confidence_interval}\"\n",
")\n",
- "print(f\"option estimated value: {result} with confidence interval {conf_interval}\")"
+ "print(\n",
+ " f\"option estimated value: {parsed_result} with confidence interval {conf_interval}\"\n",
+ ")"
]
},
{
@@ -708,9 +685,9 @@
" np.log(ALPHA_VALUE / ALPHA_ASSERTION)\n",
") # based on e^2=(1/2N)*log(2T/alpha) from \"Iterative Quantum Amplitude Estimation\" since our alpha is low, we want to check within a bigger confidence interval\n",
"assert (\n",
- " np.abs(result - expected_payoff)\n",
+ " np.abs(parsed_result - expected_payoff)\n",
" <= 0.5 * measured_confidence * confidence_scale_by_alpha\n",
- "), f\"Payoff result is out of the {ALPHA_ASSERTION*100}% confidence interval: |{result} - {expected_payoff}| > {0.5*measured_confidence * confidence_scale_by_alpha}\""
+ "), f\"Payoff result is out of the {ALPHA_ASSERTION*100}% confidence interval: |{parsed_result} - {expected_payoff}| > {0.5*measured_confidence * confidence_scale_by_alpha}\""
]
},
{
diff --git a/research/rainbow_options/rainbow_options_direct_method.ipynb b/research/rainbow_options/rainbow_options_direct_method.ipynb
index 81e26d03..ef29d7fe 100644
--- a/research/rainbow_options/rainbow_options_direct_method.ipynb
+++ b/research/rainbow_options/rainbow_options_direct_method.ipynb
@@ -106,7 +106,7 @@
},
"outputs": [],
"source": [
- "from classiq import QConstant\n",
+ "from classiq import *\n",
"\n",
"EPSILON_VALUE = 0.05\n",
"ALPHA_VALUE = 0.1\n",
@@ -292,7 +292,6 @@
"source": [
"from functools import reduce\n",
"\n",
- "from classiq import *\n",
"from classiq.qmod.symbolic import max as qmax\n",
"\n",
"a = STEP_X / SCALING_FACTOR\n",
@@ -430,8 +429,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Starting synthesis\n",
- ""
+ "Starting synthesis\n"
]
}
],
@@ -512,8 +510,7 @@
" rainbow_direct(qvars)\n",
"\n",
"\n",
- "constraints = Constraints(max_width=24)\n",
- "qmod = create_model(main, constraints=constraints)\n",
+ "qmod = create_model(main, constraints=Constraints(max_width=24))\n",
"print(\"Starting synthesis\")\n",
"qprog = synthesize(qmod)\n",
"show(qprog)"
@@ -596,19 +593,16 @@
},
"outputs": [],
"source": [
- "def get_main():\n",
- " @qfunc\n",
- " def main(\n",
- " k: CInt,\n",
- " ind: Output[QBit],\n",
- " ) -> None:\n",
- " qvars = EstimationVars(\"qvars\")\n",
- " allocate(qvars.size, qvars)\n",
- " grover_algorithm(k, qmci_oracle, rainbow_direct, qvars)\n",
- " state = QArray(\"state\")\n",
- " bind(qvars, [state, ind])\n",
- "\n",
- " return main"
+ "@qfunc\n",
+ "def main(\n",
+ " k: CInt,\n",
+ " ind: Output[QBit],\n",
+ ") -> None:\n",
+ " qvars = EstimationVars(\"qvars\")\n",
+ " allocate(qvars.size, qvars)\n",
+ " grover_algorithm(k, qmci_oracle, rainbow_direct, qvars)\n",
+ " state = QArray(\"state\")\n",
+ " bind(qvars, [state, ind])"
]
},
{
@@ -623,26 +617,17 @@
},
"outputs": [],
"source": [
- "from classiq import execute, write_qmod\n",
- "\n",
- "\n",
- "def synthesize_and_execute(post_process):\n",
- " constraints = Constraints(max_width=25)\n",
- " qmod = create_model(\n",
- " get_main(),\n",
- " constraints=constraints,\n",
- " classical_execution_function=cmain,\n",
- " )\n",
- " write_qmod(qmod, \"rainbow_options_direct_method\")\n",
- " print(\"Starting synthesis\")\n",
- " qprog = synthesize(qmod)\n",
- " show(qprog)\n",
- " print(\"Starting execution\")\n",
- " res = execute(qprog).result()\n",
- " iqae_res = res[0].value\n",
- " parsed_res = post_process(res[0].value)\n",
- "\n",
- " return (qmod, qprog, iqae_res, parsed_res)"
+ "qmod = create_model(\n",
+ " main,\n",
+ " constraints=Constraints(max_width=25),\n",
+ " classical_execution_function=cmain,\n",
+ " out_file=\"rainbow_options_direct_method\",\n",
+ ")\n",
+ "print(\"Starting synthesis\")\n",
+ "qprog = synthesize(qmod)\n",
+ "show(qprog)\n",
+ "print(\"Starting execution\")\n",
+ "result = execute(qprog).result_value()"
]
},
{
@@ -709,7 +694,6 @@
"output_type": "stream",
"text": [
"Starting synthesis\n",
- "",
"Starting execution\n",
"raw iqae results: 0.08014469753569903 with confidence interval (0.07186168028239096, 0.08842771478900711)\n",
"option estimated value: 24.26836709887192 with confidence interval [ 2.12356356 46.41317064]\n"
@@ -717,14 +701,13 @@
}
],
"source": [
- "qmod_direct, qprog_direct, iqae_res_direct, parsed_res_direct = synthesize_and_execute(\n",
- " parse_result_direct\n",
- ")\n",
- "result, conf_interval = parsed_res_direct\n",
+ "parsed_result, conf_interval = parse_result_direct(result)\n",
"print(\n",
- " f\"raw iqae results: {iqae_res_direct.estimation} with confidence interval {iqae_res_direct.confidence_interval}\"\n",
+ " f\"raw iqae results: {result.estimation} with confidence interval {result.confidence_interval}\"\n",
")\n",
- "print(f\"option estimated value: {result} with confidence interval {conf_interval}\")"
+ "print(\n",
+ " f\"option estimated value: {parsed_result} with confidence interval {conf_interval}\"\n",
+ ")"
]
},
{
@@ -763,9 +746,9 @@
" np.log(ALPHA_VALUE / ALPHA_ASSERTION)\n",
") # based on e^2=(1/2N)*log(2T/alpha) from \"Iterative Quantum Amplitude Estimation\" since our alpha is low, we want to check within a bigger confidence interval\n",
"assert (\n",
- " np.abs(result - expected_payoff)\n",
+ " np.abs(parsed_result - expected_payoff)\n",
" <= 0.5 * measured_confidence * confidence_scale_by_alpha\n",
- "), f\"Payoff result is out of the {ALPHA_ASSERTION*100}% confidence interval: |{result} - {expected_payoff}| > {0.5*measured_confidence * confidence_scale_by_alpha}\""
+ "), f\"Payoff result is out of the {ALPHA_ASSERTION*100}% confidence interval: |{parsed_result} - {expected_payoff}| > {0.5*measured_confidence * confidence_scale_by_alpha}\""
]
},
{
diff --git a/research/rainbow_options/rainbow_options_integration_method.ipynb b/research/rainbow_options/rainbow_options_integration_method.ipynb
index ec048080..0e4e9aad 100644
--- a/research/rainbow_options/rainbow_options_integration_method.ipynb
+++ b/research/rainbow_options/rainbow_options_integration_method.ipynb
@@ -463,9 +463,6 @@
},
"outputs": [],
"source": [
- "from classiq import within_apply\n",
- "\n",
- "\n",
"@qfunc\n",
"def integration_payoff(max_reg: QNum, integrator_reg: QNum, ind_reg: QBit):\n",
" geq_reg = QBit(\"geq_reg\")\n",
@@ -494,8 +491,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Starting synthesis\n",
- ""
+ "Starting synthesis\n"
]
}
],
@@ -581,9 +577,6 @@
},
"outputs": [],
"source": [
- "from classiq import CInt, QArray, QCallable, grover_operator, power\n",
- "\n",
- "\n",
"@qfunc\n",
"def grover_algorithm(\n",
" k: CInt,\n",
@@ -611,24 +604,21 @@
},
"outputs": [],
"source": [
- "def get_main():\n",
- " @qfunc\n",
- " def main(\n",
- " k: CInt,\n",
- " ind: Output[QBit],\n",
- " ) -> None:\n",
- " qvars = EstimationVars(\"qvars\")\n",
- " allocate(qvars.size, qvars)\n",
- " grover_algorithm(\n",
- " k,\n",
- " qmci_oracle,\n",
- " rainbow_integration,\n",
- " qvars,\n",
- " )\n",
- " state = QArray(\"state\")\n",
- " bind(qvars, [state, ind])\n",
- "\n",
- " return main"
+ "@qfunc\n",
+ "def main(\n",
+ " k: CInt,\n",
+ " ind: Output[QBit],\n",
+ ") -> None:\n",
+ " qvars = EstimationVars(\"qvars\")\n",
+ " allocate(qvars.size, qvars)\n",
+ " grover_algorithm(\n",
+ " k,\n",
+ " qmci_oracle,\n",
+ " rainbow_integration,\n",
+ " qvars,\n",
+ " )\n",
+ " state = QArray(\"state\")\n",
+ " bind(qvars, [state, ind])"
]
},
{
@@ -643,27 +633,18 @@
},
"outputs": [],
"source": [
- "from classiq import execute, write_qmod\n",
- "\n",
- "\n",
- "def synthesize_and_execute(post_process):\n",
- " constraints = Constraints(max_width=25)\n",
- " qmod = create_model(\n",
- " get_main(),\n",
- " constraints=constraints,\n",
- " classical_execution_function=cmain,\n",
- " )\n",
- " write_qmod(qmod, \"rainbow_options_integration_method\")\n",
- " print(\"Starting synthesis\")\n",
- " qprog = synthesize(qmod)\n",
- " show(qprog)\n",
- " print(\"Starting execution\")\n",
- " res = execute(qprog).result()\n",
- " iqae_res = res[0].value\n",
- " print(\"raw iqae results:\", iqae_res.estimation, iqae_res.confidence_interval)\n",
- " parsed_res = post_process(res[0].value)\n",
- "\n",
- " return (qmod, qprog, iqae_res, parsed_res)"
+ "qmod = create_model(\n",
+ " main,\n",
+ " constraints=Constraints(max_width=25),\n",
+ " classical_execution_function=cmain,\n",
+ " out_file=\"rainbow_options_integration_method\",\n",
+ ")\n",
+ "print(\"Starting synthesis\")\n",
+ "qprog = synthesize(qmod)\n",
+ "show(qprog)\n",
+ "print(\"Starting execution\")\n",
+ "result = execute(qprog).result_value()\n",
+ "print(\"raw iqae results:\", result.estimation, result.confidence_interval)"
]
},
{
@@ -701,11 +682,9 @@
"C = S0[0] * np.exp((MU[0] + MIN_X * CHOLESKY[0].sum()))\n",
"\n",
"\n",
- "def parse_result_integration(iqae_res):\n",
- " option_value = (iqae_res.estimation * (C * B)) + (C * A) - K\n",
- " confidence_interval = (\n",
- " (np.array(iqae_res.confidence_interval) * (C * B)) + (C * A) - K\n",
- " )\n",
+ "def parse_result_integration(result):\n",
+ " option_value = (result.estimation * (C * B)) + (C * A) - K\n",
+ " confidence_interval = (np.array(result.confidence_interval) * (C * B)) + (C * A) - K\n",
" return (option_value, confidence_interval)"
]
},
@@ -733,7 +712,6 @@
"output_type": "stream",
"text": [
"Starting synthesis\n",
- "",
"Starting execution\n",
"raw iqae results: 0.051301905160993394 (0.04602614017739099, 0.056577670144595804)\n",
"raw iqae results: 0.051301905160993394 with confidence interval (0.04602614017739099, 0.056577670144595804)\n",
@@ -742,14 +720,13 @@
}
],
"source": [
- "qmod_integration, qprog_integration, iqae_res_integration, parsed_res_integration = (\n",
- " synthesize_and_execute(parse_result_integration)\n",
- ")\n",
- "result, conf_interval = parsed_res_integration\n",
+ "parsed_result, conf_interval = parse_result_integration(result)\n",
"print(\n",
- " f\"raw iqae results: {iqae_res_integration.estimation} with confidence interval {iqae_res_integration.confidence_interval}\"\n",
+ " f\"raw iqae results: {result.estimation} with confidence interval {result.confidence_interval}\"\n",
")\n",
- "print(f\"option estimated value: {result} with confidence interval {conf_interval}\")"
+ "print(\n",
+ " f\"option estimated value: {parsed_result} with confidence interval {conf_interval}\"\n",
+ ")"
]
},
{
@@ -788,9 +765,9 @@
" np.log(ALPHA_VALUE / ALPHA_ASSERTION)\n",
") # based on e^2=(1/2N)*log(2T/alpha) from \"Iterative Quantum Amplitude Estimation\" since our alpha is low, we want to check within a bigger confidence interval\n",
"assert (\n",
- " np.abs(result - expected_payoff)\n",
+ " np.abs(parsed_result - expected_payoff)\n",
" <= 0.5 * measured_confidence * confidence_scale_by_alpha\n",
- "), f\"Payoff result is out of the {ALPHA_ASSERTION*100}% confidence interval: |{result} - {expected_payoff}| > {0.5*measured_confidence * confidence_scale_by_alpha}\""
+ "), f\"Payoff result is out of the {ALPHA_ASSERTION*100}% confidence interval: |{parsed_result} - {expected_payoff}| > {0.5*measured_confidence * confidence_scale_by_alpha}\""
]
},
{
diff --git a/tests/test_notebooks.py b/tests/test_notebooks.py
index e40d71ad..40199f5d 100644
--- a/tests/test_notebooks.py
+++ b/tests/test_notebooks.py
@@ -1,17 +1,14 @@
import os
-import logging
from testbook import testbook # type: ignore[import]
from utils_for_tests import iterate_notebooks
-TIMEOUT: int = 60 * 10 # 10 minutes
-LOGGER = logging.getLogger(__name__)
+TIMEOUT: int = 60 * 3 # 3 minutes
def test_notebooks() -> None:
current_dir = os.getcwd()
for notebook_path in iterate_notebooks():
- LOGGER.info(f"Exeucting notebook {notebook_path}")
os.chdir(os.path.dirname(notebook_path))
with testbook(os.path.basename(notebook_path), execute=True, timeout=TIMEOUT):
diff --git a/tests/utils_for_tests.py b/tests/utils_for_tests.py
index 2ea2a248..9ea9dd19 100644
--- a/tests/utils_for_tests.py
+++ b/tests/utils_for_tests.py
@@ -9,10 +9,10 @@ def iterate_notebooks() -> Iterable[str]:
if os.environ.get("SHOULD_TEST_ALL_FILES", "") == "true":
notebooks_to_test = _get_all_notebooks()
else:
- # if os.environ.get("HAS_ANY_IPYNB_CHANGED", "") == "true":
- notebooks_to_test = os.environ.get("LIST_OF_IPYNB_CHANGED", "").split()
- # else:
- # notebooks_to_test = []
+ if os.environ.get("HAS_ANY_IPYNB_CHANGED", "") == "true":
+ notebooks_to_test = os.environ.get("LIST_OF_IPYNB_CHANGED", "").split()
+ else:
+ notebooks_to_test = []
return notebooks_to_test