代写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?)

热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图