Skip to content

Commit

Permalink
Updates for 0.53.0
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-naveh committed Oct 15, 2024
1 parent 5b5ce6d commit 18dffbd
Show file tree
Hide file tree
Showing 71 changed files with 1,557 additions and 343 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Pull requests are the best way to propose changes to the codebase. We actively w

In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://opensource.org/licenses/MIT) that covers the project. Feel free to contact the maintainers if that's a concern.

## Report bugs using GitHub's [issues](https://github.com/Classiq/classiq-library/issues)
## Report bugs using GitHub's [issues](https://github.com/[YourRepo]/issues)

We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/Classiq/classiq-library/issues/new); it's that easy!
We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/[YourRepo]/issues/new); it's that easy!

Write bug reports with detail, background, and sample code

Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<img src="README_resources/classiq-logo.svg" width="300" height="150">
</div>

# Classiq: High-Level Quantum Modeling Language
# Classiq

Classiq provides a powerful platform for **designing, optimizing, analyzing, and executing** quantum programs. This repository hosts a comprehensive collection of quantum functions, algorithms, applications, and tutorials built using the Classiq SDK and our native Qmod language.
Your entry-point for creating & running quantum programs.

Whether you're a researcher, developer, or student, Classiq helps you simplify complex quantum workflows and seamlessly transform quantum logic into optimized circuits by leveraging our **high-level functional design** approach. A user-friendly interface allows you to model, simulate, visualize, and execute quantum programs across various quantum hardware platforms.
This repository holds a wide collection of quantum functions, algorithms, applications and tutorials built with Classiq.

<hr> <br>

