diff --git a/community/PushQuantum/final_challange_pushquantum.ipynb b/community/PushQuantum/final_challange_pushquantum.ipynb deleted file mode 100644 index aad9a1c4c..000000000 --- a/community/PushQuantum/final_challange_pushquantum.ipynb +++ /dev/null @@ -1,527 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "9136668b-7449-493d-9e3b-0a7b948c2d88", - "metadata": {}, - "source": [ - "
\n", - " \"classiq_logo\"\n", - " \"pushquantum_logo\"\n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "title", - "metadata": {}, - "source": [ - "# Classiq Challange: Estimating Molecular Spectra Using the Rodeo Algorithm" - ] - }, - { - "cell_type": "markdown", - "id": "6234c61c-2ffb-4ae4-ad97-433a05716bf2", - "metadata": {}, - "source": [ - "Welcome to the Classiq challenge of the 2024 PushQuantum Hackathon!\n", - "This Jupyter notebook is the framework for the challenge and you should follow it in order to solve it using Classiq.\n", - "\n", - "The notebook has 2 parts:\n", - "1. A warm-up session, just to get up to speed with a small example of Classiq\n", - "2. The challenge itself, including what you need to create, what's the format, and how you can check yourself\n", - "\n", - "Additional resources you should use are\n", - "- The IDE of the classiq platform at [platform.classiq.io](https://platform.classiq.io/)\n", - "- The [community Slack of Classiq](https://short.classiq.io/join-slack) - Classiq's team will answer any question you have over there, including implementation questions\n", - "- [Classiq's documentation](https://docs.classiq.io/latest/) with the dedicated:\n", - " - [Classiq 101](https://docs.classiq.io/latest/classiq_101/)\n", - " - [Python SDK Reference](https://docs.classiq.io/latest/sdk-reference/)\n", - " - [Our GitHub Repostory](https://github.com/Classiq/classiq-library)\n", - "\n", - "Good luck!" - ] - }, - { - "cell_type": "markdown", - "id": "3a4994cb-315b-4d87-ba64-95623ca36711", - "metadata": {}, - "source": [ - "### Challenge's Abstract" - ] - }, - { - "cell_type": "markdown", - "id": "613ea9c5-dcf9-4846-b4ef-ba3cd7b24b28", - "metadata": {}, - "source": [ - "Estimating the energy eigenvalues of a Hamiltonian is a fundamental task in quantum chemistry, material science and condensed matter physics. These eigenvalues provide critical insights into the underlying system, whether it be a molecule, material, or a more general quantum system. Many applications are based on the accurate estimation on the accurate estimation of the energy values like photodynamic therapy for cancer treatment, molecular drug design, and development of efficient energy storage devices.\n", - "\n", - "Quantum computers main advantage will arguably be 'to simulate nature', thus they might offer a crucial advantage in estimating the energy values of Hamiltonians representing molecules, proteins, and materials. \n", - "\n", - "The [Rodeo Algorithm](https://arxiv.org/pdf/2009.04092) is a quantum algorithm for estimating the energy eigenvalues of any given Hamiltonian within a specified energy interval. In this challenge, you will implement it using the Classiq platform! Specifically for this challenge, the Rodeo algorithm is used to solve molecular Hamiltonians.\n", - "\n", - "Roughly Speaking, the Rodeo Algorithm filters linearly spaced discrete sets of energies within a given interval, isolating and refining the true eigenvalues of the Hamiltonian. The algorithm can accurately identify energy levels by iteratively \"sweeping\" through the energy spectrum, making it a practical approach for quantum computations.\n", - "\n", - "This challenge provides an opportunity to implement a state-of-the-art quantum algorithm, bridging theoretical concepts with real-world applications in quantum computing.\n", - "\n", - "This is a scheme of the Rodeo Algorithm:" - ] - }, - { - "cell_type": "markdown", - "id": "5e18de0a-6131-4657-af9c-6688745545bf", - "metadata": {}, - "source": [ - "
\n", - " \"Rodeo.png\"\n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "e20137bf-c228-47c5-926d-91046a269ca6", - "metadata": {}, - "source": [ - "

\n", - "Fig.1 from the original paper: Rodeo Algorithm for Quantum Computing by Kenneth Choi et al.\n", - "

" - ] - }, - { - "cell_type": "markdown", - "id": "setup", - "metadata": {}, - "source": [ - "### Make Sure You Are Ready to Go" - ] - }, - { - "cell_type": "markdown", - "id": "install-classiq", - "metadata": {}, - "source": [ - "If you haven't done it yet, try running the following lines of code and use the [regestration and installation](https://docs.classiq.io/latest/classiq_101/registration_installations/) page if you are having difficulty setting up your environment.\\\n", - "Uncomment and run the following command to install or update to the latest version of the Classiq SDK (if not installed yet):" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "install-code", - "metadata": {}, - "outputs": [], - "source": [ - "# pip install -U classiq" - ] - }, - { - "cell_type": "markdown", - "id": "authenticate-classiq", - "metadata": {}, - "source": [ - "Uncomment and run the following command if your machine has not been authenticated yet:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "authenticate-code", - "metadata": {}, - "outputs": [], - "source": [ - "# import classiq\n", - "# classiq.authenticate()" - ] - }, - { - "cell_type": "markdown", - "id": "73abede7-6a19-4296-b4b0-33f1e1801679", - "metadata": {}, - "source": [ - "## Challenge Warm-Up" - ] - }, - { - "cell_type": "markdown", - "id": "c94b4ed3-dbc1-469c-9a6a-5ff8559ef3f6", - "metadata": {}, - "source": [ - "A quick warm-up task will ensure you are ready to dive into the challenge confidently. Here’s what you need to do:\n", - "\n", - "1. Create a `qfunc` named `prep`:\n", - " - This function should prepare the $|-\\rangle$ state, assuming the input state is $|0\\rangle$.\n", - "\n", - "2. Create a `qfunc` named `trotter`:\n", - " - This function should utilize the `suzuki_trotter()` method.\n", - " - Inputs: A variable of the type `QArray[QBit]`.\n", - " - Implementation details:\n", - " - Call the `suzuki_trotter()` function with the following parameters:\n", - " - `HAMILTONIAN`: Use the given dummy Hamiltonian.\n", - " - `evolution_coefficient`: Set to 1.\n", - " - `order`: Set to 1.\n", - " - `repetitions`: Set to 30.\n", - " - `qbv`: Pass the declared quantum variable.\n", - "\n", - "3. Create a `main` function:\n", - " - This function should:\n", - " - Use the `prep` function to prepare an auxiliary qubit named `aux` in the $|-\\rangle$ state.\n", - " - Use the auxiliary qubit as a `control` for the `trotter` function, which should act on another qubit. (Read more on `control`:[here](https://docs.classiq.io/latest/qmod-reference/language-reference/statements/control/?h=control))\n", - " - Finally, apply an `H` gate on the auxiliary qubit.\n", - "\n", - "By completing this warm-up, you will practice the essential steps needed for the challenge. Take it step by step, starting simple, and then make your code robust and adaptable!" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "7f3de58b-bcf1-4556-9e59-1c3cd4749ce3", - "metadata": {}, - "outputs": [], - "source": [ - "from classiq import *\n", - "\n", - "HAMILTONIAN = [PauliTerm([Pauli.I], 1)] # Dummy Hamiltonian" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "18bc5174-9fab-4f19-ba8e-4fb58763f01d", - "metadata": {}, - "outputs": [], - "source": [ - "### Your Code Goes Here: ###" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "09f0c14d-2c74-4661-81ab-ac5197ffea66", - "metadata": {}, - "outputs": [], - "source": [ - "qmod = create_model(main)\n", - "qprog = synthesize(qmod)\n", - "show(qprog)" - ] - }, - { - "cell_type": "markdown", - "id": "6b62fafe-0cf7-45ca-8103-3e6cfad4327f", - "metadata": {}, - "source": [ - "
\n", - "Preparation Task Reminder\n", - " \n", - "This is a reminder of the preparation task provided after the workshop:\n", - "\n", - "- Design your own Quantum Phase Estimation (QPE) algorithm using the Suzuki-Trotter method as the unitary.\n", - " - Learn more about QPE: [Wiki](https://en.wikipedia.org/wiki/Quantum_phase_estimation_algorithm)\n", - " - Refer to the Suzuki-Trotter Documentation: [Classiq Docs](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/qmod_core_library/hamiltonian_evolution/suzuki_trotter/suzuki_trotter/)\n", - "- Optionally, experiment by adding an RX rotation gate to the phase register (control qubits), where the angle for the n-th rotation qubit is set to π/n.\n", - "\n", - "If you've already completed these tasks, they may prove useful during the challenge. If not, consider taking this extra step to enhance your preparation. :)\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "0ff3314e-7312-4f9b-b2aa-9612c417c4dd", - "metadata": {}, - "source": [ - "While these task is not required for submission, keeping it in mind could help you adrass the more complex problem during the hackathon!" - ] - }, - { - "cell_type": "markdown", - "id": "challenge-start", - "metadata": {}, - "source": [ - "## The Challenge Itself" - ] - }, - { - "cell_type": "markdown", - "id": "8cd896ac-7f28-49ec-b51e-3f413000dc22", - "metadata": {}, - "source": [ - "The challenge is composed of 2 steps:\n", - "\n", - "1. In the first step, you will implement the algorithm to solve the simple Hamiltonian representing the H₂ molecule.\n", - "2. The second step will be to adapt your implementation to a more complex Hamiltonian representing the H₂O molecule\n", - "\n", - "This notebook should guide you (and help you) in successfully solving the challenge." - ] - }, - { - "cell_type": "markdown", - "id": "98ee6812-bd84-4252-9b77-fd9870b081fc", - "metadata": {}, - "source": [ - "Note that the Hamiltonians are given already in their Pauli form. Some assumptions were made to reduce the complexity and runtime for the sake of the hackathon" - ] - }, - { - "cell_type": "markdown", - "id": "903b9d48-3faf-4d99-9f35-f2c20e255bad", - "metadata": {}, - "source": [ - "### Submission" - ] - }, - { - "cell_type": "markdown", - "id": "aa701ef2-60c7-4e4d-b06a-aca7f54a75b5", - "metadata": {}, - "source": [ - "You are required to submit the following:\n", - "\n", - "1. Jupyter Notebook (`.ipynb`) \n", - " - Ensure your code and explanations are well-documented.\n", - "\n", - "2. Output graphs of Averaged Energy Population Distribution (for each part of the challenge): \n", - " - Plot normalized population as a function of energy values.\n", - " - Identify and mark the peaks on the graph.\n", - " - Specify the parameters used to produce the graph.\n", - "\n", - "3. Quantum program files (`.qprog`) \n", - " - Submit a `.qprog` file corresponding to each part of the challenge (you can use the `save_qprog` function defined below, or export it from the platform using it's GUI)\n", - "\n", - "Create a `.zip` file and submit it all together in the following link: [here](https://fvrn0h72gwo.typeform.com/to/WNGZ7hIH)" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "1d156298", - "metadata": {}, - "outputs": [], - "source": [ - "def save_qprog(qprog, file_name):\n", - " \"\"\"\n", - " A simple function that saves your quantum program (qprog) as a text file in a .qprog format.\n", - " The function saves the qprog in the same directory as the current Python file you are working on.\n", - "\n", - " Inputs:\n", - " - qprog: the quantum program (the returned value of the synthesize() function)\n", - " - file_name: a string that determines the file name\n", - " \"\"\"\n", - " file = open(file_name + \".qprog\", \"w\")\n", - " file.write(qprog)\n", - " file.close()" - ] - }, - { - "cell_type": "markdown", - "id": "61a913e1-fcac-4d99-9902-ef9608ad0da1", - "metadata": {}, - "source": [ - "### Evaluation Criteria" - ] - }, - { - "cell_type": "markdown", - "id": "05ed41a0-c590-47a9-bbec-50c3508ce766", - "metadata": {}, - "source": [ - "The evaluation criteria, in order of priority, are as follows:\n", - "\n", - "- Efficient use of high-level algorithmic design concepts\n", - "- Accurate solutions for each step\n", - "- Ability to explain your solution and the decisions made\n", - "- Readability\n", - "- Creativity" - ] - }, - { - "cell_type": "markdown", - "id": "fcf00e82-a448-4ee2-8cfa-49f7e2c3d632", - "metadata": {}, - "source": [ - "
\n", - "Hints\n", - "\n", - "- If you have completed the preparation task, use it for a smooth start.\n", - "- Try to understand the parameters of the problem and consider their significance.\n", - "- Experiment by running the algorithm with different parameter values to observe the effects.\n", - "- Identify which parts of the algorithm should be adapted for different Hamiltonians, as suggested by the paper, to optimize its results.\n", - "- It is always recommended to start simple and then try to make your code more robust and flexible.\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "part1-intro", - "metadata": {}, - "source": [ - "### Part 1: Implementing the Rodeo Algorithm for a 2D Hamiltonian" - ] - }, - { - "cell_type": "markdown", - "id": "70ebfaa3-4195-48f1-b820-b94a64a8efb1", - "metadata": {}, - "source": [ - "\n", - "In this part, you will implement the algorithm described in the paper to solve the following **2D Hamiltonian** representing the H₂ molecule:\n", - "\n", - "---\n", - "\n", - "#### Steps:\n", - "1. Find the eigenvalues of this Hamiltonian analytically using `hamiltonian_to_matrix(HAMILTONIAN)` and `numpy.`\n", - "2. Use Classiq’s SDK for efficient design of the Rodeo Algorithm to estimate the eigenvalues of the Hamiltonian." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "part1-hamiltonian", - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "\n", - "from classiq import *\n", - "\n", - "np.random.seed(0) # Please don't change\n", - "\n", - "# Define the 2D Hamiltonian\n", - "HAMILTONIAN = [\n", - " PauliTerm([Pauli.I, Pauli.I], -1.0523),\n", - " PauliTerm([Pauli.I, Pauli.Z], 0.3979),\n", - " PauliTerm([Pauli.Z, Pauli.I], -0.3979),\n", - " PauliTerm([Pauli.Z, Pauli.Z], -0.0112),\n", - " PauliTerm([Pauli.X, Pauli.X], 0.1809),\n", - "]" - ] - }, - { - "cell_type": "markdown", - "id": "70dac6e7-63ad-4446-8801-9aec7db33c57", - "metadata": {}, - "source": [ - "### Analytical Solution" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "8b82f870-3129-4ea3-bfea-d04004ad106f", - "metadata": {}, - "outputs": [], - "source": [ - "### Your Code Goes Here ###" - ] - }, - { - "cell_type": "markdown", - "id": "4c67245a-7bf8-4b97-a104-f0813763dd6e", - "metadata": {}, - "source": [ - "### Rodeo implementation for H₂ molecule" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "f1ca7374-e641-4a30-a9e5-4d8c66a92894", - "metadata": {}, - "outputs": [], - "source": [ - "### Your Code Goes Here ###\n", - "### Use as many cells as you need..." - ] - }, - { - "cell_type": "markdown", - "id": "99d6b9eb-b95f-40dd-b156-743d96d2a491", - "metadata": {}, - "source": [ - "### Part 2: Implementing the Rodeo Algorithm for a 6D Hamiltonian" - ] - }, - { - "cell_type": "markdown", - "id": "part2", - "metadata": {}, - "source": [ - "In this part, you will extend the implementation of the Rodeo Algorithm to solve a more complex 6D Hamiltonian, which represents a reduced model of the water H₂O molecule.\n", - "\n", - "The **goal is to find the five lowest energy levels of this Hamiltonian.**\n", - "\n", - "---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5714a550-e178-4936-bad7-5df6ff6b9e00", - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "\n", - "from classiq import *\n", - "\n", - "np.random.seed(0) # Please don't change\n", - "\n", - "HAMILTONIAN_H2O = [\n", - " PauliTerm([Pauli.I, Pauli.I, Pauli.I, Pauli.I, Pauli.I, Pauli.I], -12.533),\n", - " PauliTerm([Pauli.Z, Pauli.I, Pauli.I, Pauli.Z, Pauli.I, Pauli.I], -1.276),\n", - " PauliTerm([Pauli.Z, Pauli.Z, Pauli.I, Pauli.I, Pauli.I, Pauli.I], 0.627),\n", - " PauliTerm([Pauli.I, Pauli.Z, Pauli.I, Pauli.I, Pauli.Z, Pauli.I], -0.875),\n", - " PauliTerm([Pauli.I, Pauli.I, Pauli.Z, Pauli.Z, Pauli.I, Pauli.I], 0.452),\n", - " PauliTerm([Pauli.X, Pauli.I, Pauli.X, Pauli.I, Pauli.I, Pauli.I], 0.182),\n", - " PauliTerm([Pauli.I, Pauli.X, Pauli.I, Pauli.X, Pauli.I, Pauli.I], 0.139),\n", - " PauliTerm([Pauli.Y, Pauli.Y, Pauli.I, Pauli.I, Pauli.I, Pauli.I], -0.047),\n", - " PauliTerm([Pauli.Z, Pauli.I, Pauli.Z, Pauli.I, Pauli.Z, Pauli.I], 0.209),\n", - " PauliTerm([Pauli.Z, Pauli.Z, Pauli.Z, Pauli.Z, Pauli.I, Pauli.I], -0.154),\n", - " PauliTerm([Pauli.I, Pauli.Z, Pauli.I, Pauli.Z, Pauli.Z, Pauli.Z], 0.198),\n", - " PauliTerm([Pauli.X, Pauli.I, Pauli.I, Pauli.I, Pauli.X, Pauli.I], 0.061),\n", - " PauliTerm([Pauli.I, Pauli.I, Pauli.Y, Pauli.I, Pauli.Y, Pauli.I], -0.027),\n", - " PauliTerm([Pauli.Z, Pauli.I, Pauli.Z, Pauli.Z, Pauli.I, Pauli.Z], 0.118),\n", - "]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "bebb7230-4ef3-4cd8-aad3-7e9c01adb36f", - "metadata": {}, - "outputs": [], - "source": [ - "### Your Code Goes Here ###\n", - "### Use as many cells as you need..." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.9" - }, - "vscode": { - "interpreter": { - "hash": "529b62266d4f537a408698cf820854c65fe877011c7661f0f70aa11c4383fddc" - } - } - }, - "nbformat": 4, - "nbformat_minor": 5 -}