Interpretation of the questions of the 6th 2024 MindSpore Quantum Computing Hackathon Warm-up Competition

第六届·2024 MindSpore量子计算黑客松火热进行中。本次大赛由量子信息网络产业联盟主办,昇思MindSpore Quantum社区承办,多所高校和单位联合举办。开发者将全面体验全新一代通用量子计算框架MindSpore Quantum。

The warm-up game is for basic learning and programming exercises of quantum computing. The first 100 players who complete the warm-up competition will have the opportunity to receive a customized cultural shirt. The quantity is limited, so don’t miss it.

Step 1: Pay attention to the MindQuantum code repository and see the Quantum Software Programming Guide

Step 2: Register and complete the real-name authentication of your Huawei Cloud account .

Step 3: Log in to the HiQ quantum computing cloud platform to answer questions online.

Warm-up competition reference document: https://competition.huaweicloud.com/information/1000042022/noise

There are two links above each question: MindQuantum Tutorial and MindQuantum API Reference . The answers to the questions can be found at both links. Tip: Search for the keywords in the question in the MindQuantum API reference to quickly find the corresponding content.

Warm-up match replay via strategy video: https://www.koushare.com/live/details/33684

first question

This question is about how to add quantum gates in the circuit using the on method. In MindQuantum, each quantum gate has an on method. For example, X.on(0, 1) means that the X gate is applied to the 0th bits and controlled by the 1st bit. This question requires the X gate to act on the 2nd bit and be controlled by the 0th and 1st bits. Therefore it can be represented by X.on(2, [0, 1]) . As you can see, the second parameter of the on method can accept a list containing multiple control bits, so multiple control gates can be easily added. For detailed usage, please refer to the API documentation of the on method . 

Question 2

This question tests how to compress quantum circuits. In MindSpore Quantum, the Circuit class is a quantum circuit module, which implements many methods for operating quantum circuits. There is a method that can compress lines, and the interface name is compress() . Therefore, this question can be passed successfully by calling the compress() method.

Question 3

This question tests line flipping, that is, we need to reverse the bit order of the line upside down. A very long line is given in the question, but we do not need to care about the specific content of the line, because there is a method in the Circuit class that can directly realize the function of line flipping - reverse_qubits() , we call this method directly in the code It will pass successfully.

Question 4

This question tests how to add suffixes to variable names in parameterized quantum circuits. Once you master this technique, you can easily build variational quantum circuits. In the mindquantum.core.circuit module, the add_suffix() function can implement the function of adding suffixes. Specifically, it needs to accept a quantum circuit and a suffix string as input parameters, and then return a new quantum circuit with the suffix added. Players only need to add this new quantum circuit to the back of the newly constructed circuit through += to construct a multi-layer variational circuit. The code in the question is as follows:

First we need to import the add_suffix() function. The question needs to build 3 layers of lines, so it can be implemented with a loop. In each loop, use += to add the new line returned by the add_suffix() function to new_circ. The suffix string is set to the value p of the loop counter, so You can successfully pass the question.

Question 5

All the links to the modules that need to be used are given in the question. Click to view the usage. Among them, the third gate, the RY controlled gate, can be simply built using the RY gate: circ += RY(0.1).on(1, 0). QubitOperator can construct Pauli operators, and Hamiltonian is a class that constructs Hamiltonian. Therefore, the Hamiltonian in the question can be constructed like this: ham = Hamiltonian(QubitOperator("X0 Y1")). Finally, run sim.get_expectation(ham, circ) to get the expectation value of the Hamiltonian.

Question 6

 You can see various implemented Ansatz lines in mindquantum.algorithm.nisq . You only need to pass in the number of bits and layers to construct (ansatz in the question is RYCascade). After the construction is completed, circ = RYCascade(n_qubits, depth). circuit will get the ansatz line.

Question 7

