Skip to content

Commit

Permalink
fine tune
Browse files Browse the repository at this point in the history
  • Loading branch information
Dror Segman authored and Dror Segman committed Feb 16, 2025
1 parent 16fcc54 commit 5f489f4
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 3 deletions.
132 changes: 132 additions & 0 deletions tutorials/Classiq_tutorial/Execution_tutorial.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# [WIP] Execution Tutorial"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A typical workflow with classiq ends with the execution of a quantum program on a chosen simulator or hardware (and post-processing the results).\n",
"\n",
"\n",
"Another typical workflow, called _hybrid execution_ is based not on the execution of a single quantum program, but on iterative executions of quantum progarams that are tuned between iterations according to some classical logic (see for example the [VQE algorithm](https://en.wikipedia.org/wiki/Variational_quantum_eigensolver)).\n",
"\n",
"In this tutorial, we will cover the required knowledge for both usecases:\n",
"- Specifying the quantum backend (hardware or simulator) on which to run, and the `n_shots` number of times to run.\n",
"- use `ExecutionSession` as a context manager for the execution:\n",
" - Choosing between `sample` (measurement aling the z-axis) and `estimate` as the execution primitive.\n",
" - Creating parametric circuits and executing them for different parameter-values.\n",
" - Using batch-execution to obtain multiple results in a single command.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Specifying Backend and Number of Shots\n",
"\n",
"Let's look into the following quantum model:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Opening: https://platform.classiq.io/circuit/2t8Hqj0F0Ixb67vJRXiGzQLjy0G?version=0.68.0\n"
]
}
],
"source": [
"from classiq import *\n",
"\n",
"@qfunc\n",
"def main(x: Output[QBit]):\n",
" allocate(1, x)\n",
" RX(3.14, x)\n",
"\n",
"\n",
"qmod = create_model(main)\n",
"qprog = synthesize(qmod)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[***] show how to specify BE and n_shots, both in IDE and in code."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using Execution Session as a Context Manager\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[***] add subsections according to details in the first section.\n",
"use Nadav's notebook and the user guide as resources."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## [Internal]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"@qfunc\n",
"def main(x: Output[QBit], t: CReal, w: CReal):\n",
" allocate(1, x)\n",
" RX(t, x)\n",
" RZ(w, x)\n",
"\n",
"\n",
"qmod = create_model(main)\n",
"qprog = synthesize(qmod)\n",
"# execution_session = ExecutionSession(qprog)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "external-user-venv-PaJZMdG0-py3.11",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 1 addition & 1 deletion tutorials/Classiq_tutorial/Qmod_tutorial_part1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise #2 - Repeat\n",
"### Exercise #2 - The Repeat Statement\n",
"\n",
"Use Qmod's [`repeat`](https://docs.classiq.io/latest/qmod-reference/language-reference/statements/classical-control-flow/#classical-repeat) statement to create your own Hadamard Transform - a function that takes a `QArray` of an unspecified size and applies `H` to each of its qubits.\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion tutorials/Classiq_tutorial/classiq_overview_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"In this notebook we introduce a typical workflow with Classiq:\n",
"- **Designing a quantum algorithm** using the Qmod language and it's accompanied function library.\n",
"- **Synthesizing the algorithm** into a concrete circuit implementation.\n",
"- **Executing the algorithm** on a chosen simulator or quantum harware.\n",
"- **Executing the algorithm** on a chosen simulator or quantum hardware.\n",
"- **Post-processing** the results.\n",
"\n",
"Later tutorials dive into each of the above stages, providing hands-on interactive guides that go from the very basics to advanced usage. \n",
Expand Down
2 changes: 1 addition & 1 deletion tutorials/Classiq_tutorial/synthesis_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Synthesis\n",
"# Synthesis Tutorial\n",
"\n",
"Classiq synthesis engine takes a high-level program written in Classiq's Qmod language, and compiles it into an executable gate-based circuit.\\\n",
"In most cases, there is not a single implementation that is superior in all manners - there might be one implementation that requires the lowest number of qubits, another that minimizes the gate-count etc. \n",
Expand Down

0 comments on commit 5f489f4

Please sign in to comment.