代写CSE1010调试Python

CSE1010 Final Group Project
In this project, you will write a basic Quantum Computation and Communication simulator.
Instructions: First read this document through. Then, look at the ZyBooks lab and you will see a
skeleton code already setup. At certain points there are comments indicating which function is for
which task. Furthermore, there are comments that say ##YOUR CODE HERE. These are hints that
you need to write something there. It is highly recommended you do not remove any code from the
skeleton file.
There are five tasks in this project and you will need to implement a function or functions for each of
them. The skeleton code already has a lot setup for you to get you started. Please refer to the Chapter
15 Zybooks lab for the programming portion of the project.
In addition, your group must make a small presentation during your lab session using Blackboard
Collaborate. During this presentation you should discuss what you learned, talk about your solution,
and any comments you have on the “open ended” “why?” questions listed in Task 5.
About Quantum Computing:
We are all used to classical bits: 0's and 1's, which make up our current computer and communication
systems. Quantum bits (also called qubits) are very different:
1. Qubits can be in a 0 or 1 state (which we denote |0> or |1>) like a classical bit, however, unlike
a classical bit, they can also be in a superposition state – a combination of |0> and |1>. We
denote this by:
x|0> + y|1>
where “x” and “y” are real or complex numbers (for this project you may assume they are real
numbers) with the following property:
x2 + y2 = 1.
The “x” and “y” are called probability amplitudes.
2. Unlike classical bits which you can read any time, quantum bits are measured. This process of
measuring a qubit is destructive and potentially random.
3. You cannot copy an unknown qubit (unlike a classical bit which you can copy as many times as
you like)
To model a qubit mathematically (and using a classical computer), we use vectors. The state |0> is the
vector (1,0) while the state |1> is the vector (0,1). Thus, the superposition state:
x|0> + y|1>
is the vector:
x(1,0) + y(0,1) = (x,0) + (0,y) = (x,y).
>> Therefore, in your simulator, you may represent any qubit as a Python list: [x,y]
Task 1: Write a function createQubit. It takes two inputs: alpha and beta. These are floating point
values. It should return a list [x,y] where:
x = alpha / N
y = beta / N
and:
N = sqrt(alpha2 + beta2)
This makes sure that the list [x,y] is a proper qubit (in that it is normalized: x2 + y2 = 1). (Check this
yourself on paper and make sure x2 + y2 = 1)
Now, measuring a qubit is a destructive process. There are also infinitely many ways to perform a
measurement. We will simulate only two ways: Z basis measurements and X basis measurements.
If you're curious as to why the are called Z and X basis measurements, they have to do with the
eigenvectors of the Pauli Z and X operators. However, knowledge of this is not needed to perform the
tasks here!
Let's consider a quantum state [x,y] which, recall, means the superposition state:
x|0> + y|1>
Now, to perform a Z basis measurement is “easy”: first, you “plug in” your quantum state. Next the
measurement device will “click” (i.e., read or output) either “0” or “1” (but not both). The probability
that it clicks “0” is simply x2. The probability that it clicks “1” is y2. (Recall that x2 + y2 = 1 so this
makes sense!).
For example, if the input state is:
|+>= 1
√2
|0>+ 1
√2
|1> (1)
Then, after measurement, the device will read /click “0” with probability 1/2 or it will read “1” with
probability 1/2. Furthermore, the quantum state undergoes state collapse. That means that, no matter
what the input state originally was, after measurement the state becomes what you observe. So, if the
state was originally |+> (defined above), then if after measuring, the measurement device clicks “0”,
the qubit now really is |0>. The original state, |+>, was destroyed!
Task 2: Write a Z basis measurement function. It should take as input a state [x,y] and simulate a Z
basis measurement. Namely, given [x,y], your simulator should compute: what is the probability of
observing |0>; what is the probability of observing |1>. Then, based on this probability, choose a
random outcome.
An X basis measurement is a little more involved but not much. For this measurement, given [x,y], the
probability of observing “0” is now:
0.5 * (x2 + y2) + xy
The probability of observing “1” is now:
0.5*(x2 + y2) – xy
Note that, now, the probability of observing “0”, given the input state |+> defined above, is always 1!
Task 3: Write an X basis measurement function. Similar to the Z basis one, first compute the
probability of observing 0 or 1. Then simulate the measurement by choosing a random outcome
according to the correct distribution.
Quantum Tomography
Let's say I give you a quantum state |q> but you don't know what it is (i.e., you don't know what the “x”
and the “y” are). If you measure in the Z basis, you will observe one outcome or the other (Be careful:
the simulator may know the probability distribution, but in real life you do not know that from a single
arbitrary state!). If you measure and the device clicks “0” what does this tell you? Not too much. But
now, let's say I give you 1000 copies of |q>. You measure in the Z basis and observe 250 “0”s and 750
1's. This may lead you to conclude that:
|q>=√14 |0>+√34 |1> (2)
Since 250/1000 = ¼ and 750/1000 = ¾. Note the square roots because probability amplitudes are
always the square root of the probability!
This is an example of a (simplified) version of quantum tomography. The idea of taking multiple
copies of an unknown quantum state, subjecting them to measurements, and learning what the
underlying state actually is. (Comment: In real life you need to perform measurements in other bases
to really know the state).
Task 4: Write a simplified quantum tomography simulator. It should be a function that takes as input a
quantum state [x,y] and an integer value “numTrials.” Then, it should repeat the following (simulated)
experiment “numTrials” times:
1. Take a copy of the state and measure it in the Z basis to get an outcome 0 or 1
2. Keep count of how many times you observe 0 or 1
After repeating the above, use this information to guess at “x” and “y”. The guess for x should be
based on the number of times you observe 0; for y it should be based on the number of times you
observe 1. Indeed, from Task 2, note that p0 is x2. You are trying to estimate p0 and, in so doing,
estimating x (similarly y). Be careful about not forgetting square roots in your answer....
Output the following data:
Estimated x is ...
Estimated y is ...
where the … are your guesses. Next, output:
The error is E
where E is the computed squared error, namely:
E = (guess_X – x)2 + (guess_y – y)2,
where guess_x and guess_y are your guesses from the tomography experiment.
Finally, test your function with numTrials at 10, 100, 1000, and 10000 to see how the error diminishes.
Use various x and y.
Quantum Key Distribution
One very useful application of quantum communication is through quantum key distribution (QKD).
The goal of such a protocol is to allow two parties Alice (A) and Bob (B) to establish a shared secret
key – that is, a string of classical bits which are correlated and secret. Key distribution using only
classical communication is impossible unless you make assumptions on the adversary's computational
power (the adversary is attempting to learn information on the secret key that Alice is trying to send to
Bob). However, using quantum communication, it is possible without making any assumptions.
Here you will simulate a basic QKD protocol called the BB84 protocol. The goal is for Alice to
transmit a key to Bob. So the protocol repeats the following process:
1. First, Alice chooses a random key bit (50/50 it's 0 or 1).
2. Next, Alice chooses a random basis Z or X (50/50)
3. Alice now prepares a qubit using the following rules:
1. If the key is 0 and the basis is Z, she sends |0> = [1,0]
2. If the key is 1 and the basis is Z, she sends |1> = [0,1]
3. If the key is 0 and the basis is X, she sends |+> = [1/sqrt(2), 1/sqrt(2)]
4. If the key is 1 and the basis is X, she sends |-> = [1/sqrt(2), -1/sqrt(2)]
The qubit Alice prepares is sent to Bob.
4. When Bob gets the qubit, he chooses a random basis Z or X (50/50) independently of Alice.
Alice BobAdversary
|0>
Key=0
basis=Z
Then, he measures the qubit in the chosen basis to get a key bit (0 or 1).
5. Finally, Alice tells Bob what basis she used.
1. If they match (Alice and Bob used the same basis this time), they add their key bits to their
shared key. They then repeat
2. If the do not match, they throw out this round and repeat
Task 5: Write a function that simulates the above BB84 protocol “numTrials” time. In the skeleton
code, AlicePrepare() is already written for you. Take a look at it to see how it works. You will need to
write functions for Bob and also a function to simulate the entire protocol calling these functions.
Your function should do that following:
1. Simulate the BB84 protocol and every time Alice and Bob use the same basis, they append their key
bits (which can be integers 0 or 1) to a list “aliceKey” and a list “bobKey” variable.
2. After “numTrials”, print the following:
Size of key is …
where … is the length of the final keyA list (the length of keyB should be identical – why?) Finally,
your function should return “aliceKey” (which should match “bobKey” - why?)

热门主题

课程名

omp9727 ddes9903 mgt253 fc021 int2067/int5051 bsb151 babs2202 mis2002s phya21 18-213 cege0012 math39512 math38032 mech5125 mdia1002 cisc102 07 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 efim20036 mn-3503 comp9414 math21112 fins5568 comp4337 bcpm000028 info6030 inft6800 bcpm0054 comp(2041|9044) 110.807 bma0092 cs365 math20212 ce335 math2010 ec3450 comm1170 cenv6141 ftec5580 ecmt1010 csci-ua.0480-003 econ12-200 ectb60h3f cs247—assignment ib3960 tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 econ7230 msinm014/msing014/msing014b math2014 math350-real eec180 stat141b econ2101 fit2004 comp643 bu1002 cm2030 mn7182sr ectb60h3s ib2d30 ohss7000 fit3175 econ20120/econ30320 acct7104 compsci 369 math226 127.241 info1110 37007 math137a mgt4701 comm1180 fc300 ectb60h3 llp120 bio99 econ7030 csse2310/csse7231 comm1190 125.330 110.309 csc3100 bu1007 comp 636 qbus3600 compx222 stat437 kit317 hw1 ag942 fit3139 115.213 ipa61006 econ214 envm7512 6010acc fit4005 fins5542 slsp5360m 119729 cs148 hld-4267-r comp4002/gam cava1001 or4023 cosc2758/cosc2938 cse140 fu010055 csci410 finc3017 comp9417 fsc60504 24309 bsys702 mgec61 cive9831m pubh5010 5bus1037 info90004 p6769 bsan3209 plana4310 caes1000 econ0060 ap/adms4540 ast101h5f plan6392 625.609.81 csmai21 fnce6012 misy262 ifb106tc csci910 502it comp603/ense600 4035 csca08 8iar101 bsd131 msci242l csci 4261 elec51020 blaw1002 ec3044 acct40115 csi2108–cryptographic 158225 7014mhr econ60822 ecn302 philo225-24a acst2001 fit9132 comp1117b ad654 comp3221 st332 cs170 econ0033 engr228-digital law-10027u fit5057 ve311 sle210 n1608 msim3101 badp2003 mth002 6012acc 072243a 3809ict amath 483 ifn556 cven4051 2024 comp9024 158.739-2024 comp 3023 ecs122a com63004 bms5021 comp1028
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图