├── .github └── ISSUE_TEMPLATE │ └── open-hackathon-final-submission.md ├── Code_of_Conduct.md ├── Floq_challenge.md ├── Open_Hackathon.md ├── QML_Challenges.md ├── QML_Challenges ├── README.md ├── circuit_training_100_template │ ├── 1.ans │ ├── 1.in │ ├── 2.ans │ ├── 2.in │ ├── circuit_training_100_template.py │ └── problem.pdf ├── circuit_training_200_template │ ├── 1.ans │ ├── 1.in │ ├── 2.ans │ ├── 2.in │ ├── circuit_training_200_template.py │ └── problem.pdf ├── circuit_training_500_template │ ├── 1.ans │ ├── 1.in │ ├── circuit_training_500_template.py │ └── problem.pdf ├── images │ ├── clar_req.PNG │ ├── clarifications.PNG │ ├── clarifications_send_respond.PNG │ ├── correct_submission.PNG │ ├── full_clar_req.PNG │ ├── logo-white-background.png │ ├── pending_submission.PNG │ ├── points.PNG │ ├── qhack-banner.png │ ├── register.PNG │ ├── submit.PNG │ └── submit_dialog.PNG ├── quantum_gradients_100_template │ ├── 1.ans │ ├── 1.in │ ├── 2.ans │ ├── 2.in │ ├── problem.pdf │ └── quantum_gradients_100_template.py ├── quantum_gradients_200_template │ ├── 1.ans │ ├── 1.in │ ├── 2.ans │ ├── 2.in │ ├── 3.ans │ ├── 3.in │ ├── problem.pdf │ └── quantum_gradients_200_template.py ├── quantum_gradients_500_template │ ├── 1.ans │ ├── 1.in │ ├── 2.ans │ ├── 2.in │ ├── problem.pdf │ └── quantum_gradients_500_template.py ├── requirements.txt ├── simple_circuits_20_template │ ├── 1.ans │ ├── 1.in │ ├── 2.ans │ ├── 2.in │ ├── problem.pdf │ └── simple_circuits_20_template.py ├── simple_circuits_30_template │ ├── 1.ans │ ├── 1.in │ ├── 2.ans │ ├── 2.in │ ├── problem.pdf │ └── simple_circuits_30_template.py ├── simple_circuits_50_template │ ├── 1.ans │ ├── 1.in │ ├── 2.ans │ ├── 2.in │ ├── problem.pdf │ └── simple_circuits_50_template.py ├── vqe_100_template │ ├── 1.ans │ ├── 1.in │ ├── 2.ans │ ├── 2.in │ ├── problem.pdf │ └── vqe_100_template.py ├── vqe_200_template │ ├── 1.ans │ ├── 1.in │ ├── 2.ans │ ├── 2.in │ ├── problem.pdf │ └── vqe_200_template.py └── vqe_500_template │ ├── 1.ans │ ├── 1.in │ ├── 2.ans │ ├── 2.in │ ├── problem.pdf │ └── vqe_500_template.py ├── README.md └── img ├── clar_req.png ├── clarifications.png ├── clarifications_send_respond.png ├── correct_submission.png ├── full_clar_req.png ├── pending_submission.png ├── points.png ├── problem_description_domjudge.png ├── qhack-banner.png ├── register.png ├── submit.png ├── submit_dialog.png └── submit_window.png /.github/ISSUE_TEMPLATE/open-hackathon-final-submission.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Open Hackathon Final Submission 3 | about: A template to be used for submitting your final QHack Open Hackathon project 4 | title: "[ENTRY] Your Project Title" 5 | labels: submission 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Team Name: 11 | 12 | *Your team's name (matching the name used on the QML Challenge Scoreboard)* 13 | 14 | ### Project Description: 15 | 16 | *A brief description of your project (1-2 paragraphs).* 17 | 18 | ### Presentation: 19 | 20 | *A hyperlink to an explanatory presentation of your team’s hackathon project in a non-technical form (e.g., video, blog post, jupyter notebook, website, slideshow, etc.).* 21 | 22 | ### Source code: 23 | 24 | *A hyperlink to the final source code for your team's hackathon project (e.g., a GitHub repo).* 25 | -------------------------------------------------------------------------------- /Code_of_Conduct.md: -------------------------------------------------------------------------------- 1 | # Xanadu QHACK Code of Conduct—2021 2 | 3 | Xanadu Quantum Technologies Inc ("the Company") is committed to providing a safe and respectful 4 | event environment that promotes diversity, inclusiveness, safety, and freedom from all types of 5 | discrimination*. The Company will take whatever steps are reasonable to create and protect all event 6 | attendees and participants. This policy applies to all those attending any Xanadu virtual event, 7 | including but not limited to attendees, Xanadu employees, speakers, and service providers. Every 8 | attendee is responsible for complying with this policy and working together to prevent any instances 9 | of unacceptable behaviour. 10 | 11 | ## Event Code of Conduct Principles 12 | 13 | Be gracious and respectful of all those participating in the event. Abstain from any behaviours 14 | that you ought to know are harassing or discriminatory (on camera, in writing, through audio). 15 | Communicate immediately any incidents/behaviours that are not aligned with this Policy. 16 | 17 | ## Definitions of Unacceptable Behaviour 18 | 19 | Below is a list of possible unacceptable behaviours. It is not intended to be all-inclusive. 20 | 21 | - insulting, intimidating, demeaning, annoying, embarrassing or otherwise offensive behaviour 22 | - inappropriate or unwelcome focus or comments on a person's physical characteristics or appearance 23 | - posting or showcasing violent, discriminatory, explicit, illegal or otherwise offensive pictures, 24 | photos, audio, or chat/text conversations 25 | - stalking or other intimidating behaviour 26 | - misuse of any confidential or proprietary information provided for or during the course of the 27 | event 28 | - disruptive noise or conversations that impact the smooth flow of the event 29 | - release of or publishing confidential or personal information 30 | - use of offensive language or gestures (e.g., sexually explicit, profanity, discriminatory slurs, 31 | etc.) 32 | 33 | ## Consequences for Non-Compliance 34 | 35 | Unacceptable behaviour will not be condoned at any time during the event and immediate action deemed 36 | appropriate in the circumstances by the event organizers will be taken. If someone is asked to 37 | cease any behaviour deemed to be unacceptable, immediate compliance is required. Other actions 38 | available to the organizers may include expulsion from the event, disqualification from contests, 39 | being banned from participating in the event chat, non-admission to future events, and contacting 40 | local law enforcement. 41 | 42 | ## Reporting of Non-Compliance 43 | 44 | If you experience, witness or know of an incident that entails unacceptable behaviour or actions, 45 | please report them as soon as possible to: 46 | 47 | - Rebecca Laramee (rebecca@xanadu.ai) - HR 48 | - Beth Adams (beth@xanadu.ai) 49 | 50 | If when using the service, you can also report instances to: Twitchevents@twitch.tv 51 | 52 | ## Summary 53 | 54 | Let's ensure we collectively produce a meaningful, engaging and respectful event. 55 | 56 | 57 | This Code of Conduct can be revised at any time and its contents are non-negotiable. Last updated: 58 | Jan. 12/20 59 | 60 | 61 | --- 62 | 63 | *Discrimination can come in different forms including: race, national or ethnic origin, colour, 64 | religion, age, sex, sexual orientation, gender identity or expression, marital status, family 65 | status, genetic characteristics, disability, and conviction for an offence for which a pardon has 66 | been granted or in respect of which a record suspension has been ordered. 67 | -------------------------------------------------------------------------------- /Floq_challenge.md: -------------------------------------------------------------------------------- 1 | 2 | ![image](img/qhack-banner.png) 3 | 4 | ## Floq Challenge 5 | 6 | The top 50 teams in the QML Challenge will each receive an API key for the alpha of Sandbox@Alphabet's Floq API. 7 | Contestants from these teams will be able to develop and test their QML creations on Floq's TPU-based 8 | high-performance quantum simulator for the duration of the Open Hackathon portion of the event. 9 | 10 | --- 11 | ### Prize 12 | 13 | **The team with the best usage of Floq by the end of the Open Hackathon will be eligible to receive a $2500 cash prize**. 14 | 15 | ### Timeline 16 | 17 | | Sun | Mon | Tue | Wed | Thu | Fri | Sat | 18 | |---|---|---|---|---|---|---| 19 | | | | | | | **Feb 19**: Earn access to Floq by ranking in top 50 on the [QML Challenges](QML_Challenges.md) Leaderboard | | 20 | | | **Feb 22**: Open Hackathon begins | | | | **Feb 26**: Open Hackathon concludes (6PM EST) | | 21 | 22 | --- 23 | 24 | ### How do I take part? 25 | 26 | To submit your team's entry for the Floq Prize, simply open an Issue on *[this GitHub repo](https://github.com/XanaduAI/QHack/issues/)* summarizing your Floq project by 6pm EST on Feb 26. **Make sure to add "[Floq]" to the title of your submission**. Specifically, this issue should contain: 27 | 28 | 1. The name of your team (matching the name used on the [QML Challenge](QML_Challenges.md) Scoreboard). 29 | 2. A brief description of your project (1-2 paragraphs). 30 | 3. A hyperlink to an explanatory presentation of your team’s hackathon project in a non-technical form (e.g., video, blog post, jupyter notebook, website, slideshow, etc.). 31 | 4. A hyperlink to the final source code for your team's hackathon project (e.g., a GitHub repo). 32 | 33 | --- 34 | 35 | Access to Floq and judging of the Floq challenge prize will be managed by the Sandbox team. 36 | -------------------------------------------------------------------------------- /Open_Hackathon.md: -------------------------------------------------------------------------------- 1 | ![image](img/qhack-banner.png) 2 | 3 | ## QHack Open Hackathon 4 | 5 | Show the world what you've got in this open-ended hackathon! 6 | 7 | --- 8 | ### Grand Prize 9 | 10 | **The top team will receive summer internships at [CERN](https://home.cern/) (up to 3 positions available)**. 11 | 12 | The winning entry will be determined based on the following collective criteria: 13 | 14 | *Open Hackathon project*: 15 | - Scientific and/or technical ability demonstrated. 16 | - Overall quality of presentation. 17 | - Depth of use of the quantum computing software and hardware stack. 18 | 19 | *QML Challenge Leaderboard*: 20 | - A max of 20 teams will have their projects judged for the Open Hackathon Grand Prize, based on the their position in the 21 | [QML Challenge Leaderboard](QML_Challenges.md) rankings. 22 | 23 | Some eligibility conditions apply. Please see [here](https://home.cern/summer-student-programme) and 24 | [here](https://jobs.smartrecruiters.com/CERN/743999725457995-cern-online-summer-student-programme-2021-member-and-non-member-states-) 25 | for a description of the CERN internship program. 26 | 27 | --- 28 | 29 | ### Power Ups 30 | 31 | **$4000 in AWS credits are available for up to 20 teams on Feb 24**. These credits can be used to finish off your hackathon project on AWS Braket. This Power Up is available independently of whether your team received any Power Ups from the QML Challenges. 32 | 33 | To submit an entry for this Power Up, your team must open a new Issue on *[this GitHub repo](https://github.com/XanaduAI/QHack/issues/new?assignees=&labels=Power+Up&template=open-hackathon-power-up-entry.md&title=%5BPower+Up%5D+Your+Project+Title)* 34 | which describes your (in-progress) hackathon project by Feb 24 at 12PM EST. Specifically, this issue should contain: 35 | 36 | 1. The name of your team (matching the name used on the [QML Challenge](QML_Challenges.md) Scoreboard). 37 | 2. A brief description of your Open Hackathon project (1-2 paragraphs). 38 | 3. A hyperlink to draft source code for your Open Hackathon project. 39 | 4. A 1-2 paragraph written **Resource Estimate**, indicating how you expect to use the additional AWS credits, if awarded, to finish your Open Hackathon project. 40 | 41 | ### Timeline 42 | 43 | | Sun | Mon | Tue | Wed | Thu | Fri | Sat | 44 | |---|---|---|---|---|---|---| 45 | | | | | | | **Feb 19**: Earn $250 Power Up AWS credits from [QML Challenge](QML_Challenges.md) Leaderboard | | 46 | | | **Feb 22**: Open Hackathon begins. Live stream on [twitch.tv/qhack](https://twitch.tv/qhack) to provide guidance on setting up and using Amazon Braket (10AM EST) | | **Feb 24**: Submit entry for $4000 Power Up AWS credits (by 12 PM EST) | | **Feb 26**: Open Hackathon concludes (6PM EST) | | 47 | 48 | --- 49 | 50 | ### How do I take part? 51 | 52 | To submit your team's entry for the Grand Prize, simply open an Issue on *[this GitHub repo](https://github.com/XanaduAI/QHack/issues/new?assignees=&labels=submission&template=open-hackathon-final-submission.md&title=%5BENTRY%5D+Your+Project+Title)* summarizing your project. 53 | Specifically, this issue should contain: 54 | 55 | 1. The name of your team (matching the name used on the [QML Challenge](QML_Challenges.md) Scoreboard). 56 | 2. A brief description of your project (1-2 paragraphs). 57 | 3. A hyperlink to an explanatory presentation of your team’s hackathon project in a non-technical form (e.g., video, blog post, jupyter notebook, website, slideshow, etc.). 58 | 4. A hyperlink to the final source code for your team's hackathon project (e.g., a GitHub repo). 59 | 60 | --- 61 | 62 | ### What hackathon project should my team do? 63 | 64 | The QHack Open Hackathon is open-ended. The choice of topic is completely up to you! 65 | You could brainstorm a new idea with your team, or start from one of the following seed ideas: 66 | 67 | 1. Implement a QML idea from the literature—or from one of our guest speaker presentations—in code 68 | 2. Create a self-contained tutorial or demonstration of an idea from QML (and submit it the 69 | [PennyLane Community page](https://pennylane.ai/qml/demos_community.html)!) 70 | 3. Extend one of the [QML Challenge](QML_Challenges.md) problems in a novel or interesting way 71 | 4. Repurpose one of the [PennyLane demos](https://pennylane.ai/qml/demonstrations.html) to run on a quantum hardware device 72 | 5. Submit a Pull Request to an open-source library with a new QML-related feature 73 | 74 | All entries are subject to the QHack [Terms & Conditions](https://qhack.ai/terms_and_conditions_2021.html). 75 | -------------------------------------------------------------------------------- /QML_Challenges.md: -------------------------------------------------------------------------------- 1 | ![image](img/qhack-banner.png) 2 | 3 | ## QHack QML Challenges 4 | 5 | Sharpen your quantum machine learning (QML) skills and compete against other teams for top spot! 6 | 7 | The QML Challenge contains 12 individual problems, ranging in difficulty from building basic 8 | quantum circuits to implementing QML workflows. The problems can be tackled in any order, 9 | and harder questions are worth more points. The problems can be tackled individually or 10 | as part of a team (limit of one account per team). 11 | 12 | The QML Challenges will remain open during the [QHack Open Hackathon](Open_Hackathon.md). Achieving a high rank on the [QML Challenge Scoreboard](https://challenge.qhack.ai/public) will improve your chances of claiming the Open Hackathon Grand Prize of summer internships at CERN. 13 | 14 | --- 15 | 16 | ### Power Ups 17 | 18 | You can tackle the QML Challenges at any time during QHack, but there are some *Power Ups* available 19 | to be won by those who start early. 20 | 21 | **The top 80 teams on the scoreboard at 6PM EST on Friday Feb 19 will receive $250 in AWS credits**. 22 | 23 | These credits can be used to build your [QHack Open Hackathon](Open_Hackathon.md) project. Teams can apply credits to any AWS service, including [Amazon Braket](https://aws.amazon.com/braket/), where they can showcase their ideas using Rigetti, IonQ, and D-Wave hardware or with high-performance simulators in the cloud. 24 | 25 | --- 26 | 27 | ### Timeline 28 | 29 | | Sun | Mon | Tue | Wed | Thu | Fri | Sat | 30 | |---|---|---|---|---|---|---| 31 | | | **Feb 15**: [Challenge portal](https://challenge.qhack.ai) opens | | **Feb 17**: Challenges available | | **Feb 19**: $250 in AWS credits each for top 80 teams (as of 6PM EST) | | 32 | | | **Feb 22**: Open Hackathon begins | | | | **Feb 26**: Challenge portal closes | | 33 | 34 | --- 35 | 36 | ### How do I take part? 37 | 38 | You will need to register your Team in order to be able to submit your solutions and claim your points. There can only be one account associated with each Team, so if you're a Team of more than one person you should designate someone as Team Captain to register on behalf of the Team and submit the Team's solutions. 39 | 40 | To register, go to https://challenge.qhack.ai/register and enter the following: 41 | 42 | 1. `Team name` - The name of your Team as it will appear on the Scoreboard. 43 | 2. `Email address` - The email address associated with the account. 44 | 3. `Username` - The login name for your account. You will use this login name to access your Team page. 45 | 4. `Password` - The password for accessing your account. 46 | 5. `Repeat Password` - Re-enter your password. 47 | 48 | ![](img/register.PNG) 49 | 50 | For more details about QML Challenge problems, submission, and scoring, check out our [how-to guide](https://github.com/XanaduAI/QHack/blob/main/QML_Challenges/README.md) once the challenges become available. 51 | 52 | All entries are subject to the QHack [Terms & Conditions](https://qhack.ai/terms_and_conditions_2021.html). 53 | -------------------------------------------------------------------------------- /QML_Challenges/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | # QHack 2021 Coding Challenge 6 | 7 | The [QHack 2021 Coding Challenge](https://challenge.qhack.ai) presents a series of QML-based coding challenges for you to tackle. Please read the following carefully for details on the scoring system, how to register and submit your problems, and other aspects of the challenge. 8 | 9 | ### Template files are provided for you to simplify the submission process for the [QHack 2021 Coding Challenge](https://challenge.qhack.ai). Please base your solutions off of these template files as any other form of submission will likely fail the judging process. [Get the template files here](https://github.com/XanaduAI/QHack/tree/main/QML_Challenges/). 10 | 11 | ## Table of Contents 12 | 1. [Scoring System](#scoring) 13 | 1. [Solution Assessment](#assess) 14 | 1. [Problem Categories](#categories) 15 | 1. [Submission Templates](#templates) 16 | 1. [What's in the Templates](#provided) 17 | 1. [Setting Up Your Environment](#setup) 18 | 1. [Testing Your Solutions](#testing) 19 | 1. [How to Register](#register) 20 | 1. [Submitting Your Solutions](#submit) 21 | 1. [Submission Outcomes](#outcomes) 22 | 1. [Clarifications](#clarifications) 23 | 1. [Lost Password](#lostpwd) 24 | 25 | ## Scoring system 26 | ### Points 27 | Each challenge problem is worth a set number of points. The scoring system is pass/fail, meaning either your submission passes the judging criteria and you receive all the points for that problem, or your submission fails and you receive no points for that submission. If your submission fails you can modify and resubmit an unlimited number of times until your submission passes. 28 | ### Time 29 | In addition to your score in points, the cumulative time of submission since the start of the contest is also taken into account. For example, if you submit a correct solution for your first problem 15 minutes into the Challenge, your cumulative submission time would be 15 minutes. If you then submit your second correct solution 1 hour into the challenge, your cumulative submission time would then be 75 minutes. Incorrect or failed submissions do not count towards your cumulative submission time. 30 | 31 | In the event of a tie between teams on points, the lowest cumulative submission time for successful submissions will break the tie. Your cumulative submission time in minutes is displayed next to your score on the Scoreboard: 32 | 33 | ![](images/points.PNG) 34 | 35 | ## Solution Assessment 36 | The scoring system works on an input/output basis. A set of inputs are fed into your submitted Python script via `stdin` and the generated outputs are compared against the expected results. For all outputs except floating-point numbers, an exact match is required (unless otherwise specified in the problem file). 37 | 38 | When the answer to a challenge problem is one or more floating point values, a submission will pass so long as each value is within a certain tolerance of its accepted answer. This tolerance varies from problem to problem and is always relative, i.e., the absolute value of the difference between your solution and the accepted solution, divided by the accepted solution, should be smaller than the tolerance. The specific tolerance for a given problem will be clearly stated in a table at the end of its problem statement. 39 | 40 | The assessment system is strictly pass/fail, so a submission must be correct and satisfy each criterion outlined in the problem for all points to be awarded. The constraints of the system dictate that very little feedback will be provided in the event that your submission is deemed incorrect, so if this is the case double check your solution locally and compare with the sample data before resubmitting. There is no penalty for a wrong submission, save the cumulative submission time. 41 | 42 | ## Problem Categories 43 | 44 | The Challenge problems are divided into 4 categories: 45 | 46 | - Simple Circuits 47 | - Quantum Gradients 48 | - Circuit Training 49 | - Variational Quantum Eigensolver (VQE) 50 | 51 | Each category contains 3 problems worth differing amounts of points. The "Simple Circuits" problem set contains questions valued at 20, 30, and 50 points. This category is intended primarily as a tutorial so you can get used to the submission process, as well as learn the basics of [PennyLane](https://pennylane.ai), the software library in which all the problems are written. The other three categories have problems valued at 100, 200, and 500 points. 52 | 53 | **The challenges may be completed in any order**, but for true beginners we recommend starting with the *Simple Circuits* problems before progressing to the more challenging ones. While in some cases solving the lower-valued problems will provide insight into the higher-valued ones, all of the problems are intended to be self-contained and do not require any code or numerical values to be carried forward through a category. 54 | 55 | ## Submission Templates 56 | 57 | Because of the strict submission requirements, it is strongly encouraged that you base your submissions off of the supplied [problem templates](https://github.com/XanaduAI/QHack/tree/main/QML_Challenges/). 58 | 59 | Avoid modifying these templates in any way beyond where it is indicated for you to do so, as this will most likely result in a failed submission. Even within the modifiable portion of the script, do not add any print statements or try to plot, as this will interfere with the assessment of the solution. 60 | 61 | Do not import any external libraries in these templates. The only libraries that will be available when your submission is run are those in the [requirements.txt file](https://github.com/XanaduAI/QHack/blob/main/QML_Challenges/requirements.txt) found in the [problem templates repository](https://github.com/XanaduAI/QHack/tree/main/QML_Challenges/). 62 | 63 | ### Downloading The Templates 64 | 65 | If you use git: 66 | 67 | ```console 68 | git clone https://github.com/XanaduAI/QHack.git 69 | ``` 70 | or 71 | ```console 72 | git clone git@github.com:XanaduAI/QHack.git 73 | ``` 74 | 75 | If you don't use `git`, you can download a zipped version of this repository [here](https://github.com/XanaduAI/QHack/archive/main.zip). 76 | 77 | ### What's Provided For You 78 | 79 | Every problem in the Coding Challenge has a corresponding directory nested under `QML_Challenges/` of the form `__template/`. Within each problem template folder are three types of files to help you with the coding challenges: 80 | 81 | 1. **problem.pdf** 82 | This is the statement of the problem you're being challenged to solve, along with any constraints that may be imposed. Read these over carefully before tackling the corresponding Coding Challenge problem. If you're having problems viewing these you can also find a description of the problems at [the Challenge Problems page](https://challenge.qhack.ai/public/problems). 83 | 84 | 2. **\_\_template.py** 85 | These are the Python coding templates required for submitting your solution to a particular problem. Read the docstrings within these files carefully to see what code is required from you and where exactly you should add your solution (typically between `# QHACK #` comment markers). 86 | **NOTE:** It is extremely important that you do not import any additional libraries or modify any of the code in these files other than where specified, as this may result in your submission failing the automated judging process. See the sections below on testing your solutions locally and submitting them for judging. 87 | 3. **\#.in and \#.ans files** 88 | The numbered `.in` and `.ans` files are the input and corresponding expected output, respectively, for your solution. They are the data files for the problem. Do not modify these files! Once you have added your code to the `<>_template.py` file, passing the `#.in` file to the modified `<>_template.py` file via `stdin` should result in output that matches the corresponding `#.ans` file. Your generated answer may not match the value(s) in the corresponding `#.ans` file exactly, but that's normal. As long as they match to within a tolerance specified in the `problem.pdf` file, then your solution will be judged to be correct. More details on how to test your solutions locally are provided in a section below. 89 | 90 | ## Setting Up Your Environment 91 | 92 | All solutions must be written in Python and be compatible with Python 3.7. Instructions for installing Python 3.7 are out of scope for this document, but many web resources exist for how to install Python 3.7 on your chosen OS. 93 | 94 | We have included a [requirements.txt](https://github.com/XanaduAI/QHack/blob/main/QML_Challenges/requirements.txt) file that specifies the libraries which you will need to be able to run and test your solutions locally. Installing these can be done on the command line via `pip`: 95 | 96 | ```console 97 | pip install -r requirements.txt 98 | ``` 99 | 100 | We recommend that you set up a virtual environment to keep these packages isolated from the rest of your installed Python libraries. Setting up a virtual environment is also out of scope for this document, but many tutorials for doing so with your Python distribution and OS are available online. 101 | 102 | ## Testing Your Solutions 103 | 104 | Once you have added your code to one of the solution templates, you can test if it is correct by supplying one of the `#.in` files for that problem to the solution script via stdin. 105 | 106 | For example, if you've added a solution for the 100 point Circuit Training problem and you want to test the solution using the first set of inputs, do the following: 107 | * Open a terminal console (`CMD`, `Terminal`, etc.) and navigate to the folder containing your solution 108 | * Run your modified Python template and pass in the inputs: 109 | `python ./circuit_training_100_template.py < 1.in` 110 | * Check what was output to the console. If everything worked, you should see a single number or series of comma delimited numbers and nothing else 111 | * Open the file `1.ans` for this problem and compare its contents to what was written to the command line. They should match to within some tolerance specified in the `problem.pdf` to be judged correct. 112 | 113 | ## How to Register 114 | You will need to register your Team in order to be able to submit your solutions and claim your points. There can only be one account associated with each Team, so if you're a Team of more than one person you should designate someone as Team Captain to register on behalf of the Team and submit the Team's solutions. 115 | 116 | To register, go to https://challenge.qhack.ai/register and enter the following: 117 | 118 | 1. `Team name` - The name of your Team as it will appear on the Scoreboard. 119 | 2. `Email address` - The email address associated with the account. 120 | 3. `Username` - The login name for your account. You will use this login name to access your Team page. 121 | 4. `Password` - The password for accessing your account. 122 | 5. `Repeat Password` - Re-enter your password. 123 | 124 | ![](images/register.PNG) 125 | 126 | Don't forget to read the [terms and conditions](https://qhack.ai/terms_and_conditions_2021.html) before registering. By registering, you agree to abide by the terms and conditions outlined therein. 127 | 128 | 129 | ## Submitting Your Solutions 130 | 131 | Once you're satisfied that you have the correct solution and have tested it using the supplied data, you can submit it to the Coding Challenge to earn the points associated with that problem. 132 | 133 | To submit your solution: 134 | 1. Log into your Team's account at https://challenge.qhack.ai/login with the Username and Password used to register your Team. 135 | 2. Click the green "Submit" button in the top right corner: 136 | 137 | ![](images/submit.PNG) 138 | 139 | 3. In the Submit pop-up window: 140 | a. Click "Browse", which will open a file navigator. Navigate to the location of your Python script solution, select it, and click "Open". 141 | b. Click the dropdown list under "Problem" to choose which problem you're submitting a solution for. 142 | c. If the Language drop-down list doesn't auto-populate with "Python 3", click the dropdown list under "Language" and choose "Python 3". That should be the only option. 143 | d. Click Submit! A popup will confirm your submission. 144 | 145 | ![](images/submit_dialog.PNG) 146 | 147 | Depending on the problem it can take anywhere from a few seconds to a few minutes to be assessed. In the meantime you should see a new entry under the Submissions section of the Team homepage (lower-left corner) with a `pending` result: 148 | 149 | ![](images/pending_submission.PNG) 150 | 151 | Once the submission has been assessed, the result will be updated. You may need to refresh the page to see the new status: 152 | 153 | ![](images/correct_submission.PNG) 154 | 155 | # Submission Outcomes 156 | There are several possible outcomes following a submission: 157 | 158 | ### Correct 159 | Congratulations! The points are yours. 160 | 161 | ### Wrong Answer 162 | Some part of your solution is incorrect. Double check that when run locally your outputs match the expected outputs to within the allowed tolerance. 163 | 164 | ### Run-Error 165 | Something in your solution caused the assessment process to fail. Double check that you don't have any print statements, warnings, imports of additional packages, or other run-time errors. 166 | 167 | ### Too-Late 168 | The contest has temporarily ended to award the prizes to the top Teams. Don't worry, once the contest is restarted this submission will be graded and appear on the scoreboard. 169 | 170 | ## Clarifications 171 | If you have a question about one of the problems that is not answered in the PDF description document for that problem, or suspect there is an error in one of the problems, or you would like to dispute an assessment, you can request a clarification by clicking the "request clarification" button on your Team's home screen: 172 | 173 | ![](images/clarifications.PNG) 174 | 175 | This will open a window where you can compose a message for the organizers: 176 | 177 | ![](images/clar_req.PNG) 178 | Under "Subject" you can choose a specific problem if this is a clarification for a particular problem, or specify that this is a general or technical question. 179 | 180 | To help us help you, please provide as much detail as possible. Please be aware that due to the large number of teams participating we will not be able to respond to clarification requests immediately. These messages are private and will only be seen by the organizers. 181 | 182 | Once submitted, a record of your clarification request will appear under the Clarification Requests section, and responses will appear under the Clarifications section directly above that. Clicking on either entry will give you the full text and details of the message: 183 | 184 | ![](images/clarifications_send_respond.PNG) 185 | 186 | ![](images/full_clar_req.PNG) 187 | 188 | ## Lost Password 189 | Unfortunately there is no mechanism for you to change or reset your password yourself, so please have your web browser remember your Team's login details, or record them some other way. If you have lost the password for your Team's account and need it reset you will need to contact `admin@qhack.ai` using the same email address you registered with the judging system. 190 | -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_100_template/1.ans: -------------------------------------------------------------------------------- 1 | 0.6174534088307637 2 | -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_100_template/1.in: -------------------------------------------------------------------------------- 1 | 0.863327072347624,0.0167108057202516,0.07991447085492759,0.0854049026262154,0.0167108057202516,0.8237963773906136,-0.07695947154193797,0.03131548733285282,0.07991447085492759,-0.07695947154193795,0.8355417021014687,-0.11345916130631205,0.08540490262621539,0.03131548733285283,-0.11345916130631205,0.758156886827099 2 | -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_100_template/2.ans: -------------------------------------------------------------------------------- 1 | 0.0024648812008861154 -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_100_template/2.in: -------------------------------------------------------------------------------- 1 | 0.32158897156285354,-0.20689268438270836,0.12366748295758379,-0.11737425017261123,-0.20689268438270836,0.7747346055276305,-0.05159966365446514,0.08215539696259792,0.12366748295758379,-0.05159966365446514,0.5769050487087416,0.3853362904758938,-0.11737425017261123,0.08215539696259792,0.3853362904758938,0.3986256655167206 -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_100_template/circuit_training_100_template.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python3 2 | import sys 3 | import pennylane as qml 4 | from pennylane import numpy as np 5 | 6 | # DO NOT MODIFY any of these parameters 7 | WIRES = 2 8 | LAYERS = 5 9 | NUM_PARAMETERS = LAYERS * WIRES * 3 10 | 11 | 12 | def optimize_circuit(params): 13 | """Minimize the variational circuit and return its minimum value. 14 | 15 | The code you write for this challenge should be completely contained within this function 16 | between the # QHACK # comment markers. You should create a device and convert the 17 | variational_circuit function into an executable QNode. Next, you should minimize the variational 18 | circuit using gradient-based optimization to update the input params. Return the optimized value 19 | of the QNode as a single floating-point number. 20 | 21 | Args: 22 | params (np.ndarray): Input parameters to be optimized, of dimension 30 23 | 24 | Returns: 25 | float: the value of the optimized QNode 26 | """ 27 | 28 | optimal_value = 0.0 29 | 30 | # QHACK # 31 | 32 | # Initialize the device 33 | # dev = ... 34 | 35 | # Instantiate the QNode 36 | # circuit = qml.QNode(variational_circuit, dev) 37 | 38 | # Minimize the circuit 39 | 40 | # QHACK # 41 | 42 | # Return the value of the minimized QNode 43 | return optimal_value 44 | 45 | 46 | def variational_circuit(params): 47 | """ 48 | # DO NOT MODIFY anything in this function! It is used to judge your solution. 49 | 50 | This is a template variational quantum circuit containing a fixed layout of gates with variable 51 | parameters. To be used as a QNode, it must either be wrapped with the @qml.qnode decorator or 52 | converted using the qml.QNode function (as shown above). 53 | 54 | The output of this circuit is the expectation value of a Hamiltonian. An unknown Hamiltonian 55 | will be used to judge your solution. 56 | 57 | Args: 58 | params (np.ndarray): An array of optimizable parameters of shape (30,) 59 | """ 60 | parameters = params.reshape((LAYERS, WIRES, 3)) 61 | qml.templates.StronglyEntanglingLayers(parameters, wires=range(WIRES)) 62 | return qml.expval(qml.Hermitian(hamiltonian, wires=[0, 1])) 63 | 64 | 65 | if __name__ == "__main__": 66 | # DO NOT MODIFY anything in this code block 67 | 68 | # Load and process Hamiltonian data 69 | hamiltonian = sys.stdin.read() 70 | hamiltonian = hamiltonian.split(",") 71 | hamiltonian = np.array(hamiltonian, float).reshape((2 ** WIRES, 2 ** WIRES)) 72 | 73 | # Generate random initial parameters 74 | np.random.seed(1967) 75 | initial_params = np.random.random(NUM_PARAMETERS) 76 | 77 | minimized_circuit = optimize_circuit(initial_params) 78 | print(f"{minimized_circuit:.6f}") 79 | -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_100_template/problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/circuit_training_100_template/problem.pdf -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_200_template/1.ans: -------------------------------------------------------------------------------- 1 | [2, 3, 4] -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_200_template/1.in: -------------------------------------------------------------------------------- 1 | {"directed": false, "multigraph": false, "graph": [], "nodes": [{"id": 0}, {"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}], "adjacency": [[{"id": 2}, {"id": 3}], [{"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}], [{"id": 0}, {"id": 1}], [{"id": 0}, {"id": 1}, {"id": 5}], [{"id": 1}, {"id": 5}], [{"id": 1}, {"id": 3}, {"id": 4}]], "params": [[0.007251195968545696, 0.0008594067983382697, 6.757788685303326e-05, -0.002960663108058259, -3.990107834181506e-05, 0.0008459551312108134, -0.001277886948034289, 0.0013917849664037338, 0.0050844175570855495, 0.0004046899603893801], [0.056410689341680226, 0.07332551003086096, 0.11573770360937545, 0.1471947383136579, 0.16520379259436668, 0.16107577283133256, 0.13346398582028385, 0.08533445938002224, 0.06505979609496622, 0.047259251575614024]]} -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_200_template/2.ans: -------------------------------------------------------------------------------- 1 | [0, 1, 2] -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_200_template/2.in: -------------------------------------------------------------------------------- 1 | {"directed": false, "multigraph": false, "graph": [], "nodes": [{"id": 0}, {"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}], "adjacency": [[{"id": 3}, {"id": 4}], [{"id": 4}, {"id": 5}], [{"id": 3}, {"id": 5}], [{"id": 0}, {"id": 2}, {"id": 4}], [{"id": 0}, {"id": 1}, {"id": 3}], [{"id": 1}, {"id": 2}]], "params": [[0.00725119586350819, 0.0006993146552754333, 0.00018938653033438184, -0.002576694936729869, 0.000184128566739523, 0.0007971715773060028, -0.001474030227059991, 0.001133453129607066, 0.004748509435854284, -2.719819887597862e-05], [0.023501757757741343, 0.04041058176918198, 0.10033413722212867, 0.1891521087372252, 0.24644283314811008, 0.2038888864247133, 0.12928227840808193, 0.06257051158195509, 0.04319572071910715, 0.02744074527290291]]} -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_200_template/circuit_training_200_template.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python3 2 | import json 3 | import sys 4 | import networkx as nx 5 | import numpy as np 6 | import pennylane as qml 7 | 8 | 9 | # DO NOT MODIFY any of these parameters 10 | NODES = 6 11 | N_LAYERS = 10 12 | 13 | 14 | def find_max_independent_set(graph, params): 15 | """Find the maximum independent set of an input graph given some optimized QAOA parameters. 16 | 17 | The code you write for this challenge should be completely contained within this function 18 | between the # QHACK # comment markers. You should create a device, set up the QAOA ansatz circuit 19 | and measure the probabilities of that circuit using the given optimized parameters. Your next 20 | step will be to analyze the probabilities and determine the maximum independent set of the 21 | graph. Return the maximum independent set as an ordered list of nodes. 22 | 23 | Args: 24 | graph (nx.Graph): A NetworkX graph 25 | params (np.ndarray): Optimized QAOA parameters of shape (2, 10) 26 | 27 | Returns: 28 | list[int]: the maximum independent set, specified as a list of nodes in ascending order 29 | """ 30 | 31 | max_ind_set = [] 32 | 33 | # QHACK # 34 | 35 | # QHACK # 36 | 37 | return max_ind_set 38 | 39 | 40 | if __name__ == "__main__": 41 | # DO NOT MODIFY anything in this code block 42 | 43 | # Load and process input 44 | graph_string = sys.stdin.read() 45 | graph_data = json.loads(graph_string) 46 | 47 | params = np.array(graph_data.pop("params")) 48 | graph = nx.json_graph.adjacency_graph(graph_data) 49 | 50 | max_independent_set = find_max_independent_set(graph, params) 51 | 52 | print(max_independent_set) 53 | -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_200_template/problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/circuit_training_200_template/problem.pdf -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_500_template/1.ans: -------------------------------------------------------------------------------- 1 | 1,0,-1,0,-1,1,-1,-1,0,-1,1,-1,0,1,0,-1,-1,0,0,1,1,0,-1,0,0,-1,0,-1,0,0,1,1,-1,-1,-1,0,-1,0,1,0,-1,1,1,0,-1,-1,-1,-1,0,0 -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_500_template/1.in: -------------------------------------------------------------------------------- 1 | 0.46586604,0.47378893,0.22608081S0.32045034,0.26276939,0.12634708S-0.2470099,0.11383845,0.14686661S-0.39945595,0.12837791,0.16662385S-0.33023235,-0.12453634,0.19838102S0.0389054,-0.69261027,-1.21261411S0.42256658,0.14487072,0.35552406S0.0303721,-0.85336874,-1.18990811S-0.392693,0.19513864,0.17895097S0.18111608,-0.72151142,-0.95512507S-1.05264143e-03,-8.30227549e-01,-1.09879603e+00S0.03193414,-0.8447708,-1.02092673S0.19179465,-0.82053591,-1.11369488S0.07828842,-0.72121359,-1.03063612S-0.04261801,-0.83277986,-1.16934362S0.58582894,0.18689473,-0.0158016S0.47054132,0.45185067,0.11082881S-0.53220502,0.0745649,0.35702981S0.48842563,0.45346625,0.14954127S-0.5160971,0.19909077,0.2903203S0.05038535,-0.76699001,-1.07848612S-0.32660025,0.10945672,0.2024972S-0.5394994,0.22455073,0.20148256S0.5528424,0.31794484,0.09053302S0.47420368,0.33399085,-0.10304811S0.10312505,-0.7574786,-1.06435887S-0.62605291,0.06582095,0.36379447S0.31580511,0.32184123,-0.05351776S0.02968595,-0.91284674,-1.05289105S0.51966568,0.21633931,0.00648104S-0.07171478,-0.74513965,-1.15804761S0.40814842,0.45010358,0.05821922S0.04098097,-0.73361912,-1.10153893S0.05528618,-0.82638083,-0.99978546S0.55454061,0.33737905,0.01419551S-0.12677521,-0.75799267,-1.07740539S0.57376841,0.35411985,0.21902689S0.4628419,0.07548531,-0.01007068S-0.58499139,0.10132561,0.21754139S0.07461424,-0.77871035,-1.0814442S0.04051597,-0.72213868,-1.07933982S-0.45372273,0.3255691,0.33714207S0.03049757,-0.7809584,-1.21679712S0.71585987,0.22307051,-0.02668602S0.04026284,-0.89483754,-1.11810609S-0.6542349,0.02911683,0.18016644S-0.38597985,0.15599033,0.28498535S-0.60542281,-0.0215697,0.09006117S0.43969367,0.26848854,0.21111782S-0.01066465,-0.7473321,-1.02239483S0.38351869,0.44920541,-0.00296667S-0.67475164,0.10728927,0.25117917S0.43779221,0.31314116,0.12134041S-0.4990913,0.06831219,0.28735811S-0.56260046,0.08317784,0.10553639S-0.52682539,0.12420713,0.26004478S0.73364561,0.22928562,0.12229883S-0.0862039,-0.8800752,-1.3127185S0.57259556,0.05797397,0.1872531S-0.07674491,-0.78915102,-1.04782222S0.01081953,-0.68319945,-1.09432826S-0.49812869,0.16354196,0.19889403S-0.51589701,0.16000079,0.23662374S0.45003143,0.462059,-0.00046733S0.05196018,-0.86911901,-1.10572119S-0.09753183,-0.85924584,-1.2269797S-0.4387632,0.15434547,0.0945755S0.59692774,0.36828036,0.14479708S0.0945115,-1.00601545,-1.02386254S-0.02123672,-0.77908428,-0.91771505S-0.65315483,0.08252364,0.25992099S0.67920258,0.2535962,0.20332562S-0.51183021,0.33269296,0.02382962S0.03680035,-0.69996054,-1.2431507S0.093765,-0.82435502,-1.11777769S0.61758073,0.21074834,0.13390901S0.49244136,0.45368496,0.21100953S0.67153403,0.31335057,-0.0407779S-0.026173,-0.6268307,-1.0917989S-0.06618392,-0.82217384,-1.19868385S-0.59430397,-0.0392231,0.22348787S0.07648112,-0.89752536,-1.05764044S0.48571867,0.15742808,0.02545175S-0.52120387,0.05263318,0.05963792S0.46024834,0.46043696,0.1053023S0.43438268,0.18056089,0.34202475S-0.02439888,-0.85495369,-0.97373313S0.72267864,0.36271745,0.1392846S0.55364728,0.5956439,0.33923943S0.15663361,-1.01904261,-1.0090487S0.66453117,0.25252449,0.02474578S-0.01086562,-0.89226463,-1.13267025S0.61897491,0.49558478,0.11806663S-0.55912684,0.00742588,0.28311342S0.47177323,0.52614687,0.07675935S-0.12936416,-0.7821488,-1.08664497S0.61024675,0.14144255,0.03989248S-0.4507991,0.15829516,0.32716214S-0.08600944,-0.89287022,-0.99519577S-0.57401578,0.03659592,0.29150285S-0.61407857,0.09140983,0.1149462S-0.11362972,-0.73153221,-0.89771388S-0.649895,0.01662504,0.38531355S0.48865657,0.28472007,0.15177966S-0.4238432,0.08970976,0.15635289S-0.19565303,-0.83061094,-0.9649536S0.44306604,0.34002029,0.14302506S0.02977696,-0.86546233,-0.92870379S0.02677424,-0.81553439,-0.95730639S0.40994897,0.06150972,0.16046814S-0.07149889,-0.58208198,-1.0126174S-0.4659447,0.10283548,0.23093765S0.0874035,-0.69179745,-1.17117445S0.07873183,-0.66866557,-1.0784978S-0.48526743,0.14742026,0.27828786S0.09190276,-0.79045987,-1.05934517S0.50158225,0.16731197,0.16655285S-0.49948252,0.1593856,0.15049781S-0.31022551,-0.83829793,-1.10310754S-0.43075831,-0.06022182,-0.01180528S-0.14821455,-0.64819591,-1.07327132S0.43720573,0.46041497,0.01054351S0.04570713,-0.90472892,-0.89905817S-0.44126533,0.01203136,0.28900837S-0.45907141,0.11804302,0.08849841S0.48040568,0.25875523,0.04843328S0.01843911,-0.88741668,-1.19135387S0.58460096,0.34593132,-0.04856142S0.01384269,-0.73927445,-1.307374S0.00978928,-0.92487141,-1.08016442S0.4685007,0.15819096,-0.16311592S0.54811454,0.14682222,0.13901901S0.15005457,-0.67760829,-1.13745619S0.04058434,-0.85258189,-1.01363624S-0.44111201,0.30476937,0.17434411S-0.43616802,0.04681985,0.09555649S0.03431215,-0.93870912,-1.09438437S-0.52026004,0.14616853,0.25724309S-0.07031338,-0.82580299,-1.24194729S0.43817817,0.26749891,0.00132841S-0.39727368,0.36360971,0.27369237S0.33579518,0.25544255,0.16081367S0.29565719,0.45793857,0.0088813S-0.69896537,0.22678934,0.31350039S0.68222586,0.30100997,0.0437635S0.06622169,-0.85673734,-1.08118111S0.39282617,0.40234595,0.07506095S0.4857379,0.40896801,0.09344525S0.09212053,-0.72413501,-1.11650161S0.48557014,0.47273349,0.05720922S0.40308302,0.32246697,0.1064751S0.04940429,-0.85262005,-1.05449176S-0.5709479,0.03059745,0.04632767S-0.32793971,0.16124178,0.11995423S-0.38727553,-0.01855078,0.14433199S-0.57288858,0.05819425,0.2128305S-0.44641997,0.09128043,0.17438835S-0.5388403,0.19547007,0.19265951S-0.46334851,0.04242189,0.01612979S-0.09027154,-0.82974333,-1.2803292S0.35286716,0.22740138,0.10365117S-0.49228514,0.24978623,0.25686715S-0.5515381,0.20386659,0.30912911S0.15081505,-0.64879687,-0.93230771S0.37647883,0.22106232,0.18501978S-0.51215301,0.13692542,0.33482324S0.19329546,-0.74397745,-1.11249596S0.35472537,0.18899633,0.16715468S0.25607355,-0.68506018,-1.0159854S-0.05006557,-0.84420898,-1.04856424S-0.6696455,-0.07078573,0.25819087S-0.52644077,0.1145212,0.27219853S-0.12086319,-0.87598717,-1.07481487S-0.02347173,-0.69527117,-1.03966941S0.27546678,0.18010707,0.03962739S-0.50349136,0.03996178,0.28809504S0.361913,0.25842202,-0.04467126S-0.486705,-0.00678971,0.17854482S-0.0109565,-0.83968616,-1.18119864S-0.44638261,0.153507,0.17845016S0.07907108,-0.9432001,-1.24285891S-0.6350216,0.12039336,0.30715785S0.53217484,0.48816189,0.1367248S-0.60475111,0.08481663,0.23978851S-0.56765376,0.20918336,0.23348368S0.42801955,0.41959682,-0.02780118S0.4537108,0.29892194,-0.007192S-0.42762038,0.01964222,0.19056254S-0.14286424,-0.78978904,-1.20412948S0.06545285,-0.8167159,-1.22056366S0.59288922,0.51284355,0.15308085S-0.56120165,0.07225466,0.21966416S-0.3046686,0.05909879,0.35408052S0.4059693,0.26914838,0.13116571S-0.60878222,0.00358776,0.18593209S0.56745109,0.34224198,0.04420631S0.01543166,-0.8627333,-1.12044789S-0.59675659,0.28948505,0.00620695S-0.61216729,0.01620428,0.37048954S0.4687038,0.2360237,-0.07085847S-0.39932125,-0.01787135,0.1464044S-0.0779351,-0.97742816,-1.24662387S0.55342681,0.27456298,0.10023086S-0.52632321,0.03873461,0.25587369S0.60932188,0.26730498,0.08386286S-0.5468856,0.14761694,0.19828914S0.50265234,0.2803291,0.15565181S0.50242088,0.38989093,0.10242419S-0.47331057,0.02960588,0.20604749S-0.390229,0.24606526,0.27444132S0.07082366,-0.86312888,-1.15055461S-0.11870875,-0.89684984,-1.17832286S-0.00570379,-0.96989012,-1.15215462S-0.05258215,-0.85653616,-1.18856003S0.44722429,0.10055292,0.22554921S-0.46825365,0.18293021,0.26021155S-0.32421996,0.1153384,0.43635607S-0.44895139,-0.00675816,0.16446145S-0.02405064,-0.80741547,-1.14534244S-0.08678338,-0.79367383,-1.25331018S-0.01176539,-0.90345712,-1.06134848S0.60368723,0.26664392,0.21098173S0.59228637,0.25749427,-0.03103904S0.02343695,-0.67062437,-1.05584209S-0.47919673,0.12929776,0.27040821S0.43067021,0.24403681,0.18764622S-9.80510794e-04,-7.78606407e-01,-1.11240060e+00S-0.03937763,-0.77818193,-0.86033624S0.11202435,-0.82316473,-1.13125001S0.09485221,-0.72091877,-1.00720028S-0.03981215,-0.71906963,-1.28503853S0.48624908,0.17573623,0.06495013S-0.6050599,0.06255691,0.15804105S0.51627082,0.15613921,0.14858059S-0.64720412,0.0108199,0.2177732S-0.02710453,-0.9602563,-1.13461416S0.17018809,-0.81138114,-1.2630477S-0.61275141,0.16667063,0.08132574S-9.63246246e-04,-7.67162617e-01,-1.11932576e+00S-0.68456712,0.02955131,0.27780692S-0.48359735,0.09448787,0.19638433S-0.00616263,-0.67181641,-1.11448527S0.58366468,0.2620044,0.15242718S0.44313635,0.39350841,0.1859868S0.50905599,0.35109706,0.15049542S-0.00560399,-0.73204938,-1.00018059S0.61192557,0.41979195,0.12643753S0.46006123,0.45097321,-0.09123281S0.4417727,0.49338651,-0.02635283S-0.5145514,0.1683735,0.08893038XXX-1,-1,0,0,0,1,-1,1,0,1,1,1,1,1,1,-1,-1,0,-1,0,1,0,0,-1,-1,1,0,-1,1,-1,1,-1,1,1,-1,1,-1,-1,0,1,1,0,1,-1,1,0,0,0,-1,1,-1,0,-1,0,0,0,-1,1,-1,1,1,0,0,-1,1,1,0,-1,1,1,0,-1,0,1,1,-1,-1,-1,1,1,0,1,-1,0,-1,-1,1,-1,-1,1,-1,1,-1,0,-1,1,-1,0,1,0,0,1,0,-1,0,1,-1,1,1,-1,1,0,1,1,0,1,-1,0,1,0,1,-1,1,0,0,-1,1,-1,1,1,-1,-1,1,1,0,0,1,0,1,-1,0,-1,-1,0,-1,1,-1,-1,1,-1,-1,1,0,0,0,0,0,0,0,1,-1,0,0,1,-1,0,1,-1,1,1,0,0,1,1,-1,0,-1,0,1,0,1,0,-1,0,0,-1,-1,0,1,1,-1,0,0,-1,0,-1,1,0,0,-1,0,1,-1,0,-1,0,-1,-1,0,0,1,1,1,1,-1,0,0,0,1,1,1,-1,-1,1,0,-1,1,1,1,1,1,-1,0,-1,0,1,1,0,1,0,0,1,-1,-1,-1,1,-1,-1,-1,0XXX0.12689905,-0.7876047,-1.04365684S-0.52928694,0.11086547,0.20601985S0.5413154,0.3257977,-0.03238584S-0.43583611,0.13031294,0.29235773S0.66318733,0.17057945,0.25993422S0.13148431,-0.81582835,-1.04274795S0.45728263,0.39285875,0.06578703S0.55778387,0.17225289,-0.05135452S-0.47337053,0.13150477,0.25531901S0.37402566,0.2288446,0.29849314S-0.04105624,-0.88310185,-1.26749672S0.36695866,0.08880251,0.17892788S-0.48681198,0.18338072,0.26290681S-0.12915649,-0.94720221,-0.98128788S-0.36073185,0.11309875,0.16648451S0.40329104,0.32851071,0.10590837S0.53482868,0.35756364,0.05003754S-0.56117433,0.14090643,0.19954084S-0.48740957,-0.00051926,0.14699825S-0.07878229,-0.74275105,-1.11175667S0.06464298,-0.79461881,-1.33876567S-0.55054152,-0.07516366,0.11377265S0.60145565,0.22853613,0.00187534S-0.53967129,0.06017085,0.26616341S-0.46334692,0.13403597,0.32699485S0.45110893,0.31357292,0.10853206S-0.59676644,0.04037497,0.08384752S0.44793517,0.24868385,0.22297004S-0.40056483,0.04379854,0.23161959S-0.36317322,-0.00079074,0.23785054S0.25583087,-0.70569337,-1.1897083S0.00824735,-0.83002815,-1.10464594S0.57550495,0.32959665,0.1022398S0.7320316,0.3659234,0.18194847S0.46964819,0.30542544,0.19123075S-0.37876803,0.1077081,-0.04668136S0.37610909,0.42549055,0.14437636S-0.58397032,0.26809614,-0.00356644S0.10034199,-0.86862374,-1.28600421S-0.5804329,0.04154192,0.49486592S0.43392778,0.2090735,-0.03603803S0.26752925,-0.61200971,-1.00852761S0.02894648,-0.75668963,-1.14014966S-0.63152242,0.1417931,0.19207808S0.43507801,0.14127869,0.12733744S0.48594366,0.34472895,-0.02644236S0.41848143,0.4600378,0.25659156S0.61341124,0.23596843,0.23190163S-0.49730768,0.37092863,0.27156937S-0.55288172,0.18678882,0.02385478 -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_500_template/circuit_training_500_template.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python3 2 | 3 | import sys 4 | import pennylane as qml 5 | import numpy as np 6 | 7 | 8 | def classify_data(X_train, Y_train, X_test): 9 | """Develop and train your very own variational quantum classifier. 10 | 11 | Use the provided training data to train your classifier. The code you write 12 | for this challenge should be completely contained within this function 13 | between the # QHACK # comment markers. The number of qubits, choice of 14 | variational ansatz, cost function, and optimization method are all to be 15 | developed by you in this function. 16 | 17 | Args: 18 | X_train (np.ndarray): An array of floats of size (250, 3) to be used as training data. 19 | Y_train (np.ndarray): An array of size (250,) which are the categorical labels 20 | associated to the training data. The categories are labeled by -1, 0, and 1. 21 | X_test (np.ndarray): An array of floats of (50, 3) to serve as testing data. 22 | 23 | Returns: 24 | str: The predicted categories of X_test, converted from a list of ints to a 25 | comma-separated string. 26 | """ 27 | 28 | # Use this array to make a prediction for the labels of the data in X_test 29 | predictions = [] 30 | 31 | # QHACK # 32 | 33 | # QHACK # 34 | 35 | return array_to_concatenated_string(predictions) 36 | 37 | 38 | def array_to_concatenated_string(array): 39 | """DO NOT MODIFY THIS FUNCTION. 40 | 41 | Turns an array of integers into a concatenated string of integers 42 | separated by commas. (Inverse of concatenated_string_to_array). 43 | """ 44 | return ",".join(str(x) for x in array) 45 | 46 | 47 | def concatenated_string_to_array(string): 48 | """DO NOT MODIFY THIS FUNCTION. 49 | 50 | Turns a concatenated string of integers separated by commas into 51 | an array of integers. (Inverse of array_to_concatenated_string). 52 | """ 53 | return np.array([int(x) for x in string.split(",")]) 54 | 55 | 56 | def parse_input(giant_string): 57 | """DO NOT MODIFY THIS FUNCTION. 58 | 59 | Parse the input data into 3 arrays: the training data, training labels, 60 | and testing data. 61 | 62 | Dimensions of the input data are: 63 | - X_train: (250, 3) 64 | - Y_train: (250,) 65 | - X_test: (50, 3) 66 | """ 67 | X_train_part, Y_train_part, X_test_part = giant_string.split("XXX") 68 | 69 | X_train_row_strings = X_train_part.split("S") 70 | X_train_rows = [[float(x) for x in row.split(",")] for row in X_train_row_strings] 71 | X_train = np.array(X_train_rows) 72 | 73 | Y_train = concatenated_string_to_array(Y_train_part) 74 | 75 | X_test_row_strings = X_test_part.split("S") 76 | X_test_rows = [[float(x) for x in row.split(",")] for row in X_test_row_strings] 77 | X_test = np.array(X_test_rows) 78 | 79 | return X_train, Y_train, X_test 80 | 81 | 82 | if __name__ == "__main__": 83 | # DO NOT MODIFY anything in this code block 84 | 85 | X_train, Y_train, X_test = parse_input(sys.stdin.read()) 86 | output_string = classify_data(X_train, Y_train, X_test) 87 | print(f"{output_string}") 88 | -------------------------------------------------------------------------------- /QML_Challenges/circuit_training_500_template/problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/circuit_training_500_template/problem.pdf -------------------------------------------------------------------------------- /QML_Challenges/images/clar_req.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/images/clar_req.PNG -------------------------------------------------------------------------------- /QML_Challenges/images/clarifications.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/images/clarifications.PNG -------------------------------------------------------------------------------- /QML_Challenges/images/clarifications_send_respond.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/images/clarifications_send_respond.PNG -------------------------------------------------------------------------------- /QML_Challenges/images/correct_submission.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/images/correct_submission.PNG -------------------------------------------------------------------------------- /QML_Challenges/images/full_clar_req.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/images/full_clar_req.PNG -------------------------------------------------------------------------------- /QML_Challenges/images/logo-white-background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/images/logo-white-background.png -------------------------------------------------------------------------------- /QML_Challenges/images/pending_submission.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/images/pending_submission.PNG -------------------------------------------------------------------------------- /QML_Challenges/images/points.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/images/points.PNG -------------------------------------------------------------------------------- /QML_Challenges/images/qhack-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/images/qhack-banner.png -------------------------------------------------------------------------------- /QML_Challenges/images/register.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/images/register.PNG -------------------------------------------------------------------------------- /QML_Challenges/images/submit.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/images/submit.PNG -------------------------------------------------------------------------------- /QML_Challenges/images/submit_dialog.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/images/submit_dialog.PNG -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_100_template/1.ans: -------------------------------------------------------------------------------- 1 | 0,0,0,0,-0.4553474723,0 2 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_100_template/1.in: -------------------------------------------------------------------------------- 1 | 1,0.5,-0.765S0.1,0,-0.654 2 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_100_template/2.ans: -------------------------------------------------------------------------------- 1 | 0.0299518791,-0.0393131888,0,-0.0340899969,0.1662797765,0 2 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_100_template/2.in: -------------------------------------------------------------------------------- 1 | 0.94,-0.2,6.03S-2.6,-0.058,1.2 2 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_100_template/problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/quantum_gradients_100_template/problem.pdf -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_100_template/quantum_gradients_100_template.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python3 2 | 3 | import sys 4 | import pennylane as qml 5 | from pennylane import numpy as np 6 | 7 | 8 | def parameter_shift(weights): 9 | """Compute the gradient of the variational circuit given by the 10 | ansatz function using the parameter-shift rule. 11 | 12 | Write your code below between the # QHACK # markers—create a device with 13 | the correct number of qubits, create a QNode that applies the above ansatz, 14 | and compute the gradient of the provided ansatz using the parameter-shift rule. 15 | 16 | Args: 17 | weights (array): An array of floating-point numbers with size (2, 3). 18 | 19 | Returns: 20 | array: The gradient of the variational circuit. The shape should match 21 | the input weights array. 22 | """ 23 | dev = qml.device("default.qubit", wires=3) 24 | 25 | @qml.qnode(dev) 26 | def circuit(weights): 27 | for i in range(len(weights)): 28 | qml.RX(weights[i, 0], wires=0) 29 | qml.RY(weights[i, 1], wires=1) 30 | qml.RZ(weights[i, 2], wires=2) 31 | 32 | qml.CNOT(wires=[0, 1]) 33 | qml.CNOT(wires=[1, 2]) 34 | qml.CNOT(wires=[2, 0]) 35 | 36 | return qml.expval(qml.PauliY(0) @ qml.PauliZ(2)) 37 | 38 | gradient = np.zeros_like(weights) 39 | 40 | # QHACK # 41 | # 42 | # QHACK # 43 | 44 | return gradient 45 | 46 | 47 | if __name__ == "__main__": 48 | # DO NOT MODIFY anything in this code block 49 | weights = sys.stdin.read() 50 | weights = np.array([row.split(",") for row in weights.split("S") if row], dtype=np.float64) 51 | 52 | gradient = np.round(parameter_shift(weights), 10) 53 | 54 | output_array = gradient.flatten() 55 | print(",".join([str(val) for val in output_array])) 56 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_200_template/1.ans: -------------------------------------------------------------------------------- 1 | 0.0012756024,-0.7668909241,-0.1890228368,-0.0374176229,-0.7914937431,0.012713476,0.0,0.012713476,0.0062927444,0.0015144486,0.0,-0.6210429671,0.0769457494,0.1248084389,-0.6036371367,0.012713476,0.0769457494,-0.6083294911,-0.6276219392,-0.0725364203,0.0062927444,0.1248084389,-0.6276219392,0.1375219149,-0.0444237671,0.0015144486,-0.6036371367,-0.0725364203,-0.0444237671,-0.6083294911,51 2 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_200_template/1.in: -------------------------------------------------------------------------------- 1 | 0.1,0.2,0.1,0.2,0.7 2 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_200_template/2.ans: -------------------------------------------------------------------------------- 1 | 0.0,-0.7867925232,-0.4765400998,0.3633757437,-0.9097065086,0.0,0.0,-0.3652848213,-0.0,0.0,0.0,0.1429477461,0.0,0.4779974229,0.3434255479,-0.3652848213,0.0,0.1429477461,-0.5657683412,-0.1852690548,-0.0,0.4779974229,-0.5657683412,0.4314148837,0.1412730651,0.0,0.3434255479,-0.1852690548,0.1412730651,0.1429477461,51 2 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_200_template/2.in: -------------------------------------------------------------------------------- 1 | -0.654,0.65,0,0.7,1.2 2 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_200_template/3.ans: -------------------------------------------------------------------------------- 1 | 0.0384107544,-0.8375311081,-0.0275046941,0.0652744473,-0.8542807037,0.0149333165,0.0,-0.0604075719,-0.3081748739,0.0484828678,0.0,0.0801904974,-0.5325524706,-0.0350182207,0.0863201335,-0.0604075719,-0.5325524706,0.0951238139,-0.2231035998,-0.5015738947,-0.3081748739,-0.0350182207,-0.2231035998,0.4524965169,0.08239079,0.0484828678,0.0863201335,-0.5015738947,0.08239079,0.0951238139,51 2 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_200_template/3.in: -------------------------------------------------------------------------------- 1 | 1.2,1.0,12,-0.124,0.67 2 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_200_template/problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/quantum_gradients_200_template/problem.pdf -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_200_template/quantum_gradients_200_template.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python3 2 | 3 | import sys 4 | import pennylane as qml 5 | import numpy as np 6 | 7 | 8 | def gradient_200(weights, dev): 9 | r"""This function must compute the gradient *and* the Hessian of the variational 10 | circuit using the parameter-shift rule, using exactly 51 device executions. 11 | The code you write for this challenge should be completely contained within 12 | this function between the # QHACK # comment markers. 13 | 14 | Args: 15 | weights (array): An array of floating-point numbers with size (5,). 16 | dev (Device): a PennyLane device for quantum circuit execution. 17 | 18 | Returns: 19 | tuple[array, array]: This function returns a tuple (gradient, hessian). 20 | 21 | * gradient is a real NumPy array of size (5,). 22 | 23 | * hessian is a real NumPy array of size (5, 5). 24 | """ 25 | 26 | @qml.qnode(dev, interface=None) 27 | def circuit(w): 28 | for i in range(3): 29 | qml.RX(w[i], wires=i) 30 | 31 | qml.CNOT(wires=[0, 1]) 32 | qml.CNOT(wires=[1, 2]) 33 | qml.CNOT(wires=[2, 0]) 34 | 35 | qml.RY(w[3], wires=1) 36 | 37 | qml.CNOT(wires=[0, 1]) 38 | qml.CNOT(wires=[1, 2]) 39 | qml.CNOT(wires=[2, 0]) 40 | 41 | qml.RX(w[4], wires=2) 42 | 43 | return qml.expval(qml.PauliZ(0) @ qml.PauliZ(2)) 44 | 45 | gradient = np.zeros([5], dtype=np.float64) 46 | hessian = np.zeros([5, 5], dtype=np.float64) 47 | 48 | # QHACK # 49 | 50 | # QHACK # 51 | 52 | return gradient, hessian, circuit.diff_options["method"] 53 | 54 | 55 | if __name__ == "__main__": 56 | # DO NOT MODIFY anything in this code block 57 | weights = sys.stdin.read() 58 | weights = weights.split(",") 59 | weights = np.array(weights, float) 60 | 61 | dev = qml.device("default.qubit", wires=3) 62 | gradient, hessian, diff_method = gradient_200(weights, dev) 63 | 64 | print( 65 | *np.round(gradient, 10), 66 | *np.round(hessian.flatten(), 10), 67 | dev.num_executions, 68 | diff_method, 69 | sep="," 70 | ) 71 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_500_template/1.ans: -------------------------------------------------------------------------------- 1 | 5.098012385138764,0.3672053121880165,-0.5560134995039925,0.6762305142883951,0.0394466954830584,0.0072009476963740965 -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_500_template/1.in: -------------------------------------------------------------------------------- 1 | 1,1,1,2,2,2 2 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_500_template/2.ans: -------------------------------------------------------------------------------- 1 | -1.5381661785755925,-0.24111785221606102,2.9299917429057065,-0.1390801472935338,-0.5109644640437793,-0.10416551780461344 -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_500_template/2.in: -------------------------------------------------------------------------------- 1 | 0.81025621,0.5900447,0.52045692,0.70485107,0.34666493,0.4154791 2 | -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_500_template/problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/quantum_gradients_500_template/problem.pdf -------------------------------------------------------------------------------- /QML_Challenges/quantum_gradients_500_template/quantum_gradients_500_template.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python3 2 | import sys 3 | import pennylane as qml 4 | from pennylane import numpy as np 5 | 6 | # DO NOT MODIFY any of these parameters 7 | a = 0.7 8 | b = -0.3 9 | dev = qml.device("default.qubit", wires=3) 10 | 11 | 12 | def natural_gradient(params): 13 | """Calculate the natural gradient of the qnode() cost function. 14 | 15 | The code you write for this challenge should be completely contained within this function 16 | between the # QHACK # comment markers. 17 | 18 | You should evaluate the metric tensor and the gradient of the QNode, and then combine these 19 | together using the natural gradient definition. The natural gradient should be returned as a 20 | NumPy array. 21 | 22 | The metric tensor should be evaluated using the equation provided in the problem text. Hint: 23 | you will need to define a new QNode that returns the quantum state before measurement. 24 | 25 | Args: 26 | params (np.ndarray): Input parameters, of dimension 6 27 | 28 | Returns: 29 | np.ndarray: The natural gradient evaluated at the input parameters, of dimension 6 30 | """ 31 | 32 | natural_grad = np.zeros(6) 33 | 34 | # QHACK # 35 | 36 | # QHACK # 37 | 38 | return natural_grad 39 | 40 | 41 | def non_parametrized_layer(): 42 | """A layer of fixed quantum gates. 43 | 44 | # DO NOT MODIFY anything in this function! It is used to judge your solution. 45 | """ 46 | qml.RX(a, wires=0) 47 | qml.RX(b, wires=1) 48 | qml.RX(a, wires=1) 49 | qml.CNOT(wires=[0, 1]) 50 | qml.CNOT(wires=[1, 2]) 51 | qml.RZ(a, wires=0) 52 | qml.Hadamard(wires=1) 53 | qml.CNOT(wires=[0, 1]) 54 | qml.RZ(b, wires=1) 55 | qml.Hadamard(wires=0) 56 | 57 | 58 | def variational_circuit(params): 59 | """A layered variational circuit composed of two parametrized layers of single qubit rotations 60 | interleaved with non-parameterized layers of fixed quantum gates specified by 61 | ``non_parametrized_layer``. 62 | 63 | The first parametrized layer uses the first three parameters of ``params``, while the second 64 | layer uses the final three parameters. 65 | 66 | # DO NOT MODIFY anything in this function! It is used to judge your solution. 67 | """ 68 | non_parametrized_layer() 69 | qml.RX(params[0], wires=0) 70 | qml.RY(params[1], wires=1) 71 | qml.RZ(params[2], wires=2) 72 | non_parametrized_layer() 73 | qml.RX(params[3], wires=0) 74 | qml.RY(params[4], wires=1) 75 | qml.RZ(params[5], wires=2) 76 | 77 | 78 | @qml.qnode(dev) 79 | def qnode(params): 80 | """A PennyLane QNode that pairs the variational_circuit with an expectation value 81 | measurement. 82 | 83 | # DO NOT MODIFY anything in this function! It is used to judge your solution. 84 | """ 85 | variational_circuit(params) 86 | return qml.expval(qml.PauliX(1)) 87 | 88 | 89 | if __name__ == "__main__": 90 | # DO NOT MODIFY anything in this code block 91 | 92 | # Load and process inputs 93 | params = sys.stdin.read() 94 | params = params.split(",") 95 | params = np.array(params, float) 96 | 97 | updated_params = natural_gradient(params) 98 | 99 | print(*updated_params, sep=",") 100 | -------------------------------------------------------------------------------- /QML_Challenges/requirements.txt: -------------------------------------------------------------------------------- 1 | pennylane==0.14.1 2 | networkx==2.4 3 | numpy==1.19.5 4 | -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_20_template/1.ans: -------------------------------------------------------------------------------- 1 | 0.5563631060725739 -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_20_template/1.in: -------------------------------------------------------------------------------- 1 | 1.45783 -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_20_template/2.ans: -------------------------------------------------------------------------------- 1 | 0.7879057356348377 -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_20_template/2.in: -------------------------------------------------------------------------------- 1 | 0.9572 -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_20_template/problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/simple_circuits_20_template/problem.pdf -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_20_template/simple_circuits_20_template.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python3 2 | import pennylane as qml 3 | from pennylane import numpy as np 4 | import sys 5 | 6 | 7 | def simple_circuits_20(angle): 8 | """The code you write for this challenge should be completely contained within this function 9 | between the # QHACK # comment markers. 10 | 11 | In this function: 12 | * Rotate the qubit around the x-axis by angle 13 | * Measure the probability the qubit is in the zero state 14 | 15 | Args: 16 | angle (float): how much to rotate a state around the x-axis 17 | 18 | Returns: 19 | float: the probability of of the state being in the 0 ground state 20 | """ 21 | prob = 0.0 22 | # QHACK # 23 | 24 | # Step 1 : initalize a device 25 | 26 | # Step 2 : Create a quantum circuit and qnode 27 | 28 | # Step 3 : Run the qnode 29 | # prob = ? 30 | 31 | # QHACK # 32 | return prob 33 | 34 | 35 | if __name__ == "__main__": 36 | # DO NOT MODIFY anything in this code block 37 | 38 | # Load and process input 39 | angle_str = sys.stdin.read() 40 | angle = float(angle_str) 41 | 42 | ans = simple_circuits_20(angle) 43 | 44 | if isinstance(ans, np.tensor): 45 | ans = ans.item() 46 | 47 | if not isinstance(ans, float): 48 | raise TypeError("the simple_circuits_20 function needs to return a float") 49 | 50 | print(ans) 51 | -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_30_template/1.ans: -------------------------------------------------------------------------------- 1 | 0.9440031218347901 2 | -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_30_template/1.in: -------------------------------------------------------------------------------- 1 | 1.23456 -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_30_template/2.ans: -------------------------------------------------------------------------------- 1 | 0.1835461227247332 -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_30_template/2.in: -------------------------------------------------------------------------------- 1 | 2.957 -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_30_template/problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/simple_circuits_30_template/problem.pdf -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_30_template/simple_circuits_30_template.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python3 2 | import pennylane as qml 3 | from pennylane import numpy as np 4 | import sys 5 | 6 | 7 | def simple_circuits_30(angle): 8 | """The code you write for this challenge should be completely contained within this function 9 | between the # QHACK # comment markers. 10 | 11 | In this function: 12 | * Rotate a qubit around the y-axis by angle 13 | * Measure the expectation value of `PauliX` 14 | 15 | Args: 16 | angle (float): how much to rotate a state around the y-axis 17 | 18 | Returns: 19 | float: the expectation value of a PauliX measurement 20 | """ 21 | x_expectation = 0.0 22 | 23 | # QHACK # 24 | 25 | # Step 1 : initialize a device 26 | 27 | # Step 2 : Create a quantum circuit and qnode 28 | 29 | # Step 3 : Run the qnode 30 | # x_expectation = ? 31 | 32 | # QHACK # 33 | return x_expectation 34 | 35 | 36 | if __name__ == "__main__": 37 | # DO NOT MODIFY anything in this code block 38 | 39 | # Load and process input 40 | angle_str = sys.stdin.read() 41 | angle = float(angle_str) 42 | 43 | ans = simple_circuits_30(angle) 44 | 45 | if isinstance(ans, np.tensor): 46 | ans = ans.item() 47 | 48 | if not isinstance(ans, float): 49 | raise TypeError("the simple_circuits_30 function needs to return a float") 50 | 51 | print(ans) 52 | -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_50_template/1.ans: -------------------------------------------------------------------------------- 1 | 0.3299365180851774 -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_50_template/1.in: -------------------------------------------------------------------------------- 1 | 1.23456 -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_50_template/2.ans: -------------------------------------------------------------------------------- 1 | -0.2940234756205866 -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_50_template/2.in: -------------------------------------------------------------------------------- 1 | 1.86923 -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_50_template/problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/simple_circuits_50_template/problem.pdf -------------------------------------------------------------------------------- /QML_Challenges/simple_circuits_50_template/simple_circuits_50_template.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python3 2 | import pennylane as qml 3 | from pennylane import numpy as np 4 | import sys 5 | 6 | 7 | def simple_circuits_50(angle): 8 | """The code you write for this challenge should be completely contained within this function 9 | between the # QHACK # comment markers. 10 | 11 | In this function: 12 | * Create the standard Bell State 13 | * Rotate the first qubit around the y-axis by angle 14 | * Measure the expectation value of the tensor observable `qml.PauliZ(0) @ qml.PauliZ(1)` 15 | 16 | Args: 17 | angle (float): how much to rotate a state around the y-axis 18 | 19 | Returns: 20 | float: the expectation value of the tensor observable 21 | """ 22 | 23 | expectation_value = 0.0 24 | 25 | # QHACK # 26 | 27 | # Step 1 : initialize a device 28 | 29 | # Step 2 : Create a quantum circuit and qnode 30 | 31 | # Step 3 : Run the qnode 32 | # expectation_value = ? 33 | 34 | # QHACK # 35 | return expectation_value 36 | 37 | 38 | if __name__ == "__main__": 39 | # DO NOT MODIFY anything in this code block 40 | 41 | # Load and process input 42 | angle_str = sys.stdin.read() 43 | angle = float(angle_str) 44 | 45 | ans = simple_circuits_50(angle) 46 | 47 | if isinstance(ans, np.tensor): 48 | ans = ans.item() 49 | 50 | if not isinstance(ans, float): 51 | raise TypeError( 52 | "the simple_circuits_50 function needs to return either a float or PennyLane tensor." 53 | ) 54 | 55 | print(ans) 56 | -------------------------------------------------------------------------------- /QML_Challenges/vqe_100_template/1.ans: -------------------------------------------------------------------------------- 1 | -1.749160 2 | -------------------------------------------------------------------------------- /QML_Challenges/vqe_100_template/1.in: -------------------------------------------------------------------------------- 1 | + 5.906709445000001 I S - 4.286607049870561 X0 S - 6.343290554999999 Z0 -------------------------------------------------------------------------------- /QML_Challenges/vqe_100_template/2.ans: -------------------------------------------------------------------------------- 1 | -2.045671 -------------------------------------------------------------------------------- /QML_Challenges/vqe_100_template/2.in: -------------------------------------------------------------------------------- 1 | + 32.7658547225 I S - 2.1433035249352805 X1 S - 2.1433035249352805 Z0 X1 S + 17.015854722500002 Z1 S + 3.913118960624632 X0 Z1 S - 23.359145277499998 Z0 Z1 S - 3.913118960624632 X0 S - 26.859145277499998 Z0 -------------------------------------------------------------------------------- /QML_Challenges/vqe_100_template/problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/vqe_100_template/problem.pdf -------------------------------------------------------------------------------- /QML_Challenges/vqe_100_template/vqe_100_template.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python3 2 | 3 | import sys 4 | import pennylane as qml 5 | import numpy as np 6 | 7 | 8 | def variational_ansatz(params, wires): 9 | """ 10 | DO NOT MODIFY anything in this function! It is used to judge your solution. 11 | 12 | This is ansatz is used to help with the problem structure. It applies 13 | alternating layers of rotations and CNOTs. 14 | 15 | Don't worry about the contents of this function for now—you'll be designing 16 | your own ansatze in a later problem. 17 | 18 | Args: 19 | params (np.ndarray): An array of floating-point numbers with size (n, 3), 20 | where n is the number of parameter sets required (this is determined by 21 | the problem Hamiltonian). 22 | wires (qml.Wires): The device wires this circuit will run on. 23 | """ 24 | n_qubits = len(wires) 25 | n_rotations = len(params) 26 | 27 | if n_rotations > 1: 28 | n_layers = n_rotations // n_qubits 29 | n_extra_rots = n_rotations - n_layers * n_qubits 30 | 31 | # Alternating layers of unitary rotations on every qubit followed by a 32 | # ring cascade of CNOTs. 33 | for layer_idx in range(n_layers): 34 | layer_params = params[layer_idx * n_qubits : layer_idx * n_qubits + n_qubits, :] 35 | qml.broadcast(qml.Rot, wires, pattern="single", parameters=layer_params) 36 | qml.broadcast(qml.CNOT, wires, pattern="ring") 37 | 38 | # There may be "extra" parameter sets required for which it's not necessarily 39 | # to perform another full alternating cycle. Apply these to the qubits as needed. 40 | extra_params = params[-n_extra_rots:, :] 41 | extra_wires = wires[: n_qubits - 1 - n_extra_rots : -1] 42 | qml.broadcast(qml.Rot, extra_wires, pattern="single", parameters=extra_params) 43 | else: 44 | # For 1-qubit case, just a single rotation to the qubit 45 | qml.Rot(*params[0], wires=wires[0]) 46 | 47 | 48 | def run_vqe(H): 49 | """Runs the variational quantum eigensolver on the problem Hamiltonian using the 50 | variational ansatz specified above. 51 | 52 | Fill in the missing parts between the # QHACK # markers below to run the VQE. 53 | 54 | Args: 55 | H (qml.Hamiltonian): The input Hamiltonian 56 | 57 | Returns: 58 | The ground state energy of the Hamiltonian. 59 | """ 60 | # Initialize parameters 61 | num_qubits = len(H.wires) 62 | num_param_sets = (2 ** num_qubits) - 1 63 | params = np.random.uniform(low=-np.pi / 2, high=np.pi / 2, size=(num_param_sets, 3)) 64 | 65 | energy = 0 66 | 67 | # QHACK # 68 | 69 | # Create a quantum device, set up a cost funtion and optimizer, and run the VQE. 70 | # (We recommend ~500 iterations to ensure convergence for this problem, 71 | # or you can design your own convergence criteria) 72 | 73 | # QHACK # 74 | 75 | # Return the ground state energy 76 | return energy 77 | 78 | 79 | def pauli_token_to_operator(token): 80 | """ 81 | DO NOT MODIFY anything in this function! It is used to judge your solution. 82 | 83 | Helper function to turn strings into qml operators. 84 | 85 | Args: 86 | token (str): A Pauli operator input in string form. 87 | 88 | Returns: 89 | A qml.Operator instance of the Pauli. 90 | """ 91 | qubit_terms = [] 92 | 93 | for term in token: 94 | # Special case of identity 95 | if term == "I": 96 | qubit_terms.append(qml.Identity(0)) 97 | else: 98 | pauli, qubit_idx = term[0], term[1:] 99 | if pauli == "X": 100 | qubit_terms.append(qml.PauliX(int(qubit_idx))) 101 | elif pauli == "Y": 102 | qubit_terms.append(qml.PauliY(int(qubit_idx))) 103 | elif pauli == "Z": 104 | qubit_terms.append(qml.PauliZ(int(qubit_idx))) 105 | else: 106 | print("Invalid input.") 107 | 108 | full_term = qubit_terms[0] 109 | for term in qubit_terms[1:]: 110 | full_term = full_term @ term 111 | 112 | return full_term 113 | 114 | 115 | def parse_hamiltonian_input(input_data): 116 | """ 117 | DO NOT MODIFY anything in this function! It is used to judge your solution. 118 | 119 | Turns the contents of the input file into a Hamiltonian. 120 | 121 | Args: 122 | filename(str): Name of the input file that contains the Hamiltonian. 123 | 124 | Returns: 125 | qml.Hamiltonian object of the Hamiltonian specified in the file. 126 | """ 127 | # Get the input 128 | coeffs = [] 129 | pauli_terms = [] 130 | 131 | # Go through line by line and build up the Hamiltonian 132 | for line in input_data.split("S"): 133 | line = line.strip() 134 | tokens = line.split(" ") 135 | 136 | # Parse coefficients 137 | sign, value = tokens[0], tokens[1] 138 | 139 | coeff = float(value) 140 | if sign == "-": 141 | coeff *= -1 142 | coeffs.append(coeff) 143 | 144 | # Parse Pauli component 145 | pauli = tokens[2:] 146 | pauli_terms.append(pauli_token_to_operator(pauli)) 147 | 148 | return qml.Hamiltonian(coeffs, pauli_terms) 149 | 150 | 151 | if __name__ == "__main__": 152 | # DO NOT MODIFY anything in this code block 153 | 154 | # Turn input to Hamiltonian 155 | H = parse_hamiltonian_input(sys.stdin.read()) 156 | 157 | # Send Hamiltonian through VQE routine and output the solution 158 | ground_state_energy = run_vqe(H) 159 | print(f"{ground_state_energy:.6f}") 160 | -------------------------------------------------------------------------------- /QML_Challenges/vqe_200_template/1.ans: -------------------------------------------------------------------------------- 1 | -1.749160 2 | -------------------------------------------------------------------------------- /QML_Challenges/vqe_200_template/1.in: -------------------------------------------------------------------------------- 1 | + 5.906709 I S + 0.218291 Z0 S - 6.125 Z1 S - 2.143304 X0 X1 S - 2.143304 Y0 Y1 -------------------------------------------------------------------------------- /QML_Challenges/vqe_200_template/2.ans: -------------------------------------------------------------------------------- 1 | -2.045671 -------------------------------------------------------------------------------- /QML_Challenges/vqe_200_template/2.in: -------------------------------------------------------------------------------- 1 | + 15.531709 I S + 0.218291 Z0 S - 6.125 Z1 S - 2.143304 X0 X1 S - 2.143304 Y0 Y1 S - 9.625 Z2 S - 3.913119 X1 X2 S - 3.913119 Y1 Y2 -------------------------------------------------------------------------------- /QML_Challenges/vqe_200_template/problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/vqe_200_template/problem.pdf -------------------------------------------------------------------------------- /QML_Challenges/vqe_200_template/vqe_200_template.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python3 2 | 3 | import sys 4 | import pennylane as qml 5 | import numpy as np 6 | 7 | 8 | def variational_ansatz(params, wires): 9 | """The variational ansatz circuit. 10 | 11 | Fill in the details of your ansatz between the # QHACK # comment markers. Your 12 | ansatz should produce an n-qubit state of the form 13 | 14 | a_0 |10...0> + a_1 |01..0> + ... + a_{n-2} |00...10> + a_{n-1} |00...01> 15 | 16 | where {a_i} are real-valued coefficients. 17 | 18 | Args: 19 | params (np.array): The variational parameters. 20 | wires (qml.Wires): The device wires that this circuit will run on. 21 | """ 22 | 23 | # QHACK # 24 | 25 | # QHACK # 26 | 27 | 28 | def run_vqe(H): 29 | """Runs the variational quantum eigensolver on the problem Hamiltonian using the 30 | variational ansatz specified above. 31 | 32 | Fill in the missing parts between the # QHACK # markers below to run the VQE. 33 | 34 | Args: 35 | H (qml.Hamiltonian): The input Hamiltonian 36 | 37 | Returns: 38 | The ground state energy of the Hamiltonian. 39 | """ 40 | energy = 0 41 | 42 | # QHACK # 43 | 44 | # Initialize the quantum device 45 | 46 | # Randomly choose initial parameters (how many do you need?) 47 | 48 | # Set up a cost function 49 | 50 | # Set up an optimizer 51 | 52 | # Run the VQE by iterating over many steps of the optimizer 53 | 54 | # QHACK # 55 | 56 | # Return the ground state energy 57 | return energy 58 | 59 | 60 | def pauli_token_to_operator(token): 61 | """ 62 | DO NOT MODIFY anything in this function! It is used to judge your solution. 63 | 64 | Helper function to turn strings into qml operators. 65 | 66 | Args: 67 | token (str): A Pauli operator input in string form. 68 | 69 | Returns: 70 | A qml.Operator instance of the Pauli. 71 | """ 72 | qubit_terms = [] 73 | 74 | for term in token: 75 | # Special case of identity 76 | if term == "I": 77 | qubit_terms.append(qml.Identity(0)) 78 | else: 79 | pauli, qubit_idx = term[0], term[1:] 80 | if pauli == "X": 81 | qubit_terms.append(qml.PauliX(int(qubit_idx))) 82 | elif pauli == "Y": 83 | qubit_terms.append(qml.PauliY(int(qubit_idx))) 84 | elif pauli == "Z": 85 | qubit_terms.append(qml.PauliZ(int(qubit_idx))) 86 | else: 87 | print("Invalid input.") 88 | 89 | full_term = qubit_terms[0] 90 | for term in qubit_terms[1:]: 91 | full_term = full_term @ term 92 | 93 | return full_term 94 | 95 | 96 | def parse_hamiltonian_input(input_data): 97 | """ 98 | DO NOT MODIFY anything in this function! It is used to judge your solution. 99 | 100 | Turns the contents of the input file into a Hamiltonian. 101 | 102 | Args: 103 | filename(str): Name of the input file that contains the Hamiltonian. 104 | 105 | Returns: 106 | qml.Hamiltonian object of the Hamiltonian specified in the file. 107 | """ 108 | # Get the input 109 | coeffs = [] 110 | pauli_terms = [] 111 | 112 | # Go through line by line and build up the Hamiltonian 113 | for line in input_data.split("S"): 114 | line = line.strip() 115 | tokens = line.split(" ") 116 | 117 | # Parse coefficients 118 | sign, value = tokens[0], tokens[1] 119 | 120 | coeff = float(value) 121 | if sign == "-": 122 | coeff *= -1 123 | coeffs.append(coeff) 124 | 125 | # Parse Pauli component 126 | pauli = tokens[2:] 127 | pauli_terms.append(pauli_token_to_operator(pauli)) 128 | 129 | return qml.Hamiltonian(coeffs, pauli_terms) 130 | 131 | 132 | if __name__ == "__main__": 133 | # DO NOT MODIFY anything in this code block 134 | 135 | # Turn input to Hamiltonian 136 | H = parse_hamiltonian_input(sys.stdin.read()) 137 | 138 | # Send Hamiltonian through VQE routine and output the solution 139 | ground_state_energy = run_vqe(H) 140 | print(f"{ground_state_energy:.6f}") 141 | -------------------------------------------------------------------------------- /QML_Challenges/vqe_500_template/1.ans: -------------------------------------------------------------------------------- 1 | -1.1658819,-1.0698449,-0.44972335 2 | -------------------------------------------------------------------------------- /QML_Challenges/vqe_500_template/1.in: -------------------------------------------------------------------------------- 1 | + 0.35807927646889326 X0 S + 0.7556205249987815 X1 S + 0.04828309125493235 X2 S + 0.07927207111541623 Z1 Z2 2 | -------------------------------------------------------------------------------- /QML_Challenges/vqe_500_template/2.ans: -------------------------------------------------------------------------------- 1 | -1.31795925,-0.99412998,-0.32243601 -------------------------------------------------------------------------------- /QML_Challenges/vqe_500_template/2.in: -------------------------------------------------------------------------------- 1 | + 0.4977616234240615 X0 S + 0.5635396435844906 X1 S + 0.32588875859719557 Z1 Z2 S + 0.18913602999217294 X2 -------------------------------------------------------------------------------- /QML_Challenges/vqe_500_template/problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/QML_Challenges/vqe_500_template/problem.pdf -------------------------------------------------------------------------------- /QML_Challenges/vqe_500_template/vqe_500_template.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python3 2 | 3 | import sys 4 | import pennylane as qml 5 | import numpy as np 6 | 7 | 8 | def find_excited_states(H): 9 | """ 10 | Fill in the missing parts between the # QHACK # markers below. Implement 11 | a variational method that can find the three lowest energies of the provided 12 | Hamiltonian. 13 | 14 | Args: 15 | H (qml.Hamiltonian): The input Hamiltonian 16 | 17 | Returns: 18 | The lowest three eigenenergies of the Hamiltonian as a comma-separated string, 19 | sorted from smallest to largest. 20 | """ 21 | 22 | energies = np.zeros(3) 23 | 24 | # QHACK # 25 | 26 | # QHACK # 27 | 28 | return ",".join([str(E) for E in energies]) 29 | 30 | 31 | def pauli_token_to_operator(token): 32 | """ 33 | DO NOT MODIFY anything in this function! It is used to judge your solution. 34 | 35 | Helper function to turn strings into qml operators. 36 | 37 | Args: 38 | token (str): A Pauli operator input in string form. 39 | 40 | Returns: 41 | A qml.Operator instance of the Pauli. 42 | """ 43 | qubit_terms = [] 44 | 45 | for term in token: 46 | # Special case of identity 47 | if term == "I": 48 | qubit_terms.append(qml.Identity(0)) 49 | else: 50 | pauli, qubit_idx = term[0], term[1:] 51 | if pauli == "X": 52 | qubit_terms.append(qml.PauliX(int(qubit_idx))) 53 | elif pauli == "Y": 54 | qubit_terms.append(qml.PauliY(int(qubit_idx))) 55 | elif pauli == "Z": 56 | qubit_terms.append(qml.PauliZ(int(qubit_idx))) 57 | else: 58 | print("Invalid input.") 59 | 60 | full_term = qubit_terms[0] 61 | for term in qubit_terms[1:]: 62 | full_term = full_term @ term 63 | 64 | return full_term 65 | 66 | 67 | def parse_hamiltonian_input(input_data): 68 | """ 69 | DO NOT MODIFY anything in this function! It is used to judge your solution. 70 | 71 | Turns the contents of the input file into a Hamiltonian. 72 | 73 | Args: 74 | filename(str): Name of the input file that contains the Hamiltonian. 75 | 76 | Returns: 77 | qml.Hamiltonian object of the Hamiltonian specified in the file. 78 | """ 79 | # Get the input 80 | coeffs = [] 81 | pauli_terms = [] 82 | 83 | # Go through line by line and build up the Hamiltonian 84 | for line in input_data.split("S"): 85 | line = line.strip() 86 | tokens = line.split(" ") 87 | 88 | # Parse coefficients 89 | sign, value = tokens[0], tokens[1] 90 | 91 | coeff = float(value) 92 | if sign == "-": 93 | coeff *= -1 94 | coeffs.append(coeff) 95 | 96 | # Parse Pauli component 97 | pauli = tokens[2:] 98 | pauli_terms.append(pauli_token_to_operator(pauli)) 99 | 100 | return qml.Hamiltonian(coeffs, pauli_terms) 101 | 102 | 103 | if __name__ == "__main__": 104 | # DO NOT MODIFY anything in this code block 105 | 106 | # Turn input to Hamiltonian 107 | H = parse_hamiltonian_input(sys.stdin.read()) 108 | 109 | # Send Hamiltonian through VQE routine and output the solution 110 | lowest_three_energies = find_excited_states(H) 111 | print(lowest_three_energies) 112 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Note**: This repository has been frozen while we consider the submissions for the QHack Open Hackathon. We hope you enjoyed the event! 2 | 3 | ![image](img/qhack-banner.png) 4 | 5 | Welcome to [QHack](https://qhack.ai), the quantum machine learning hackathon! We're thrilled to have the opportunity to meet and work with such a large and diverse group of participants, and we look forward to interacting with you all during the event. 6 | 7 | This year's event consists of three main components: 8 | 9 | - **[QHack Live Stream](https://twitch.tv/qhack)**: We will be streaming at [twitch.tv/qhack](https://twitch.tv/qhack). Join us for three days of talks from an amazing set of guest speakers. 10 | 11 | - **[QHack QML Challenges](QML_Challenges.md)**: Build your skills by tackling a series of QML challenge questions for all skill levels. 12 | 13 | - **[QHack Open Hackathon](Open_Hackathon.md)**: Show the world what you can do with [PennyLane](https://pennylane.ai) and [Amazon Braket](https://aws.amazon.com/braket/)! Dream up your own hackathon project, or start from one of our seed ideas. 14 | 15 | The up-to-date event schedule can be found [here](https://qhack.ai/schedule.html). 16 | 17 | ## Power Ups and Prizes 18 | 19 | QHack has some amazing goodies and prizes available to be won, courtesy of our sponsors. 20 | 21 | ### Credits for AWS 22 | 23 | - **Earn $250 in AWS credits**: At the conclusion of our Feb 19 live stream, the top 80 teams on the scoreboard will receive $250 credits to help them build their Open Hackathon solutions on AWS. Teams can apply credits to any AWS service, including Amazon Braket where they can showcase their ideas on Rigetti, IonQ, and D-Wave hardware or with high-performance simulators in the cloud. 24 | 25 | - **Earn $4000 in AWS credits**: Teams who open an issue by Feb 24 on [this GitHub repository](https://github.com/XanaduAI/QHack/issues) with a description of their (in progress) Open Hackathon project are eligible for *$4000 in additional AWS credits* to use towards their hackathon project. 26 | 27 | ### Access Sandbox's Floq Simulator 28 | 29 | - **Alpha access to TPU-based quantum simulators**: The top 50 teams in the challenge will each receive an API key for the alpha of Sandbox@Alphabet's Floq API. Discover more details about Floq@QHack [here](Floq_challenge.md). 30 | 31 | - **Floq Cash Prize**: The team with the best usage of Floq by the end of the Open Hackathon will be eligible to receive a $2500 cash prize. See [here](https://github.com/XanaduAI/QHack/blob/main/Floq_challenge.md) for more details. 32 | 33 | ### Grand Prize 34 | 35 | - **Win a summer internship at CERN**: The top overall team (judged by QML Challenge scoreboard ranking and Open Hackathon project) will receive up to 3 summer internship positions at CERN. 36 | 37 | Please read our [terms and conditions](https://qhack.ai/terms_and_conditions_2021.html) for official eligibility and evaluation criteria. Entry void in Quebec. 38 | 39 | Participants in the event agree to abide by the [QHack Code of Conduct](Code_of_Conduct.md). 40 | -------------------------------------------------------------------------------- /img/clar_req.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/img/clar_req.png -------------------------------------------------------------------------------- /img/clarifications.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/img/clarifications.png -------------------------------------------------------------------------------- /img/clarifications_send_respond.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/img/clarifications_send_respond.png -------------------------------------------------------------------------------- /img/correct_submission.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/img/correct_submission.png -------------------------------------------------------------------------------- /img/full_clar_req.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/img/full_clar_req.png -------------------------------------------------------------------------------- /img/pending_submission.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/img/pending_submission.png -------------------------------------------------------------------------------- /img/points.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/img/points.png -------------------------------------------------------------------------------- /img/problem_description_domjudge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/img/problem_description_domjudge.png -------------------------------------------------------------------------------- /img/qhack-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/img/qhack-banner.png -------------------------------------------------------------------------------- /img/register.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/img/register.png -------------------------------------------------------------------------------- /img/submit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/img/submit.png -------------------------------------------------------------------------------- /img/submit_dialog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/img/submit_dialog.png -------------------------------------------------------------------------------- /img/submit_window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/QHack2021/df18bf7159fe2806c12cde437e3a1f92fec17f04/img/submit_window.png --------------------------------------------------------------------------------