Comments (6)
Have you solved the previous task, superposition of two bit strings? One of the possible solutions for it uses a similar approach, which is discussed in issue #66.
This task is based on the same principle; you can read about it in a bit more detail in the editorial for the contest in which it was used (problem A2).
Please let me know if these two sources help you or if after reading them you still have some questions. We are planning to write "workbooks" for some of the katas (including this one), which will provide not only the code answer but also the details on how to arrive to this code (both the math behind the solution and the insights into non-trivial features of Q#, if any are used in the code). These are some time away from being released, though - stay tuned!
from quantumkatas.
Thanks for the editorial @tcNickolas, It is really useful especially now when there's lack of structured information available on this topic.
And yeah, I have done the task on superposition of two bit strings .
But I am still hazy on the part (ControlledOnInt(i, X))(anc, qs[j]);
I am unsure of what exactly is happening here , and though I understand(from issue #66 ) the latter part code(below) is so that superposition doesn't collapse, but i don't get why the same uncomputing technique is cannot be used(as mentioned in issue #66 ).
// Uncompute the ancillas, using patterns on main qubits as control
for (i in 0 .. 3) {
if (i % 2 == 1) {
(ControlledOnBitString(bits[i], X))(qs, anc[0]);
}
if (i / 2 == 1) {
(ControlledOnBitString(bits[i], X))(qs, anc[1]);
}
}
P.S.Please do keep me posted about those "workbooks".
from quantumkatas.
Let's look at the example from the statement: N = 3 and desired state |010⟩ + |100⟩ + |001⟩ + |110⟩ (I'm dropping normalization here, you can check more carefully that it works out).
After we apply H to the ancillas, we get a state (|00⟩ + |01⟩ + |10⟩ + |11⟩) ⊗ |000⟩ (the first two qubits are ancillas, the last 3 - the ones on which we prepare the state).
(ControlledOnInt(i, X))(anc, qs[j]);
allows us to pick one of the ancilla states as control (if i = 0
, the control state is |00⟩, etc.) and to set up the right bit pattern on the target qubits. If bits[0] = [false, true, false]
, we can convert the part of the superposition |00⟩ ⊗ |000⟩ into |00⟩ ⊗ |010⟩ to match the first term of the superposition we're trying to prepare.
After this step the state of the system is going to be |00⟩ ⊗ |010⟩ + |10⟩ ⊗ |100⟩ + |01⟩ ⊗ |001⟩ + |11⟩ ⊗ |110⟩ (ControlledOnInt uses little-endian order of bits).
For the uncomputing part of the solution, we need again to consider each part of the superposition and convert the state of the ancilla qubits in it back to |00⟩. For example, taking the second term, |10⟩ ⊗ |100⟩, we have to use the bit pattern 100 as control and flip the first ancilla bit to 0 - this is what ControlledOnBitString allows to do.
Try to work out this example in details, and it should get more clear for you how the overall solution works. Let me know if that helps!
from quantumkatas.
Okay I worked out the problem as you suggested @tcNickolas and i understood the use of ancillas.
And I abstractly understood the use of ControlledOnBitString function in this problem but could you elaborate on the what exactly it is (I tried the documentation but couldn't understand much perhaps an example of it in different problem would be helpful).
from quantumkatas.
ControlledOnBitString applies an operation to the target register if the control register is in the state described by the given bit string (instead of the |1...1> state like the normal controlled operation does). Internally it does the following steps:
- applies X gate to each qubit that corresponds to a 0 bit in the bit string;
- applies normally controlled version of the operation (apply operation if all control qubits are in |1> state) to the control and target registers;
- and applies X gate to each qubit that that corresponds to a 0 bit in the bit string again to return control register to its starting state.
from quantumkatas.
Initially i was having a hard time following through the steps but then I did some reading on oracles and controlled operations, now it all makes much more sense.
Thank you @tcNickolas .
from quantumkatas.
Related Issues (20)
- Sample solutions for task 1.14 of the Superposition katas. HOT 2
- Mistake in multi-qubit measurement tutorial exercise 2 calculations. HOT 1
- Enable tests that are currently excluded with multicell solution tag HOT 2
- [MultiQubitSystemMeasurements] Add code to Exercise 2 solution to show state in Pauli X basis HOT 2
- Fix math mode rendering in browser HOT 5
- Task 1.15 in Measurements Kata says two states are orthogonal. HOT 2
- Exercise 5 for RandomNumberGenerationTutorial - slightly cleaner solution HOT 4
- QFT Question HOT 9
- Late introduction of `ControlledOnInt` operation HOT 4
- Disable cell id generation while working on jupyter notebooks locally HOT 2
- Validate only changed katas…
- %kata magic doesn't work with lambda expressions HOT 1
- O(1) time complexity solution to Oracles tutorial, task 4.2 HOT 9
- Add error-free arbitrary state transmission demo to QEC_BitFlipCode kata HOT 7
- docker image creation is stuck HOT 1
- Add Memory Management Tutorials and Concepts HOT 1
- Systems of Equations not properly explained HOT 1
- BasicGates kata task 1.6 PhaseChange fails
- Docker Build Failing HOT 1
- getting issue in exit command HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quantumkatas.