This question examines the structure of the Rn gate and how to find the expectation value and gradient of the variational line parameters with respect to the Hamiltonian. The Rn gate has 3 parameters, so the parameter-containing circuit can be constructed like this: circ += Rn('a','b','c').on(0). The construction method of the Hamiltonian is similar to the fifth question. : ham = Hamiltonian(QubitOperator("Z0")), the gradient operator needs to call the simulator's class method to get: grad_ops = sim.get_expectation_with_grad(ham, circ), the obtained gradient operator can pass in the specific values ​​of the line parameters , and return the corresponding expected value and gradient: f, g = grad_ops(np.array([alpha, beta, gamma])). Since the question requires the derivative value of α, the first parameter of the gradient value will finally be obtained. Just return the real part: return np.real(g[0,0,0]).

Question 8

This question involves many mathematical concepts, but in general it tests the use of the TimeEvolution module. Let’s analyze it in detail below.

The TimeEvolution class belongs to the mindquantum.core.operator module, and its main function is to generate the quantum circuit corresponding to the formula based on the Hamiltonian. It accepts two input parameters: the first is the Hamiltonian H, and the second is the evolution time t. Calling the TimeEvolution().circuit method will return a quantum circuit, corresponding to the operator. In some cases, the generated line is only an approximation of the theoretical value, so there will be accuracy problems, and the accuracy of this approximation can be improved by increasing the approximation order n (the specific approximation formula is as mentioned in the question). In this question, we need to use TimeEvolution to generate an n-order approximate line and compare it with the exact value obtained by theoretical calculation.

It can be seen that the Hamiltonian H (line 7) and the exact value m1 (line 8) have been given in the question code, and the matrix m2 corresponding to the line is given in the loop (line 14), and Code for comparing m1 with m2 (line 15). We only need to add line 12, that is: use TimeEvolution to generate an approximate line of order n.

It can be found in the approximation formula that the so-called n-order approximation is to divide the evolution time t by n to become, and then apply this formula n times, that is. This formula can be constructed as follows: The formula in brackets can be used to generate a quantum circuit using the TimeEvolution module, and then repeat the circuit n times to obtain an n-order approximate circuit. We can implement the entire process very concisely: TimeEvolution(h, 1.0/n).circuit*n , and a short line of code constructs an n-order approximation.

Then the matrix m2 of this line will be compared with the theoretical solution m1. If the accuracy is 1e-2, the loop will be jumped out, so that the minimum n required to achieve accuracy is obtained.

Question 9

This question tests how to add noise to the line. In MindQuantum, the noise model can be constructed through ChannelAdder . First, we set the gate to which noise needs to be added through GateSelector, and then use MixerAdder to combine the noise we want to add, for example: MixerAdder([GateSelector('x'),DepolarizingChannelAdder(0.05, 1)]). The Y gate and CNOT gate can be deduced in the same way. Finally, they are combined into a noise model through SequentialAdder:

Question 10

This question considers the situation of running real quantum hardware. At this time, we cannot directly obtain the expected value of the Hamiltonian. We can only obtain the result by processing the bit string obtained by multiple samplings. Assume that the final state of the line is

, then the expected value is (because). After sampling 10,000 times, the obtained bit string distribution should be approximate to the corresponding coefficient, so it can be considered: a=res.data.get('00', 0)/shots, and so on, and finally the calculated expected value is returned That’s it.

Contest registration & inviting friends to participate

Click to view the prizes and operation steps: https://competition.huaweicloud.com/information/1000042022/invite

The prize pictures are for reference only. The actual prizes received shall prevail. The quantity is limited and first come first served!

Competition link: https://competition.huaweicloud.com/information/1000042022/introduction

Click to follow and learn about Huawei Cloud’s new technologies as soon as possible~

RustDesk suspends domestic services due to rampant fraud Apple releases M4 chip Taobao (taobao.com) restarts web version optimization work High school students create their own open source programming language as a coming-of-age gift - Netizens' critical comments: Relying on the defense Yunfeng resigned from Alibaba, and plans to produce in the future The destination for independent game programmers on the Windows platform . Visual Studio Code 1.89 releases Java 17. It is the most commonly used Java LTS version. Windows 10 has a market share of 70%, and Windows 11 continues to decline. Open Source Daily | Google supports Hongmeng to take over; open source Rabbit R1; Docker supports Android phones; Microsoft’s anxiety and ambitions; Haier Electric has shut down the open platform
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/4526289/blog/11105882