{"id":22882537,"url":"https://github.com/cqcl/ethz-hackathon22","last_synced_at":"2025-06-21T13:36:12.273Z","repository":{"id":95996592,"uuid":"478714966","full_name":"CQCL/ethz-hackathon22","owner":"CQCL","description":"The TKET challenges for the QEC Hackathon @ ETH. 8th-10th April 2022","archived":false,"fork":false,"pushed_at":"2022-04-07T13:52:24.000Z","size":324,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-12T10:09:25.266Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"OpenQASM","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CQCL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-06T20:22:11.000Z","updated_at":"2025-02-20T02:36:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"80eef4ba-762d-4df2-99b5-80479d76244a","html_url":"https://github.com/CQCL/ethz-hackathon22","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CQCL/ethz-hackathon22","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fethz-hackathon22","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fethz-hackathon22/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fethz-hackathon22/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fethz-hackathon22/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CQCL","download_url":"https://codeload.github.com/CQCL/ethz-hackathon22/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fethz-hackathon22/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261129905,"owners_count":23113910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-13T18:18:12.513Z","updated_at":"2025-06-21T13:36:07.224Z","avatar_url":"https://github.com/CQCL.png","language":"OpenQASM","funding_links":[],"categories":[],"sub_categories":[],"readme":"# QEC Hackathon: TKET challenges\n\nOn behalf of Cambridge Quantum and Quantinuum, welcome to the Quantum Hackathon!\nThis little guide should get you started quickly in `pytket`,\na high-performance Python library for building and simplifying quantum programs.\n\nIf any questions arise during the hackathon,\ndon't hesitate to contact me on Slack, or by email if you prefer!\n\nLuca Mondada: [luca.mondada@cambridgequantum.com](mailto:luca.mondada@cambridgequantum.com)\n\n## Installation\n\nFirst make sure that a recent version of\n[Python](https://www.python.org/downloads/) is installed on your machine.\nYou can check this in a terminal:\n```shell\npython --version\n```\nI would recommend using either `Python 3.9` or `Python 3.10`.\n\n### Create a virtual environment\nIt is usually best to create Python projects in independent environments,\nin order to avoid potentially conflicting dependencies between different packages.\nFor this hackathon, feel free to choose the virtual environment manager you prefer.\nAll Python code that follow will be the same in any virtual environment.\n[venv](https://docs.python.org/3/library/venv.html) is the most straight-forward choice, since this tool is shipped by default with your Python distribution.\nIf you do not feel comfortable in the terminal and/or are new to Python,\n[Anaconda](https://www.anaconda.com/products/individual) is an excellent alternative that manages the\nenvironments in a relatively transparent way and offers a graphical user interface.\nIt also plays nicely with Jupyter notebooks.\n\nTo use `venv`, create and activate a new virtual environment (I use `tket-env` as the name\nof the environment -- feel free to change this). Note that this command will create a new virtual environment in your current directory, so make sure you are in the desired folder.\n```shell\npython3 -m venv tket-env\nsource tket-env/bin/activate\n```\nIf you are on Windows, replace the second command with `tket-venv\\Scripts\\activate.bat`.\nNote that if you are using PowerShell or another shell (such as `fish` or `csh`), the script to run\nin the second command may change, please refer to the\n[documentation](https://docs.python.org/3/library/venv.html) for details.\n\n### Install pytket\nThe `tket` tool we will use in this hackathon is accessible through the Python package `pytket`.\nI would recommend you install `pytket-qiskit` at the same time.\n`pytket-qiskit` integrates `qiskit` into `pytket`,\nan IBM tool that, among other things, provides access to their quantum computers and numerous simulators.\nYou will thus be able to access all these features directly from `pytket`.\n\n```shell\npip install pytket pytket-qiskit\n```\n\n\u003e *tket and pytket: What's the difference?*\n\u003e\n\u003e `tket` encompasses the entire toolset of high-performance tools for quantum programming.\n\u003e `pytket` is the Python package that gives access to these features from Python.\n\nFor interactive development in Python, consider using Jupyter notebooks.\nInstall them with pip (or conda if you are using anaconda):\n```python\npip install jupyter notebook\n```\n\nIt's done! You are now ready for the hackathon!\n\n## The basics\nQuantum computers (and simulators) available today\ncan execute quantum programs given in a specific format,\ncalled a \"quantum circuit\".\nThese circuits can be seen as the equivalent of assembly in the world of classical computer science.\nYour work therefore consists in defining such quantum circuits so that they can\nthen be executed on the machine, or simulator, of your choice.\n\nTo define a circuit with 3 qubits:\n```python\nfrom pytket import Circuit\n\nn_qubits = 3\ncirc = Circuit(n_qubits)\n```\nThe `Circuit` documentation lists many very useful methods.\nI advise you to keep [this page](https://cqcl.github.io/pytket/build/html/circuit_class.html)\nopen as a reference.\n\nA circuit simply consists of a sequence of gates that act on a subset of the qubits\navailable, typically on one or two qubits.\nAmong the most common gates are the rotations (around the X, Y or Z axis) as well as the\n\"control-NOT\" (CNot), the controlled negation, also called `CX`.\n\nIt is easy to apply gates to our circuit:\n```python\n# a X rotation with angle pi/2 on the qubit 1\ncirc.Rx(0.5, 1)\n# a Z rotation with angle pi/4 on the qubit 0\ncirc.Rz(0.25, 0)\n# a CNot gate between qubits 0 and 2\ncirc.CX(0, 2)\n```\nThe list of all the gates available in pytket is quite long. It is\navailable in the documentation [here](https://cqcl.github.io/pytket/build/html/optype.html).\n\nWe still have to define the end of our circuit:\nto get the result of the circuit, we have to read out the qubits after the last operation.\nTo read out (\"measure\") all qubits\n```python\ncirc.measure_all()\n```\nThat's it! You have your first circuit!\n\nYou can view it at any time using `print(circ)`, or for an elegant\ngraphical visualisation, you can use the `pytket.circuit.display` module (this will only\nwork within a jupyter notebook instance -- you can also output the raw HTML, but you will\nneed a browser to visualise the result):\n```python\nfrom pytket.circuit.display import render_circuit_jupyter\nprint(tk_to_qiskit(circ))\n```\n\n## Run your circuit\nWe have seen how to define a circuit and visualize it,\nbut what can we do with it now?\n\nThere are two options: the _cool_ option would be to run this on a \"real\" quantum computer.\nThis is in fact possible: the machines available to the public usually expose an API\nthat allow you to submit and execute circuits remotely.\nFor all these machines, `tket` proposes extensions that allows you to execute your circuits\ndirectly from `pytket`\n(you will need an internet connection for this).\nThe list of these extensions can be found [here](https://cqcl.github.io/pytket/build/html/getting_started.html).\n\nThe problem is that this requires a key for the API in question, and for many machines\nthis is not free.\nA noteable exception is IBM,\nwhere everyone can get a key that gives access to certain IBM machines for free.\nTo obtain a key, follow the\n[instructions from IBM](https://quantum-computing.ibm.com/docs/manage/account/).\nBeing able to run a circuit on a real machine is fun,\nbut I must warn you that it is never without difficulties!\nIn particular, be prepared to stand and wait in a long queue before you get your\nresults back from IBM.\n\nThe second option is to simulate the execution of your circuit on your local computer.\nThis is the simplest solution, and the most used in practice, especially when it comes to iterating\nideas rapidly.\nFor example, use the qiskit simulator as follows.\nThis is complete example where we first define a circuit, then simplify it, and finally run the simulation.\n```python\nfrom pytket.backends.ibm import AerBackend # the simulator\n\n# defined the circuit as in the previous section\ncirc = Circuit(2, 2)\ncirc.Rx(0.3, 0).Ry(0.5, 1).CRz(-0.6, 1, 0).measure_all()\n\n# initializes the simulator\nbackend = AerBackend()\n# each machine and simulator have restrictions regarding\n# the gates that can be executed\n# the compilation of the circuit guarantees the circuit is in a format\n# recognized by simulator (or quantum computer)\nbackend.compile_circuit(circ)\n# runs the simulation\nhandle = backend.process_circuit(circ, n_shots=20)\n# gets the results\nshots = backend.get_result(handle).get_shots()\n```\n\nThis was a very short introduction.\nI can recommend\n[the following page](https://cqcl.github.io/pytket/build/html/manual_backend.html)\nfrom the `pytket` documentation\nto read more on executing circuits using quantum computers and simulators.\n\n## Benchmarking\nFor the duration of this hackathon, we provide a toolkit that you\ncan use for benchmarking your work, along with a database of over 200 circuits.\nIt can be found in the `benchmarking` folder.\nThis tool is internal to Quantinuum, please DO NOT SHARE outside\nthis hackathon and delete it at the end of the weekend.\n\n## What next?\nThis was a first glimpse of the workflow from the design\nof a quantum circuit to its execution.\nThere is much more to discover.\nThere is an entire series of example notebooks for `pytket`\navailable on the [pytket github](https://github.com/CQCL/pytket/tree/master/examples).\nI can only recommend that you look at them!\nIn particular, here is a selection you can go through\nas a continuation of this introduction:\n- [Run a circuit on the backends](https://github.com/CQCL/pytket/blob/master/examples/backends_example.ipynb)\n- [Circuit Optimization](https://github.com/CQCL/pytket/blob/master/examples/compilation_example.ipynb)\n- [Advanced techniques for creating circuits](https://github.com/CQCL/pytket/blob/master/examples/circuit_generation_example.ipynb)\n\n## Your tasks\nYou are now ready for the _real_ challenges!\nFor this hackathon, we have prepared two different tasks that you can try to\ntackle with TKET:\n 1. \"[Estimating phases with Hadamard Test and Cat States](hadamard_test.md)\". This problem explores some of the more theoretical questions around building applications of quantum computing for quantum chemistry and Hamiltonian simulation. A bit more maths and physics heavy.\n 2. \"[World-class routing](routing.md)\". Dive into the state-of-the-art of quantum circuit compilation. This problem is more applied, open-ended and programming-heavy: you'll have to come up with your own implementations and benchmark your results.\n\nIt is NOT expected that you solve both, so do pick your favourite!\n\nGood luck! Don't hesitate to reach out to us if you have any questions :wink:\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqcl%2Fethz-hackathon22","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcqcl%2Fethz-hackathon22","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqcl%2Fethz-hackathon22/lists"}