Expand All @@ -32,7 +32,7 @@ Whether you're a researcher, developer, or student, Classiq helps you simplify c
Working with Classiq's latest GUI requires no installations!
Just head over to [Classiq's platform](https://platform.classiq.io/) and follow the examples below over there :)

If you'd rather work programmatically using Python, Classiq also provides an SDK, which can be installed as follows:
If you'd rather work programmatically, using Python, Classiq also provides an SDK, which can be installed as follows:

```bash
pip install classiq
Expand All @@ -51,9 +51,9 @@ The `.ipynb` files are intended to be viewed inside [JupyterLab](https://jupyter

# Create Quantum Programs with Classiq

The simplest quantum circuit has 1 qubit and has a single `X` gate.
The simplest quantum circuit has 1 qubit, and has a single `X` gate.

Using Classiq's SDK, it would look like this:
Using Classiq's SDK, it would like like so:

```python
from classiq import *
Expand Down Expand Up @@ -115,7 +115,7 @@ def prep_minus(out: Output[QBit]) -> None:
H(out)
```

A part of the Deutsch Jozsa algorithm (see the full algorithm [here](/algorithms/deutsch_jozsa/deutsch_jozsa.ipynb))
A part of the Deutsch Jozsa algorithm (see the full algorithm [here](/algorithms/deutsch_josza/deutsch_jozsa.ipynb))

```python
@qfunc
Expand Down Expand Up @@ -258,7 +258,7 @@ print(result[0].value.parsed_counts)

The examples found in this repository can be accessed via [Classiq's platform](https://platform.classiq.io/), in the [`model`](https://platform.classiq.io/dsl-synthesis) tab, under the same folder structure.

Additionally, one may write their own model in the model editor (highlighted in green) or upload his own model (highlighted in red)
Additionally, one may write his own model in the model editor (highlighted in green) or upload his own model (highlighted in red)

![writing_models.png](README_resources/writing_models.png)

Expand Down Expand Up @@ -302,14 +302,14 @@ qfunc main(output res: qnum){

</center>

4. Press Run:
3. Press Run:
<center>

![Execution_Screenshot_3_plus_5.png](README_resources/Execution_Screenshot_3_plus_5.png)

</center>

5. View Results:
4. View Results:
<center>

![Jobs_Screenshot_3_plus_5.png](README_resources/Jobs_Screenshot_3_plus_5.png)
Expand Down
38 changes: 19 additions & 19 deletions algorithms/bernstein_vazirani/bernstein_vazirani.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
"id": "22ec3e91-cc89-43be-88d0-1a36639e5e4e",
"metadata": {},
"source": [
"The Bernstein-Vazirani (BV) algorithm [[1](#BVWiki)], named after Ethan Bernstein and Umesh Vazirani, is a basic quantum algorithm. It gives a linear speed-up with respect to its classical counterpart, in the oracle complexity setting.\n",
"The Bernstein-Vazirani (BV) algorithm [[1](#BVWiki)], named after Ethan Bernstein and Umesh Vazirani, is a basic quantum algorithm. It gives a linear speedup compared to its classical counterpart, in the oracle complexity setting.\n",
"\n",
"The algorithm treats the following problem:\n",
"\n",
"* **Input:** A Boolean function $f: \\{0,1\\}^n \\rightarrow \\{0,1\\}$ defined as\n",
"$$\n",
"f(x)\\equiv (x\\cdot a) \\,\\,\\mod 2,\n",
"$$\n",
"where the $ \\cdot$ refers to a bitwise dot operation, and $a$ is some binary string of length $n$.\n",
"where the $ \\cdot$ refers to a bitwise dot operation, and $a$ is a binary string of length $n$.\n",
"\n",
"* **Output:** Returns the secret string $a$ with the minimal inquries of the function.\n",
"* **Output:** Returns the secret string $a$ with minimum inquiries of the function.\n",
"\n",
"\n",
"Comments:\n",
"* This problem is a special case of the [hidden-shift problem](https://github.com/Classiq/classiq-library/blob/main/algorithms/algebraic/hidden_shift/hidden_shift.ipynb), where the goal is to find a secret string satisfing $f(x)=f(x\\oplus a)$, with $\\oplus$ indicating bitwise addition.\n",
"* The problem can be considered as a restricted version of the [Duetsch-Jozsa algorithm](https://github.com/Classiq/classiq-library/blob/main/algorithms/deutsch_jozsa/deutsch_jozsa.ipynb). In particular, the functional quantum circuit is identical for both problems.\n",
"* The problem is a restricted version of the [Deutsch-Jozsa algorithm](https://github.com/Classiq/classiq-library/blob/main/algorithms/deutsch_jozsa/deutsch_jozsa.ipynb). In particular, the functional quantum circuit is identical for both problems.\n",
"\n",
"***"
]
Expand All @@ -40,7 +40,7 @@
"jp-MarkdownHeadingCollapsed": true
},
"source": [
"Problem Hardness: Classically, the minimal inquiries of the function $f$ for determining the secret string is $n$: $f$ is called with the strings \n",
"Problem hardness: Classically, the minimum inquiries of the function $f$ for determining the secret string is $n$: $f$ is called with these strings: \n",
"$$\n",
"\\begin{eqnarray}\n",
"f(100\\dots0) &=& a_0, \\\\\n",
Expand All @@ -49,7 +49,7 @@
"f(00\\dots01)&=& a_{n-1},\n",
"\\end{eqnarray}\n",
"$$\n",
"which reveals the secret string, one bit at a time. **The BV algorithm finds the secret string using one function call (oracle inquiry); thus, providing a linear speed-up with respect to the classical solution.**"
"which reveals the secret string, one bit at a time. **The BV algorithm finds the secret string using one function call (oracle inquiry), thereby providing a linear speedup with respect to the classical solution.**"
]
},
{
Expand All @@ -71,7 +71,7 @@
"source": [
"## How to Build the Algorithm with Classiq\n",
"\n",
"The BV algorithm contains three function blocks: an oracle for the predicate $f$, \"sandwiched\" between two Hadamard transforms. The resulting state corresponds to the secret string. The full [mathematical derivation](#Technical-Notes) is given at the end of this notebook."
"The BV algorithm contains three function blocks: an oracle for the predicate $f$, \"sandwiched\" between two Hadamard transforms. The resulting state corresponds to the secret string. The full [mathematical derivation](#Technical-Notes) is at the end of this notebook."
]
},
{
Expand All @@ -81,7 +81,7 @@
"source": [
"### Implementing the BV Predicate\n",
"\n",
"A simple quantum implementation of the binary function $f(x)$ is by applying a series of controlled-X operations: starting with the state $|f\\rangle=|0\\rangle$, we apply an X gate on it, controlled on the $|x_i\\rangle$ state, for all $i$ such that $a_i=1$:\n",
"A simple quantum implementation of the binary function $f(x)$ applies a series of controlled-X operations: starting with the state $|f\\rangle=|0\\rangle$, we apply an X gate, controlled on the $|x_i\\rangle$ state, for all $i$ such that $a_i=1$:\n",
"$$\n",
" |x_0\\dots x_{n-1}\\rangle |0\\rangle_f \\rightarrow \\Pi_{i: a_i=1} {\\rm CX}(x_i,f) |x_0\\dots x_{n-1}\\rangle |0\\rangle_f = |x_0\\dots x_{n-1}\\rangle X^{a\\cdot x}|0\\rangle_f=|x_0\\dots x_{n-1}\\rangle |a\\cdot x \\left(\\text{ mod } 2\\right)\\rangle_f.\n",
"$$"
Expand Down Expand Up @@ -123,8 +123,8 @@
"source": [
"<center>\n",
"<img src=\"https://docs.classiq.io/resources/bernstein-vazirani_predicate.png\" style=\"width:80%\">\n",
"<figcaption align = \"middle\"> Figure 1. The Bernstein Vazirani Predicate $f(x)$ for a secret string $a=01101$, on $n$ qubits.\n",
"The quantum variable $x$ is stored on the 5 upper qubits and the resulting value of $f$ is on the lower-most qubit.</figcaption>\n",
"<figcaption align = \"middle\"> Figure 1. The Bernstein-Vazirani predicate $f(x)$ for a secret string $a=01101$, on $n$ qubits.\n",
"The quantum variable $x$ is stored on the five upper qubits and the resulting value of $f$ is on the lowermost qubit.</figcaption>\n",
"</center>"
]
},
Expand All @@ -135,7 +135,7 @@
"source": [
"### Implementing the BV Quantum Function\n",
"\n",
"The quantum part of the BV algorithm is essentially identical to the Deutch-Jozsa one, see `deutsch_jozsa` function in [Deutsch-Jozsa notebook](https://github.com/Classiq/classiq-library/blob/main/algorithms/deutsch_jozsa/deutsch_jozsa.ipynb). However, in contrast to the latter, the predicate function implementation is fixed, depending solely on the secret string $a$. Hereafter we refer to the secret string as a secret integer, defined as an integer argument for the `bv_function`:"
"The quantum part of the BV algorithm is essentially identical to the `deutsch_jozsa` function in the [Deutsch-Jozsa notebook](https://github.com/Classiq/classiq-library/blob/main/algorithms/deutsch_jozsa/deutsch_jozsa.ipynb). However, in contrast to the latter, the predicate function implementation is fixed, depending solely on the secret string $a$. Hereafter, we refer to the secret string as a secret integer, defined as an integer argument for the `bv_function`:"
]
},
{
Expand All @@ -160,13 +160,13 @@
"id": "134ef74c-180b-4b60-9b35-c64ee626c2db",
"metadata": {},
"source": [
"## An Example on 5 Qbits\n",
"## An Example on Five Qubits\n",
"\n",
"We construct a model for a specific example, setting the secret integer to $a=13$ and $n=5$.\n",
"\n",
"We can essentially set the number of shots to 1. This is because that under the assumption of noiseless execution, the resulting state is just the secret integer (see last equation Eq. ([1](#mjx-eqn-1)) below). In particular, the idea of using solely 1 shot was used to demonstrate algorithmic speedup in Ref. [[2](#ssBV)], where the authors considered a modified version of the BV algorithm in which the secret integer changes after every inquiry.\n",
"We can essentially set the number of shots to 1. This is because that under the assumption of noiseless execution, the resulting state is just the secret integer (see the last Eq. ([1](#mjx-eqn-1)) below). In particular, the idea of using solely one shot demonstrated algorithmic speedup in Ref. [[2](#ssBV)], where the authors considered a modified version of the BV algorithm in which the secret integer changes after every inquiry.\n",
"\n",
"In our example, we take `num_shots=1000` to highlight the fact that the resulting state is purely the secret string."
"In this example, we take `num_shots=1000` to highlight the fact that the resulting state is purely the secret string."
]
},
{
Expand Down Expand Up @@ -207,7 +207,7 @@
"id": "2e210edf-f2ce-478a-9118-655d1d64f0cc",
"metadata": {},
"source": [
"We can now visualize the circuit"
"We can now visualize the circuit:"
]
},
{
Expand Down Expand Up @@ -286,11 +286,11 @@
"id": "c8c52c24-f49b-424a-bd42-c881146b5921",
"metadata": {},
"source": [
"A brief summary of the linear algebra behind the Bernstein-Vazirani algorithm. The first Hadamard transformation generates an equal super-position over all the standard basis elements:\n",
"Here is a brief summary of the linear algebra behind the Bernstein-Vazirani 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",
"The oracle gets the boolean Bernstein-Vazirani predicate and adds an $e^{\\pi i}=-1$ phase to all states for which the function returns True:\n",
"The oracle gets the Boolean Bernstein-Vazirani predicate 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)^{a\\cdot j}|j\\rangle_n.\n",
"$$\n",
Expand All @@ -299,14 +299,14 @@
"\\frac{1}{2^{n/2}}\\sum^{2^n-1}_{j=0}(-1)^{a\\cdot 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)^{j\\cdot \\left(k\\oplus a \\right)} \\right) |k\\rangle.\n",
"$$\n",
"The final expression represents a super-position over all basis states $|k\\rangle$; however, one can verify that the amplitude of the state $|k\\rangle=|a\\rangle$ is simply 1, as $a\\oplus a =0$:\n",
"The final expression represents a superposition over all basis states $|k\\rangle$; however, we can verify that the amplitude of the state $|k\\rangle=|a\\rangle$ is simply one, as $a\\oplus a =0$:\n",
"$$\n",
"\\begin{equation*}\n",
"\\left(\\frac{1}{2^{n}}\\sum^{2^n-1}_{j=0}1 \\right) |a\\rangle + \\sum^{2^n-1}_{k\\neq a} 0 |k\\rangle = |a\\rangle.\n",
"\\tag{1}\n",
"\\end{equation*}\n",
"$$\n",
"Therefore, the final state is simply the secret string."
"Therefore, the final state is the secret string."
]
},
{
Expand Down
Loading

0 comments on commit 18dffbd

Please sign in to comment.