By Nickolas, 5 months ago,

Microsoft's Quantum team is excited to announce the Q# Coding Contest – Summer 2020, the third in the series of Q# contests! In this contest you can put your quantum programming skills to the test, solving quantum computing tasks in Q#. The winners (as well as some lucky participants) will receive a Microsoft Quantum T-shirt!

Quantum computing is a radically different computing paradigm compared to classical computing. Indeed, it is so different that some tasks that are believed to be classically intractable (such as factoring integers or simulating physical systems) can be performed efficiently on a quantum computer. In December 2017 Microsoft introduced the Quantum Development Kit which includes the Q# programming language.

In summer of 2018 we hosted the first quantum programming contest, which included problems on introductory topics in quantum computing: superposition, measurement, quantum oracles and simple algorithms. In winter of 2019 we hosted the second quantum programming contest, which offered harder problems on those topics plus some tasks on implementing unitary transformations. This contest will introduce new types of tasks, as well as some twists on the previous ones.

The contest will run from June 19 to June 22. As usual, we will hold a warmup round the weekend before the contest, from June 12 to June 15, to give you an opportunity to get familiar with the contest environment and submission system before the main contest. Participation in the warmup round is optional.

Good luck! We hope you enjoy the contest!

The rules of the contest are:

• The main contest and the warmup round will have several tasks of various complexity levels.
• To solve each task, you will write Q# code to implement the described task. Solutions are accepted in Q# only.
• The solution is correct if it passes all tests from a predefined test set. You will know whether the solution is correct soon after submitting it.
• Participants are ranked according to the number of correctly solved tasks.
• Ties are resolved based on lowest penalty time for all tasks, which is computed as the latest submission time (the time since the start of the contest) for any of the correctly solved tasks. There is no penalty for failed submissions.
• The contest and the warmup round will award T-shirts as follows:
• The top 50 ranked participants in the main contest will receive a Microsoft Quantum T-shirt.
• Random 25 participants of the main contest who solved at least one problem but didn't finish in the top 50 will receive a Microsoft Quantum T-shirt.
• Random 25 participants of the warmup round who solved at least one problem but didn't win a T-shirt in the main contest will receive a Microsoft Quantum T-shirt.
• All T-shirt winners will be selected after the end of the main contest. T-shirt designs will be announced later :-)
• NO PURCHASE NECESSARY. Must be 16 years of age or older. Game ends 06/22/20. For details, see the Official Rules.

For first time Codeforces users:

1. Create user account here.
2. Register for the warmup round here.
3. Register for the contest here.
4. Once the warmup round starts on June 12, access the problems here.
5. Once the contest starts on June 19, access the problems here.

Quantum computing and Q# materials:

Note that this contest will use Q# 0.11.2004.2825, while the previous contests used Q# 0.2 and Q# 0.4, respectively. We've updated the test harnesses from the previous contests to support the latest version of Q#, so you can use them for practice.

Update: The warmup round is over, here is the editorial for the problems. You should be able to see other people's solutions and practice now.

• +512

 » 5 months ago, # |   -115 Is it rated?
•  » » 5 months ago, # ^ |   +94 No. Q# contests are quite different from regular Codeforces rounds, and not frequent enough to warrant a rating of their own :-)
•  » » 5 months ago, # ^ |   0 I find it so weird how people here downvote benign questions like this. Why the hostility?
•  » » » 5 months ago, # ^ |   0 agreed
•  » » » 4 months ago, # ^ |   0 Reddit aftereffects
•  » » 5 months ago, # ^ | ← Rev. 2 →   +6 lol your(ezdp )profile picture shows your reaction after posting "is it rated?" :P
•  » » 4 months ago, # ^ |   -35
•  » » » 4 months ago, # ^ |   0 Please stop posting irrelevant memes everywhere
 » 5 months ago, # |   +27 I'll add to resources: my syntax highlighting for Sublime Text 3 (and maybe something else), which works better than C#/F# syntax highlighting. If you want to improve it, especially by adding samples/tests, feel free to fork or submit a pull request.
•  » » 5 months ago, # ^ |   0 Thanks a lot!
 » 5 months ago, # |   +5 Q# C# F# oof
 » 5 months ago, # |   -24 Do the participants get participation certificates?
•  » » 5 months ago, # ^ |   +39 No. You'll be immortalized in the contest standings, though :-)
•  » » » 5 months ago, # ^ |   -39 So I had never won an argument with my mom. No idea from where female gets so valid and accurate points
 » 5 months ago, # |   +33 Will there be no cf normal rounds like div2 or educational rounds ?
•  » » 5 months ago, # ^ |   +15 Normal CF rounds are pretty much orthogonal to the Q# round, so it doesn't affect them. (In fact, at least one of the previous Q# contests overlapped with a normal round.) Right now the calendar has two upcoming contests in May.
 » 5 months ago, # |   0 Super Excited
•  » » 5 months ago, # ^ |   0 actually you're super saiyan gohan lol!
 » 5 months ago, # |   +143 What will probably happen to me:
•  » » 5 months ago, # ^ |   +213 If you're going to introduce your cat to quantum computing, you might want to avoid the topic of Schrödinger's cat... I believe this is why historically cats don't do so well with quantum physics.
•  » » » 5 months ago, # ^ |   0 LOL
•  » » 5 months ago, # ^ |   0 I have registered in this contest, but also I have not at the same time. Until the contest starts, both cases exist :)
 » 5 months ago, # | ← Rev. 2 →   +15 Can someone with experience from previous Q# contests suggest some more interesting resources?
 » 5 months ago, # |   0 is q# easy to learn? plz suggest resources!!
•  » » 5 months ago, # ^ |   +2 SpoilerUse those to get the answer: Google.com — YouTube.com — Quora.com :D
•  » » » 5 months ago, # ^ |   +13 I hate this kind of response. If he asked about covid-19, sure, but a site dedicated to competitive programming which hosts a competition in q# is a perfectly reasonable place to ask about a programming competition in q#.
•  » » 5 months ago, # ^ | ← Rev. 2 →   +8 I asked last year a similiar question and got a useful resource: http://lapastillaroja.net/wp-content/uploads/2016/09/Intro_to_QC_Vol_1_Loceff.pdfTL;DR The programming environment of Q# is nicely simple, but quantum physics is not.
•  » » 4 months ago, # ^ |   0 I only found the documentation ? also how to install it on local machines?
•  » » » 4 months ago, # ^ |   0 Have you checked the resources linked from the blog post? They definitely have a lot more information than just installation instructions.
 » 5 months ago, # |   0 I'm glad to be able to join these contests again!
 » 5 months ago, # | ← Rev. 2 →   -14 Does anybody knows when the div 2,3,4 will be back ?
•  » » 5 months ago, # ^ |   -13 Yes
•  » » » 5 months ago, # ^ |   -6 Please tell
•  » » » 5 months ago, # ^ |   -7 Can you tell us kingkong1 please !
•  » » 5 months ago, # ^ |   +21 Looking at the contest schedule — May 26 :-)
•  » » » 5 months ago, # ^ |   0 thanks Nickolas , it's okay they have updated new div 2 contest
 » 5 months ago, # | ← Rev. 2 →   0 looks at previous contest participationOh this seems an easy way to get a tshirt, not many participants! I'm sure I can learn the basics in a month I mean how hard can it be.opens Quantum Katas, excited about something new.drowns in linear algebra and hard-to-visualize concepts Seriously though tshirts aside, the topic does seem really interesting and I'd love to get to know more but I didn't like the written tutorials.. maybe just because I prefer videos. Is there any online resource/course that explains all the quantum basics in a more visual way ? Appreciated!
•  » » 5 months ago, # ^ |   +43 ?Linear algebra is like the most visualizable thing ever.
•  » » » 5 months ago, # ^ |   0 Non-trivial quantum computing, the type where you use entanglement non-trivially, starts in 8 (real) dimensions though. A couple fewer if you only look at unit vectors and normalize the global phase in some way, but still strictly more than 3.
•  » » » » 5 months ago, # ^ |   +3 I don't think you need to literally imagine 8 (or whatever) dimensions in your head to "visualize" higher-dimensional linear algebra. Visual intuition about 2- and 3-dimensional stuff carries over well enough. Even when working with infinite-dimensional spaces, doodling 2D stuff on paper can be helpful.
•  » » 5 months ago, # ^ |   +9 Awesome quantum computing offers a lot of resources in a variety of formats — a lot of them are written but there are videos and MOOCs there as well.
•  » » » 5 months ago, # ^ |   0 Thank you! Exactly what I was looking for.
•  » » 5 months ago, # ^ | ← Rev. 3 →   0 Quantum Computing for Computer Scientists helped me with the basics.
 » 5 months ago, # |   +2 What is Q# coding? Why we want this? and why we will do QUANTAM COMPUTING? (I just want to know. Can you please motivate us by telling some awesome benefits?)
•  » » 5 months ago, # ^ |   +22 Here is a great video on "why quantum computing?" by Dave Wecker: https://cloudblogs.microsoft.com/quantum/2018/06/01/achieving-practical-quantum-computing/. And we want to learn Q# to be able to implement the algorithms that allow us to solve unsolvable problems of today.
 » 5 months ago, # |   +10 I'll participate in the contest. Also you are beautiful!
•  » » 5 months ago, # ^ |   +107
•  » » » 5 months ago, # ^ |   -6 if he is participating because she's beautiful. BIG SIMP else just a compliment.
 » 5 months ago, # |   0 I've always found quantum computing fascinating, and now I have a reason to learn its language and work with it :)
 » 5 months ago, # |   -6 Div4-div2-edu CF is charming again. Thanks for these contest.
 » 5 months ago, # |   -7 Are these warmup challenges only for practice purposes or rated on codeforces?
•  » » 5 months ago, # ^ |   +15 Both the warmup round and the main contest are not rated. You can win a T-shirt in the warmup round, though, so it's a little more significant than only for practice purposes this time.
•  » » » 5 months ago, # ^ |   0 Okay! Thanks :)
 » 5 months ago, # |   0 Well, lets see if I can solve even a single problem
•  » » 5 months ago, # ^ |   0 haha , me too !
 » 5 months ago, # |   +10 Can someone tell me how do I run a Q# program on terminal? Googled a bit and they all told me to download some IDE.
•  » » 5 months ago, # ^ |   +6 You can bypass Visual Studio and just use .Net Core SDK (packages dotnet*) in Linux. Look for commands that use it, like here.
•  » » » 5 months ago, # ^ |   0 Thanks a lot!
 » 5 months ago, # | ← Rev. 3 →   -10 .
 » 5 months ago, # |   -32 Don't upvote.
•  » » 5 months ago, # ^ |   +2 Okay, Downvoted.
•  » » » 5 months ago, # ^ |   0 Are betichod har jagah bakchodi karta hai be tu toh
•  » » » » 5 months ago, # ^ |   0 LOL
 » 5 months ago, # |   +4 Can anyone suggest best apps for writing code like codeblocks ( other than codeblock) for a windows user
•  » » 5 months ago, # ^ |   0 well I use vs code
•  » » 5 months ago, # ^ |   0 vscode or clion
 » 5 months ago, # |   0 Does anyone have experience running Q# via Jupyter Notebooks? I tried some sample code from the warm-up rounds and it shows "The given key was not present in the dictionary".
•  » » 5 months ago, # ^ |   0 Can you please provide the exact steps you're following for a repro? It could be, for example, this issue if you're opening namespace in a separate cell. In general, Q# accumulated some syntax and libraries changes since the last warmup round (it's been over a year, after all :-)), so some of the code will generate warnings and errors on the latest Q#.
•  » » » 5 months ago, # ^ | ← Rev. 2 →   0 Does this help? I'm not sure what you mean by 'repro'. I used this link for installing Q# in Jupyter Notebooks.I basically copied code from the warmup round 2018 and tried running it in one cell. Since I could get 'Hello World' and other simple programs to run, I thought I could run code the same way as other languages. But it seems I'm missing @EntryPoint() and other important syntax or I need a separate script for inputs? Either way, I guess I need to spend more time reading the docs.
•  » » » » 5 months ago, # ^ |   0 "Repro" is the fragment of code or sequence of steps that allows to reproduce your problem. In this case, the screenshot tells me that you don't need to specify the namespace if you're running in notebooks, just the open directives and the operations you declare. (You don't need to specify EntryPoint either in the notebooks or when running on Codeforces, that is syntax for standalone Q# application which is a yet separate scenario.)You raise a good point here. I'll see if I can find the docs about the differences between running Q# in notebooks vs in console app. For Codeforces, each problem specifies the signature your code should have, and that matches running Q# code as an app with a driver.
•  » » » » » 5 months ago, # ^ | ← Rev. 2 →   0 Thanks for explaining! So you mean that for running Q# code using VS Code(for example) and .NET, you need a custom driver program in C# for each solution ?I'm considering switching to another method(like VS Code) as my Q# kernel won't connect any longer for some reason.
•  » » » » » » 5 months ago, # ^ |   0 There are multiple ways to run Q# code; you can do it with a driver program in C# or Python, or you can do it as standalone executable. Codeforces testing harness uses C#, since I need specific exception processing to provide different verdicts for some problems. You can find examples of different ways in this repository: How are you running Q# notebooks? If you install it locally, a restart should fix things like unresponsive kernel.
•  » » » » » » » 5 months ago, # ^ | ← Rev. 3 →   0 Thanks, I'll check them out.I'm running it via Anaconda. The problem is not an unresponsive kernel but a kernel that doesn't connect at all. Something like this but just for Q#. Python works fine.
•  » » » » » » » 5 months ago, # ^ |   0 How do we check in our local ide whether we have generated the correct state that has been desired in the question ?
•  » » » » » » » » 5 months ago, # ^ |   0 If you're running a task with a provided test harness, like in the Quantum Katas, the test harness will take care of that for you. If you don't have a test harness, you can use DumpMachine after preparing the state to see the amplitudes of the basis states and check whether they match the required ones.
•  » » » » » » » » » 5 months ago, # ^ |   0 Okay thanks, i'll try it out
 » 5 months ago, # |   0 When will the T-shirt designs be revealed? I'm debating whether I should participate or not, because it takes time to prepare and study for this, and I have other stuff that's taking up my time.
•  » » 5 months ago, # ^ |   0 As soon as we have them :-)
 » 5 months ago, # | ← Rev. 4 →   0 I am trying to learn Q# with the help of Quantum katas but am stuck in a question. i dont know to whom to ask so i am asking it here. can anyone help? I m stuck at exercise 6 in single qubit gates.
•  » » 5 months ago, # ^ |   0 Have you checked the solution in ReferenceImplementation.qs? For solving these exercises you go through the list of available gates and their effects (for example, in BasicGates tutorial) and check which ones have effects similar to what you need. In this case, it's just one gate.
•  » » » 5 months ago, # ^ |   0 I just didn't found the solution to this exercise previuosly. Thanks for sharing. I now totally understand it!
 » 5 months ago, # |   0 can anyone explain U3 of 2019 Warmup. I read the editorial but didn't understand it.
•  » » 5 months ago, # ^ | ← Rev. 2 →   +3 For an integer $k \in [0, 2^N - 1]$, I write $|k\rangle$ to mean the state vector corresponding to the little-endian encoding of $k$. The required unitary needs to do the following: For $k < 2^{N - 1}$, map $|k\rangle$ to $|2^{N - 1} - 1 - k\rangle$. For $k \geq 2^{N-1}$, map $|k\rangle$ to a superposition of $|2^{N-1}\rangle, |2^{N-1} + 1\rangle, \ldots, |2^N - 1\rangle$. The first task can be accomplished by flipping the each qubit in qs[0 .. N-2] if qs[N-1] == 0. This is done via the line ApplyToEach((ControlledOnInt(0, X))([Tail(qs)], _), Most(qs)); The second task can be accomplished by applying the $H$-gate to each qubit in qs[0 .. N-2] if qs[N-1] == 1. This is done via the line ApplyToEach(Controlled H([Tail(qs)], _), Most(qs)); 
•  » » » 5 months ago, # ^ |   0 I understood how the program implements the unitary. What i can't understand is how you found out what the required unitary did.
•  » » » » 5 months ago, # ^ |   +3 You can read off what a unitary does from it's matrix. For example, here's the matrix for U3 for $N=3$: ...X.... ..X..... .X...... X....... ....XXXX ....XXXX ....XXXX ....XXXX The leftmost column tells us what $|0\rangle$ gets mapped to. In this case it gets mapped to $c_0|3\rangle$, for some complex constant $|c_0| = 1$. This is because the only X in column zero is in row 3, and we know the unitary transform preserves norms. More generally $|0\rangle$ gets mapped to $c_0|2^{N-1}-1\rangle$.Column one tells us that $|1\rangle$ is mapped to $c_1|2^{N-1}-2\rangle$ for some $|c_1| = 1$.Likewise the rightmost column tells us that $|2^N - 1\rangle$ gets mapped to some linear combination of $|2^{N-1}\rangle, |2^{N-1} + 1\rangle, \ldots, |2^N - 1\rangle$.
•  » » » » » 5 months ago, # ^ |   0 Thanks
 » 5 months ago, # |   -10 Is it rated?
•  » » 5 months ago, # ^ |   0 No … Already asked and answered in the 1st comment :v
•  » » 5 months ago, # ^ |   -22 I think it is yes because last year it was rated.
 » 5 months ago, # |   -8 looking forward to participate.
 » 5 months ago, # |   -16 Rated!!!Finally a Rated contest!!!I'm so excited!!!
 » 5 months ago, # |   0 is it possible to learn Q# like in 10 hr or so if it is then can you plz share some material
•  » » 5 months ago, # ^ |   0 The resources I link in the post are really good — and you don't need to learn all the capabilities of Q#, just enough to start solving the problems. For example, you can safely skip generics :-)
•  » » » 4 months ago, # ^ | ← Rev. 2 →   0 so now I have to stay up the whole night :) thanx a lot!!!! I also find https://www.youtube.com/watch?v=F_Riqjdh2oM this video from Microsoft very good for beginners
•  » » » » 4 months ago, # ^ |   +1 The warmup round runs for 3 days, and the T-shirts in it are awarded randomly, so quite that level of sacrifice might not be necessary :-)
•  » » » » » 4 months ago, # ^ |   0 actually my exams are also going on :| i have to do lots and lots of assignments from day after tomorrow!! ༼ ಥ_ಥ ༽ sometimes i wonder why i m always so fucked up!!
•  » » » » » » 4 months ago, # ^ |   0 Welcome to the Life of every non-cs cs guy.
 » 4 months ago, # |   0 Can anyone help me with testing the code locally?For example I wrote a Q# program, how can I test it with some testcases.I have no experience except learning from QuantumKatas which provides unit test. I have installed the environment suggested here.
•  » » 4 months ago, # ^ |   0 This particular problem is task 1.11 from Superposition kata, so it's very easy to test :-)More generally, testing quantum programs can be quite challenging, depending on the type of problem. You can study the testing harnesses in the Quantum Katas to see how they are implemented for a type of problem similar to yours. Superposition tasks, though, are tested by comparing them with the correct solution, so if you don't have a correct solution on hand, you can't take the same approach. In this case I would use DumpMachine to check the amplitudes of the basis states in the state you prepared.You can follow this tutorial to create a runnable executable with Q# code and then modify Q# code to allocate qubits, call your solution on them and use DumpMachine to inspect the amplitudes.
•  » » » 4 months ago, # ^ |   0 Thank you!! I think DumpMachine would be useful for the contest.
 » 4 months ago, # |   0 Though it's not rated, it will provide tough competition.Rated contests are only for motivation, the reality is to solve practice questions which boost up the confidence.Thanks Nickolas.Happy Coding! :)
 » 4 months ago, # |   -10 In this contest, will Python3 be acceptable?
•  » » 4 months ago, # ^ |   0 From the announcement blog: To solve each task, you will write Q# code to implement the described task. Solutions are accepted in Q# only.
 » 4 months ago, # | ← Rev. 3 →   0 Could anyone get the IntelliSense in Visual Studio working for Q#? Mine cannot find the namespaces and gives errors like 'No namespace with the name "Microsoft.Quantum.Canon" exists.'. The program compiles and runs correctly.
•  » » 4 months ago, # ^ |   0 VS IntelliSense can be sensitive to a number of things in your environment, like .NET Core version and VS version; for example, this issue happens when you're running QDK 0.11.2004.2825 with .NET Core 3.1.300. I got my configuration working but I'm using .NET Core 3.1.201.
 » 4 months ago, # |   +16 Is it possible to run code in the Custom Invocation tab? I tried adding an entry point, but I'm getting this error: error QS6241: Invalid entry point. Only executable Q# projects can have entry points. My code: @EntryPoint() operation Main() : Unit { Message("Test"); } Googling the error code did not help at all.
•  » » 4 months ago, # ^ |   0 Custom invocation was implemented for the last contest:https://codeforces.com/blog/entry/65579 Custom Invocation allows you to run Q# code on Codeforces servers; make sure your code has namespace Solution and an operation with a signature operation RunQsharp () : Bool defined in it. See if that still works.
•  » » » 4 months ago, # ^ | ← Rev. 2 →   +3 It doesn't, unless I misunderstand something. namespace Solution { open Microsoft.Quantum.Intrinsic; operation RunQsharp () : Bool { let result = 1; Message($"Got some {result}"); return true; } } CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry pointEdit: this code now works, thank you. •  » » 4 months ago, # ^ | +5 You definitely shouldn't have to add @EntryPoint to run in Custom Invocation. However, it looks like it was broken when we updated Codeforces from the previous QDK version to 0.11. Let us look into fixing this... •  » » 4 months ago, # ^ | +3 We've updated custom invocation, so it should work now if you define a wrapper operation RunQsharp: namespace Solution { open Microsoft.Quantum.Intrinsic; operation RunQsharp () : Bool { // your code here let result = 1; Message($"Got some {result}"); return true; } }
 » 4 months ago, # | ← Rev. 2 →   0 I have a question. Maybe this is really stupid.How does Q# works? First i thought maybe they run on an actual quantum computer and we just get the output but what happens when we run it locally. Is the Microsoft quantum development kit a simulation which behaves like a quantum computer but inefficient because it's on a classical computer? I really have no idea edit: corrected a mistake
•  » » 4 months ago, # ^ |   0 Microsoft QDK is a collection of tools, from the Q# programming language and compiler to several simulators. When you run a Q# program locally, it will typically use a full state simulator which imitates the behavior of a perfect (error-free) quantum device up to ~30 qubits. You will also be able to use QDK to run the same Q# programs with a resource estimator or on real hardware, but this is out of scope of this contest :-)
 » 4 months ago, # |   +26 What is the best way of casting LittleEndian to Qubit[]?It seems like, without casting, it's impossible to access individual qubits. I looked through the Q# reference, including the LittleEndian and Convert documentation, and couldn't find anything that works.
•  » » 4 months ago, # ^ |   +39 LittleEndian is a wrapper type around the Qubit[] type, so to treat it as a Qubit[] you need to unwrap it: Length(register!) to get the number of qubits or register![i] to get i-th qubit.
•  » » » 4 months ago, # ^ |   +26 Thanks, that's exactly what I needed! I found the "newtype LittleEndian = Qubit[]" but didn't know how to remove the tag.Is there a page in the reference talking about the "!" syntax?
•  » » » » 4 months ago, # ^ |   +24 Types in Q#, more specifically the section on unwrap operator.
•  » » » » » 4 months ago, # ^ |   +5 I had the same question as Svlad_Cjelli. Thank you for the answer!Is there an easily searchable repository of Q# examples yet? If I'd seen any piece of code actually using LittleEndian I think this would have been obvious, but I don't know where to look. I don't think the documentation helps.
•  » » » » » » 4 months ago, # ^ |   0 https://github.com/Microsoft/QuantumKatas/ and https://github.com/Microsoft/Quantum. It would be tricky to search for !, but LittleEndian is quite searchable.
 » 4 months ago, # |   +44 Excuse me, but... why? set arr w/= idx <- expr; From the docs: In the case of arrays, Microsoft.Quantum.Arrays in our standard libraries provides the necessary tools for many common array initialization and manipulation needs, and thus help avoid having to update array items in the first place. Ok, but I don't want to have to remember the entire standard library just to write some simple imperative testing code. I'm already making a G̶o̶o̶g̶l̶e̶ Bing search every minute.
•  » » 4 months ago, # ^ | ← Rev. 2 →   0 I much prefer the old syntax (set arr[idx] = expr;) even if it's semantically an ugly special case.
 » 4 months ago, # | ← Rev. 2 →   0 Could someone help with setting up the machine learning environment? I tried doing everything as instructed but the compiler complains about having C# and Q# files in the same project, saying I should convert the executable Q# project into a Q# library and moving C# into a separate project. But when I do that, the C# project doesn't recognize and Q# classes, even though I added the Q# library project as a dependency.I also tried using python for the host program but that didn't work either for some reason, currently investigating.EDIT: I managed to get Python to work.
•  » » 4 months ago, # ^ |   0 Have you tried taking the projects from https://github.com/microsoft/MLADS2020-QuantumClassification or from https://github.com/microsoft/Quantum/tree/master/samples/machine-learning/? That's what I did when I started learning our QML library — starting with a project that already does it and modifying it is a lot easier than starting from scratch.
•  » » » 4 months ago, # ^ |   0 Yes, I tried building the HalfMoon example but it gave me the same errors. I guess I have a newer version of the QDK which has some non-backward-compatible changes?
•  » » » » 4 months ago, # ^ |   0 If you're building an existing project HalfMoon, it should use the version of QDK specified in its csproj file, and it should build regardless of the QDK version you have installed. When I try to build it, it gives me a warning "The project is an executable Q# project but no entry point has been found. The project should be a library, and any C# driver code should be defined in a separate project.", but as it's a warning, it can be safely ignored. If you're getting an actual error, can you give the exact error message you get?
•  » » » » » 4 months ago, # ^ |   0 I'm getting a runtime error "Could not load file or assembly 'System.Runtime, Version=4.2.2.0'" I tried some suggested fixes from StackOverflow but nothing worked.Now, I did make it build and run from Python, but it's not really working well. All the final parameters end up within 0.0001 of one of the initial parameter seeds, and the end result has 15% error rate. I tried increasing the LearningRate parameter, but it didn't help. Applies to both the original HalfMoons example and the D1 training set.
•  » » » » » » 4 months ago, # ^ |   0 This looks like some issue with the .NET Core version or VS, I haven't seen this kind of error recently...In the tutorial I had to both increase the LearningRate and decrease the Tolerance. Additionally, starting with multiple starting parameter sets for search helps.
•  » » 4 months ago, # ^ |   0 Anyone else manage to pass D1/2 without actually getting machine learning to work? :|
•  » » » 4 months ago, # ^ |   0 Well, I know how to do it, so it's not unexpected that you'll be able to figure it out :-) However, for the sake of solving problems in the main round you'll probably want to get it to work.
•  » » » » 4 months ago, # ^ | ← Rev. 5 →   0 Seems doubtful, overwhelmed by too many errors D:Regarding Python / Jupyter Notebooks:The intro works fine. However, "InsideQuantumClassifiers": When running the code under "Raw Data" I get a bunch of errors ... Hidden/snippet_.qs(7,23): error QS5022: No identifier with the name "RandomReal" exists. /snippet_.qs(7,38): error QS5022: No identifier with the name "RandomReal" exists. /snippet_.qs(8,21): error QS5022: No identifier with the name "ArcTan2" exists. /snippet_.qs(16,39): error QS5022: No identifier with the name "PI" exists. /snippet_.qs(16,51): error QS5022: No identifier with the name "PI" exists. /snippet_.qs(17,5): error QS5022: No identifier with the name "Message" exists. I saw this but it doesn't seem to help. %package gives Microsoft.Quantum.Standard::0.11.2006.403 Microsoft.Quantum.MachineLearning::0.11.2004.2825 "ExploringQuantumClassificationLibrary": %package and %version don't seem to work at all. "HalfMoons": Hiddenfail: Microsoft.Quantum.IQSharp.Workspace[0] QS6104: No namespace with the name "Microsoft.Quantum.MachineLearning" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS6005: No type with the name "ControlledRotation" exists in any of the open namespaces. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS6005: No type with the name "SamplingSchedule" exists in any of the open namespaces. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "LabeledSample" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS6222: The type of the given expression cannot be determined. Provide explicit type arguments ("identifier"). fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "TrainSequentialClassifier" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "SequentialModel" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "DefaultTrainingOptions" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "LearningRate" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Tolerance" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "VerboseMessage" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "SamplingSchedule" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "LabeledSample" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS6222: The type of the given expression cannot be determined. Provide explicit type arguments ("identifier"). fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "ValidateSequentialClassifier" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "SequentialModel" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS6005: No type with the name "SequentialModel" exists in any of the open namespaces. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Structure" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Parameters" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Bias" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "EstimateClassificationProbabilities" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "InferredLabels" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "ControlledRotation" exists. Preparing Q# environment... fail: Microsoft.Quantum.IQSharp.Workspace[0] QS6104: No namespace with the name "Microsoft.Quantum.Convert" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS6104: No namespace with the name "Microsoft.Quantum.Intrinsic" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Message" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Length" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Message" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Length" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Mapped" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Zip" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Message" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Mapped" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Message" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Message" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Message" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Fold" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "TimesD" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Length" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Mapped" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Zip" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "IntAsDouble" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "IntAsDouble" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Length" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Mapped" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Default" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Structure" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Parameters" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "Bias" exists. EDIT: Ok changing MachineLearning to 0.11.2006.403 seems to work for "InsideQuantumClassifiers" and "HalfMoons."
•  » » » » » 4 months ago, # ^ | ← Rev. 3 →   0 Half-moons with C# runs (although as mentioned earlier the error rate seems to be above 15%?).I see that  is part of HalfMoons.csproj. After adding open Microsoft.Quantum.MachineLearning; to Program.qs how do I automatically add it to .csproj? dotnet restore and dotnet build don't change anything, are they supposed to?
•  » » » » » » 4 months ago, # ^ |   +10 I don't think the package reference can be added automatically, you have to add package reference first and then you can open namespaces (I think other .NET languages work the same, it's not a Q# restriction). dotnet restore and dotnet build restore NuGet packages that are already specified in .csproj, not add new ones.For your earlier comment that is unresolved, %package and %version are IQ# commands, and ExploringQuantumClassificationLibrary is a Python notebook, so they won't work in that one.
•  » » » » » 4 months ago, # ^ |   0 Can confirm, after seeing a lot of errors and 50% missrates I finally had a successful training in InsideQuantumClassifiers.ipynb with 0.11.2006.403 change. Still no luck with the Moons, though.
•  » » » » » 4 months ago, # ^ |   0 I also encounter many errors when running "InsideQuantumClassifiers". Changing MachineLearning to 0.11.2006.403 helps a lot! I think this should be fixed in "InsideQuantumClassifiers".
•  » » » 4 months ago, # ^ |   0 I've thought about it, but from what I gathered from the documentation, the preparation of the qubit state from a given input isn't deterministic. How did you figure it out?
•  » » » » 4 months ago, # ^ |   0 Ok, I found the actual library implementation, it's much simpler than what they say in the arxiv paper as there's no normalization with added padding elements to preserve features. I'll have to think about how to extract the maximum probability component of a qubit, sounds similar to Grover's algorithm...
•  » » » » » 4 months ago, # ^ |   0 I got it, the library automatically does that, haha. It turned out way easier that I thought.
•  » » » » » » 4 months ago, # ^ | ← Rev. 3 →   0 Did you find a place where that's mentioned in the documentation? How can I determine how many qubits will be used? (other than assuming myself)
•  » » » » » » » 4 months ago, # ^ | ← Rev. 2 →   0 The same principle is used in machine learning in general, I just forgot about it.The network outputs a list of "confidence" probabilities, and the top one is chosen as the "answer".I thought maybe quantum machine learning would give results randomly according to the probabilities, but that's not the case, they run it many times to calculate the probability and then just output the most likely one.So in the D1 task, if you don't apply any rotations and just measure the qubit directly, you'll get the exact opposite from the desired result: the state preparation assigns the X coordinate to the Zero eigenvalue and the Y coordinate to the One eigenvalue, while the task is to output 1 if x>y and 0 otherwise.The solution is just to apply an X flip, or equivalently a Y rotation of Pi.
•  » » » » » » » 4 months ago, # ^ | ← Rev. 4 →   0 The number of qubits is always the logarithm of first power of two greater than the number of features (dimensions), or equivalently the ceiling of the logarithm of the number of features.In our 2D case, that is 1.The states are assigned as probability amplitudes of a LittleEndian register.So the first dimension (in this case, the X coordinate) is the probability amplitude of the 0 value, and the second is of the 1 value.Of course, they are first normalized, as the total probability must be unity.If you want to avoid that, you may want to preprocess your samples with an additional dimension that takes care of the normalization and is later ignored in the circuit.With 4D data, each coordinate would correspond to the probability amplitude of one value of the register, 00, 10, 01, 11.Et cetera for bigger data.In the cases of tasks D1 and D2, normalization works in our favor since classification only depends on the polar angle of the point, and not on its distance from the origin.
•  » » » » » » » 4 months ago, # ^ |   0 If you want to avoid that, you may want to preprocess your samples with an additional dimension that takes care of the normalization and is later ignored in the circuit. Alright, this is what I wanted to know. But still, are these mentioned in the documentation somewhere?
•  » » » » » » » » 4 months ago, # ^ |   +8 The documentation is pretty bad, yes.I think the best explanation is in this tutorial, though it could be better: https://github.com/microsoft/MLADS2020-QuantumClassificationI also had to check out the implementation of the library to understand some things: https://github.com/microsoft/QuantumLibraries/tree/master/MachineLearning/srcOf course, there's the official documentation, but it's pretty bad: https://docs.microsoft.com/en-us/quantum/libraries/machine-learning/For more theoretical details you may want to check the paper describing the technique: https://arxiv.org/abs/1804.00633I personally spent more than 8 hours to get everything working...
 » 4 months ago, # |   0 How can I test my program locally with testcases?(In jypyter notebook) I've done a lot of searching but cannot find a good answer. Hope someone can help, Thanks.
•  » » 4 months ago, # ^ |   +5 That really depends on the kind of program you need to test. (The main challenge is devising the code, not porting it to Jupyter notebook.)You can study the testing harnesses in the Quantum Katas to see how they are implemented for a type of problem similar to yours. This will work, for example, for reversible-computing problems (the katas are SolveSATWithGrover, GraphColoring and RippleCarryAdder). For problems A1-A5 the testing harness is the closest to the one used in the Measurements kata.Superposition tasks, though, are tested by comparing them with the correct solution, so if you don't have a correct solution on hand, you can't take the same approach. In this case I would use DumpMachine to check the amplitudes of the basis states in the state you prepared and compare them with the ones you need.
 » 4 months ago, # |   0 Microsoft.Quantum.IQSharp.Workspace[0] QS6104: No namespace with the name "Microsoft.Quantum.MachineLearning" exists.running the host python program just gives this error
•  » » 4 months ago, # ^ |   0 It's hard to debug without seeing the code (you can ask a question in contest interface so that only the contest managers will see it). Did you do things like the following to import the package? import qsharp qsharp.packages.add("Microsoft.Quantum.MachineLearning::0.11.2004.2825") qsharp.reload()
•  » » » 4 months ago, # ^ |   0 Thanks
•  » » » 4 months ago, # ^ | ← Rev. 2 →   0 I trained the model and got a array of parameters and a bias.. so how do i submit it
 » 4 months ago, # |   0 Are the type of tasks in the practice contest indicative of the type of problems we will have in the main contest? QML is something completely new this time so I guess we can expect it in the main contest as well right?
•  » » 4 months ago, # ^ |   0 Yes. The goal of the warmup round is to prepare you to solving the harder problems of the main contest: allow you to set up your environment and make sure it works and figure out how the new types of problems work.
 » 4 months ago, # |   +8 The only thing not in the QML resources is that how are the Controlled Rotations chosen
•  » » 4 months ago, # ^ | ← Rev. 4 →   +11 That's where your creativity comes in, I guess.Well, in these two particular cases, with a single qubit representing an angle, it's obvious only Y rotations make any sense.For more general cases, I suggest starting by replicating the examples given in the documentation for general-purpose two- and three-qubit circuit configurations.If that doesn't yield satisfactory results, you should look for some sort of nice structure in the given data, and design the circuit yourself specifically to exploit that.
•  » » » 4 months ago, # ^ |   +8 how do i encode sample data into multiple qubits.. i understand that only the angle data is preserved in single qubit encoding... how do i also encode distance data
•  » » » » 4 months ago, # ^ |   0
 » 4 months ago, # |   0 Is there any way to find out what is causing the runtime error in my submit? Everything works fine locally for me.
•  » » 4 months ago, # ^ | ← Rev. 2 →   0 Which task?If it's task B1 or B2, pay attention to the note on the bottom of the task statement.
•  » » » 4 months ago, # ^ |   0 It is task B, but I am only using the allowed gates.
•  » » » » 4 months ago, # ^ |   0 Make sure that any additional qubits used are left with certainty in the zero state.
•  » » » » » 4 months ago, # ^ |   0 I reset all additional qubits at the end of the using block. Can it be that I use more time or memory than allowed?
•  » » » » » » 4 months ago, # ^ |   0 Nevermind, found a different solution which works.
•  » » » » » » 4 months ago, # ^ |   0 In this type of tasks, you have to uncompute the qubits rather than reset them. Resetting them involves measurement, which collapses superposition in which the inputs can be. Uncomputing, though, returns the qubits to zero state without measuring them, thus preserving superposition on the other qubits.
•  » » » » » » » 4 months ago, # ^ |   0 aaah, ok, thanks, makes sense.
 » 4 months ago, # |   0 It might be better to suggest users to downgrade the iqsharp tool as well, to 0.11.2004.2825, if you have the newest version from June. Ran into a couple of issues with the new one with some of the libraries.
 » 4 months ago, # |   0 Trying to run the sample QML code gives the following error (using python): qsharp.clients.iqsharp.IQSharpError: The Q# kernel raised the following errors: /home/geekpradd/Desktop/Q%23/Summer%202020%20Practice/D1/qsharp.qs(2,10): error QS6104: No namespace with the name "Microsoft.Quantum.Convert" exists. /home/geekpradd/Desktop/Q%23/Summer%202020%20Practice/D1/qsharp.qs(3,10): error QS6104: No namespace with the name "Microsoft.Quantum.Intrinsic" exists.I tried using qsharp.packages.add() to add these namespaces but that didn't work also (aren't these the standard Q# namespaces and so this error shouldn't occur.. It seems adding the Machine Learning Package is causing this) Help would be appreciated.
•  » » 4 months ago, # ^ |   +5 Most likely it is a version mismatch.. Try downgrading your iqsharp to 0.11.2004.2825 Or first, try changing the library version to whichever you are using in the add packages line.
•  » » » 4 months ago, # ^ |   0 Thanks a lot. I installed the version of iqsharp that the Jupyter Notebook in the link given was supposed to have and it worked.
•  » » » 4 months ago, # ^ |   0 I installed the latest version and now can't install the older version.Tool 'microsoft.quantum.iqsharp' is already installed.So I tried to dotnet tool uninstall microsoft.quantum.iqsharp -g but I'm getting permission errors, saying that access to the path ~/.dotnet/tools/.store/microsoft.quantum.iqsharp/0.11.2006.403 is denied.Help, please?
•  » » » » 4 months ago, # ^ |   +3 Uninstall the existing version of IQ#: (you might need the -g switch here depending on how you do it; and you'll need to make sure you don't have any Q# notebooks running that would use the kernel) dotnet tool uninstall microsoft.quantum.iqsharp Install the right version: dotnet tool install microsoft.quantum.iqsharp -g --version 0.11.2004.2825 Reinstall the kernel: dotnet iqsharp install That should work.
•  » » » » » 4 months ago, # ^ | ← Rev. 2 →   0 Thanks! I don't remember if I had any notebooks opened, but after rebooting, with everything else closed, it worked for me. I now have the right version. However, ExploringQuantumClassificationLibrary.ipynb still doesn't work for me. InsideQuantumClassifiers.ipynb does though.
•  » » » » » 4 months ago, # ^ |   0 Oh, I just checked out the repo from scratch and it worked. Apparently some state about the previous installation gets persisted into the notebook.
 » 4 months ago, # |   0 Solving at least one problem means like we have to solve all of A, or it means solving atleast one part?
•  » » 4 months ago, # ^ |   +3 A1 and A2 are different problems, you can think of the letters as groups of problems that are solved in broadly the same way.
•  » » » 4 months ago, # ^ | ← Rev. 2 →   0 removed
 » 4 months ago, # |   0 I'm assuming discussing solutions for the warmup round is fine — I'm a bit stuck on B1. I decided to just use this function but this gives me RTE. Testing locally I can't really find an issue. Would it be possible to output the error when the verdict is RTE?
•  » » 4 months ago, # ^ |   0 It's mentioned that arbitary rotation gates (and that function in particular) cannot be used which is why you are getting RTE. You can implement this operation by using Controlled CNOT gates as mentioned in the question
•  » » » 4 months ago, # ^ |   0 Or Controlled recursion ;)
 » 4 months ago, # |   +15 We posted a couple of hints for problems A and C as contest announcements. I hope that helps some of you to get them right! And remember, in the warmup round it's ok to ask for hints and help, though I would draw a line at sharing the exact solution code :-)
 » 4 months ago, # |   0 for the QML problems i understand that only the angle data is preserved and is converted to a single qubit but how do i edit it to encode the data in multiple qubits and also preserve the distance data
•  » » 4 months ago, # ^ |   +8 In these problems you can't do that, but you also don't need this, since the classes are perfectly distinguishable with just the angle. That's why these problems don't offer you this option. Spoiler alertYou'll need to manipulate input data before encoding it in the problems of the main round :-)In general you need to preprocess your data and calculate new features for it before you pass it to the library. For example, in the HalfMoons example the data is preprocessed before encoding: WithProductKernel function adds an extra feature that is the product of all original features. After that the standard encoding realizes that there are 3 features in the data and those can't fit in a single-qubit state, and automatically uses an extra qubit to encode the features (the missing features are padded with 0s to the nearest power of 2).
•  » » » 4 months ago, # ^ |   0 Are there any other examples of adding extra features except Half Moons and also are there any other examples of features for a point except angle and distance
•  » » » » 4 months ago, # ^ |   0 You can build examples of adding extra features yourself easily, if you start with HalfMoons and modify the classical logic of feature calculation to compute whatever feature you need. We will share the testing harness for the main contest, so that you can see the typical feature engineering approaches.Angle and distance are not quite the chosen features of a point, but rather angle is the effective feature that results from encoding two features x1 and x2 into the amplitudes of the basis states |0⟩ and |1⟩: the amplitudes have to be normalized, so they become x1/sqrt(x1^2+x2^2) and x2/sqrt(x1^2+x2^2), which preserves only the angle of the original point. If you have more features, they'll be normalized by dividing them by a square root of the sum of their squares.
•  » » » » » 4 months ago, # ^ |   0 How good of a idea it is to set tolerance to 0.00 to try to keep misses as low as possible
•  » » » 4 months ago, # ^ |   0 I can't get the HalfMoons example to below 10% error rate, and the best model I could get is one that ignores the second qubit and simply says that the upper half is 0 and the bottom half is 1 (or maybe the opposite, I don't remember and can't check right now).It would really help if there was an example of successfully using an extra feature to avoid losing information by normalization.
•  » » » » 4 months ago, # ^ | ← Rev. 2 →   +8 I am trying a way which encodes distance as third feature... it is still training I will let you know the results after training Edit: the best i could do was 15 misses which is around 90% accurate
•  » » » 4 months ago, # ^ | ← Rev. 2 →   0 You'll need to manipulate input data before encoding it in the problems of the main round :-) Can you elaborate on this a bit? Does it mean a preprocessing function will be submitted as well (then you could do any kind of ML on it), or that a manipulation will be defined in the statement (then you could've just had that in the training data in the first place)?Maybe this is a little too specific and revealing of the problems but I'm not seeing how a preprocess step makes sense in the competition.
•  » » » » 4 months ago, # ^ |   0 The idea is to offer a pool of the ways you can manipulate your features (some of them parameterized) and to let you choose the function you want and the parameters for it. This type of problems is still very experimental, but this seems like a reasonable compromise between allowing you to do anything you want (as you point out, it would be a lot easier to classify data classically and return [1,0] for class 0 and [0,1] for class 1) and giving you exactly the features you need to use.Does this make sense?
•  » » » » » 4 months ago, # ^ |   0 Seems reasonable. Thanks for clarifying.
•  » » » » » 4 months ago, # ^ |   0 I observe a very unstable training even with one gate, no matter what (version 0.11.2006.403). Also it's slow (clearly, measurements simulations consume a lot of time).It looks like classical ML methods even without the exact gradient computation will perform way better for such kind of tasks. Though, it was interesting to try such QML anyway :)
 » 4 months ago, # |   0 Is the "time limit per test" taken as the time to run in simulated environment or do you somehow calculate what it will take on a quantum computer? Similar question for memory also..
•  » » 4 months ago, # ^ |   0 Both time and memory are measured for running the simulation. (So, for example, the more qubits you have allocated, the slower the gates become, though this doesn't have noticeable impact until 20+ qubits — I explored this a bit in this blog post)
 » 4 months ago, # |   0 Anyone know how to solve Half Moon with 95-100% accuracy... the best i could do was 85-90%
•  » » 4 months ago, # ^ | ← Rev. 2 →   0 I got the error rate down to 6% with some preprocessing. First I centered everything, then I converted it to polar coordinates, and then added some ad-hoc fixes for the argument wrap-around. After preprocessing, the training data looks like this:which is a lot easier to work with.
•  » » » 4 months ago, # ^ |   0 I got the error rate down to 3%... [3.16204833984375,1.89954833984375,12.87579833984375,0.005798339843750039,-17.62857666015625,-3.89232666015625,11.0446875,9.2503125,-1.2625,0,-15.5603125,2.840625,16.335], 0.19120000000000006 with 5 missescould you help to make a structure for 4 parameters which maybe will get 0% error
•  » » » » 4 months ago, # ^ | ← Rev. 2 →   0 Your parameters mean nothing to me without your structure and your preprocessing...Also, the validation data has only 15 points so you can't have 3% error rate with 5 misses, did you run the validation on the training data or did you make your own data?Also remember that just adding more parameters won't necessarily help. Machine learning is in its essence linear algebra, if there's no linear algebraic relation that can classify the data you MUST apply some non-linear preprocessing, and it can't be just any random processing like the addition of the product that they did, it must transform the data into a form that is easy to classify using quantum gates.
•  » » » » 4 months ago, # ^ | ← Rev. 2 →   +6 I got 0% error with a single feature! (+1 pseudo-feature to avoid them all getting normalized to 1)As you can see on my image above, the two clusters look like linear functions with the same slope, 2. The single feature I used is the y-intercept of the line with slope 2 passing through the point, and then I added sqrt(1-x^2) as another feature to avoid normalization.For my classification circuit I used a single Y rotation, as it usually is done with a single qubit.It was amazing, usually training takes a few minutes but here it got under the specified tolerance in only a few epochs and short-circuited as it got the perfect solution easily, beautiful.
•  » » » » » 4 months ago, # ^ |   0 Another method that produced 0% error is treating the y-intercept as an angle, scaling it so that the total range is pi, and supplying the sine and cosine as features.The preprocessed data looks almost the same in both cases because x and sin(x) act similarly near zero.
•  » » » » » 4 months ago, # ^ |   0 Were you also able to do similar preprocessing for D1 to make the data linearly separable?
•  » » » » » » 4 months ago, # ^ |   0 D1 and D2 don't need any preprocessing, in fact the format for submitting the solution doesn't allow preprocessing in the first place.
•  » » » » » » » 4 months ago, # ^ |   0 I tried using the same model as half-moons but the accuracy is pretty bad. Should I try experimenting with the structure?
•  » » » » » » » » 4 months ago, # ^ |   0 Yes, you should change the structure.The model from https://github.com/microsoft/MLADS2020-QuantumClassification works wonderfully, and indeed it is the only model that makes sense for data in a single qubit.
•  » » » » » » » » » 4 months ago, # ^ |   0 Will try. Thanks!
•  » » » » » » » » » 4 months ago, # ^ |   0 This worked surprisingly well. I'm curious why, Is there any intuition as to why a single PauliY gate works while multiple PauliX/Z gates don't? I'm unable to visualise how the transformation takes place by looking at the data plot.
•  » » » » » » » » » 4 months ago, # ^ | ← Rev. 2 →   +3 Well the PauliY rotation gate is straightforwardly just a rotation between 0 and 1, while the others include some sort of phase shift that doesn't really interest us in the single qubit case but could be useful with multiple qubits.
•  » » » 4 months ago, # ^ |   0 Hey can You tell me how did you actually preprocessed the data? Particularly centered everything around origin?
•  » » » » 4 months ago, # ^ | ← Rev. 2 →   0 Centering around the origin was the easiest part, I just eyeballed the center of the spirals to be around (0.25, 0.5) or something, don't remember exactly, and subtracted that from the points.Then I converted the points to polar coordinates, but since angles wrap around at 2 pi they didn't look like the straight lines in the plot. To fix that I just ad-hoc'd it, saying "if it's in the bottom right corner add 2pi, if it's in the top left corner subtract 2pi" and that gave me those nice lines.At this point the data set is linearly separable so you could probably feed it into a 2-qubit machine learning circuit and it could figure it out on its own, but I went even further:I eyeballed the slope of the lines to be about 2, calculated the y-intercept of the line with slope 2 that each point belongs to, encoded that as the angle of the single input point, and from there getting a circuit that classifies them was trivial.
•  » » » 4 months ago, # ^ | ← Rev. 3 →   +8 After working with the QML API in the warmup round and looking at the implementation a bit, I thought maybe I should make my own learner. Sampling probabilities and no backpropagation is just too damn slow. Hennkka had the same idea independently and we worked on it together last week. (Before the contest of course!) The project is on GitHub.With that I was able to get perfect or near perfect classifications on halfmoons:IIRC it was a bit better if the data was centered first, but there's no cheaty preprocessing here. Features in the above model are encoded into two qubits as [x, y, |x|^2+|y|^2, 0.8]. The major change is that we changed the cost function to a higher power instead of mean-squares. It helped lessen the misses, but of course in proper ML that doesn't make too much sense. (no separate training and testing datasets to verify it helps, generalization is far more important than absolute misses, etc). But it did work pretty well with the strictly defined areas that the contest tasks had.With it the QML tasks of the contest were a breeze (except for the qubit endianness being wrong). Kinda defeats the purpose, but hey, I had never made a gradient descent learner before. I also found a couple flaws in Microsoft's implementation of things, I'll leave issues there at some point.
 » 4 months ago, # |   0 So I was doing the winter round problems and they involve using Most function on qubits before applying the ApplyForEach function in the Unitary Transformation Problems. But running on my system gives that Most is not defined. What's going wrong?
•  » » 4 months ago, # ^ |   0 i think that you need to open Microsoft.Quantum.Arrays to use most
•  » » 4 months ago, # ^ |   0 you need to import the proper package, some things were moved around since the last contest https://docs.microsoft.com/en-us/qsharp/api/
 » 4 months ago, # |   0 In B why we cannot use an extra qubit. Because if I use and use Reset to reset it there is compilation error.
•  » » 4 months ago, # ^ |   0 You're not allowed to use measurements.Reset is a measurement.I recommend that you solve the previous two warmups first, you can read their editorials for help.
 » 4 months ago, # |   0 Struggling to understand quantum controlling.MultiQubitGates tutorial: (remember that the controlled operation should not modify the state of the control qubits) Quantum reality: qubits a, b H(a) CNOT(a, b) H(a) M(a) results in 50% 0 or 1, while without the CNOT, results in 100% 0.
•  » » 4 months ago, # ^ |   0 Quantum operations don't commute, two Hs can't annihilate across the CNOT.Also, that tutorial is telling you lies, all gates affect all qubits.
•  » » » 4 months ago, # ^ |   0 the tutorial means to say that a control qubit should not be also used as a target qubit
•  » » » » 4 months ago, # ^ |   0 I see, that would make sense, but it's a bad way to express it.
•  » » 4 months ago, # ^ |   0 It's a somewhat tricky idea to express: if you're using controlled gates on the basis states, the state of controls doesn't change; this is what allows to uncompute the changes done to the control qubits. But if you use them on the states with control qubits in superposition, there is going to be all kinds of interesting behaviors, including the one you mentioned.Thank you for pointing this out, I'll need to think how to express this better...
•  » » 4 months ago, # ^ |   0 I'm also misunderstanding this concept and it's causing my solution to task 2.2 from the Measurements Katas (man, the difficulty really ramps up at this stage ... ) to not work.Any explanation from Nickolas or someone else would be appreciated (I'm afraid I don't understand your comment).
•  » » » 4 months ago, # ^ | ← Rev. 2 →   0 Could you please clarify what explanation you'd like? Task 2.2 from the Measurements kata doesn't actually use controlled gates :-)
•  » » » » 4 months ago, # ^ |   +8 I think I understand this better now ... I got the following advice from Monogon on discord:And in this case, in your example hellman_ we are first applying $H \otimes I$ to the system, then CNOT, then $H \otimes I$ again. We get that the system is in the state$\frac12 \left( |00\rangle + |01\rangle + |10\rangle - |11\rangle \right)$which explains why we get the 50% 0, 50% 1 behaviour.I think a note word of warning in the katas would be super helpful for this, since in my opinion the Q# syntax is hiding the fact that H(a) is actually $H \otimes I$, not just $H$ applied to an isolated qubit (there are no isolated qubits, due to entanglement).
•  » » » » » 4 months ago, # ^ |   +8 I would just like to add that the classical descriptions of the gates are helpful, but you should try your best not to rely on them too heavily. Entanglement defies intuition.
•  » » » » » » 4 months ago, # ^ | ← Rev. 8 →   0 One way to somewhat regain the intuition is (correct me if I'm wrong) that if you think of the CNOT as "measuring" the superposed bit (but not revealing it to us, so the superposed/entangled bit still has the same relative probabilities), the resulting probability amplitudes would end up the same. That's why placing an H gate after it will still generate a 50-50 chance, unlike what happens when two H gates are placed in a row.This is the fundamental "measurement problem" of quantum mechanics. There doesn't seem to be a fundamental difference physically between "if this qubit is $|1\rangle$, flip the other qubit", and "if this qubit is $|1\rangle$, display "1" on the computer screen", except that the latter entangles the state of a nano-physical object with a macro-physical object. However, once we look at the computer screen, we don't observe the superposition or entanglements anymore, but it instead appears to "collapse" into a single coherent "classical" reality. Interpretations of this phenomenon is where hard physical science ends and philosophy begins, and takes many forms.Indeed, it may be that measurement/collapse is an inherently subjectivist/relativist concept, since even though from our perspective we may consider the computer superposed/entangled until we look at it, for the purposes of quantum computing, collapse happens at the M() command, since once we entangle qubits with classical bits, we obviously can't manipulate the latter with quantum computing operations anymore. This is what is called quantum decoherence; once information from the quantum system "leaks" into the surrounding environment, from one interpretation/perspective, collapse has occurred, from another interpretation/perspective, the system is entangled with the state of the environment, but either way, the superpositions no longer work as before within the quantum system. Making sure this doesn't happen non-deliberately is one of the chief challenges of building a real quantum computing system.
•  » » » » » » » 4 months ago, # ^ |   0 Okay so this made me feel like https://codeforces.com/blog/entry/77614?#comment-626409 ... except it was you Spheniscine who posted that to begin with!
 » 4 months ago, # |   0 Would anyone know how to get the Kronecker product of 2 gates? I can't seem to find details in the documentation.
•  » » 4 months ago, # ^ | ← Rev. 3 →   +3 Just apply them to different qubits one after another.
 » 4 months ago, # |   0 This post may contain some spoilers for B1 and/or B2. Question about the correct approach to B1/B2I had some trouble solving B1/B2. I couldn't think of an easy linear approach, so eventually I settled on the "quadratic" approach, where I use O(N) controlled X gates with O(N) controls each. Because I used a variable-sized set of controls, the compiler wouldn't automatically generate an adjoint for me, and I had to write it myself. Of course, I had to do this anyway, because it's the other of the two problems, but it seems against the intent of the problem, since it specifically advises you that the adjoint will be automatically generated.After using this solution (it gets AC) I googled for a better approach. The only things I found seemed very complex, and not the sort of thing I would come up with in a contest setting. (More difficult than any of the other Q# problems on this site I've tackled.)Is my approach correct/intended? Is there an easier approach I missed? Is the correct solution just very difficult to come up with from scratch?
•  » » 4 months ago, # ^ |   0 The simplest possible solution is using Controlled recursion, you can do it in 2 lines of code and the compiler can generate an Adjoint automatically without problem.
•  » » » 4 months ago, # ^ |   0 Interesting. I hadn't considered recursion in Q#. I'll take a look at your submission to the problem when the contest ends.
•  » » 4 months ago, # ^ |   0 There is a rather simple approach using O(N) CCNOT,CNOT gates and N ancilla qubits. Just note that your controls are very structured.
•  » » » 4 months ago, # ^ |   0 Ah, right, I failed to mention this in my post but that's another approach I had considered. Since simulating N additional qubits incurs a factor 2^N (ish) overhead to fully simulate (or does it?) I was worried that it would likely cause my code to timeout.
•  » » » » 4 months ago, # ^ |   +16 In gemeral, for a full state simulation additional qubits indeed increase the memory used by the program and the time to simulate each gate, but the effects are not going to be particularly noticeable until ~20 qubits (I timed larger programs in this blog post). In this contest in B problems we (actually msoeken :-)) used a variation of Toffoli simulator that takes linear memory to process extra qubits but do not support arbitrary rotations. So simulating extra N qubits shouldn't push your solution above the time limit, though I'll admit I haven't tried that.
•  » » 4 months ago, # ^ |   0 Your approach is correct and intended, but it can be implemented a lot easier. The compiler couldn't generate an adjoint automatically only because you used a mutable variable to store your control qubits, which is not really necessary. If instead you express the controls in terms of index i and a subarray of reg (array slicing is very useful for this), the code becomes something like 3 lines — and no manual Adjoint definition.
•  » » » 4 months ago, # ^ |   0 Ah, thanks, this is good to know. I often run into more problems with the non-quantum part of Q# than the actual QC knowledge.
•  » » » » 4 months ago, # ^ |   0 That is understandable, as I can only imagine that the Q# compiler is very weird and different from normal compilers. I remember that 2 years ago for the first contest, the language was even weirder and harder to understand, and the compiler had lots of bugs like not parsing doubles correctly. I had to write 2.5 as 25. / 10., those were fun times.
•  » » 4 months ago, # ^ |   0 Apparently ApplyToEach can't be used within Adj+Ctl unitary functions, but regular for-loops can.
•  » » » 4 months ago, # ^ |   +13 ApplyToEachCA
 » 4 months ago, # |   +15 dotnet run for an empty program takes 16 seconds on my machine. Is that expected? Is there a way to make it go faster?
 » 4 months ago, # |   0 Are there plans for continuing this competition in 2021?
•  » » 4 months ago, # ^ |   +26 We're not even done with the warmup round 2020 yet :-)
•  » » 4 months ago, # ^ |   0 What 2021?
 » 4 months ago, # |   0 how will we preprocess data in the main round because we just submit the parameters and the structure
•  » » 4 months ago, # ^ |   +8
•  » » » 4 months ago, # ^ |   0 could you give the list of functions for practice
 » 4 months ago, # |   +8 Any QML questions for practice... I finished D1,D2 and the half moons with 100% acuracy
•  » » 4 months ago, # ^ |   0 There are two datasets (Wine and Iris) in the MachineLearning package and there is a sample for training on Wine.
•  » » » 4 months ago, # ^ |   0 The Wine example takes several hours to train...
•  » » 4 months ago, # ^ |   0 Can you please give me some insight on how you got Half Moon to reach so high? I am unable to get even a mildly satisfactory result. Also, does the default set of programs (official sample for HalfMooon) take forever to run for you?
•  » » » 4 months ago, # ^ |   0 vilim_l helped preprocess the data in to linearly seprable classes. see comment above if you need more help just drop a message to me
 » 4 months ago, # |   +8 Preprocessing data in Q# seems like a lot of work. Would it not be better to preprocesss it in the host program? This way, you could ask us to submit one Python/C# program that contains a function with some signature to return the data that would go into the model as defined by the Q# code, like in the examples now.
•  » » 4 months ago, # ^ |   +17 This approach would convert this competition into "do the training classically and encode the labels in the output data", which would defeat the purpose of exploring quantum machine learning capabilities :-)
•  » » » 4 months ago, # ^ |   +16 Oh right, didn't see that loophole there. xD
•  » » » 4 months ago, # ^ |   +5 Isn't it like it now? I "trained" the circuit basically by hand..
•  » » » » 4 months ago, # ^ |   0 For the case of a single qubit, the only possible way to do anything is "classically encode your feature as an angle and then let the QML algorithm find the boundary between the angles of each label with a single Y rotation", but with higher-dimensional datasets it should be possible to do something interesting. Hopefully.
 » 4 months ago, # | ← Rev. 2 →   0 I am facing this problem after installation. Any solution? I tried installing 2-3 times ~~~~~ Preparing Q# environment... fail: Microsoft.Quantum.IQSharp.Workspace[0] QS6104: No namespace with the name "Microsoft.Quantum.MachineLearning" exists. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS6005: No type with the name "ControlledRotation" exists in any of the open namespaces. fail: Microsoft.Quantum.IQSharp.Workspace[0] QS6005: No type with the name "SamplingSchedule" exists in any of the open namespaces. ~~~~~
•  » » 4 months ago, # ^ |   0 https://codeforces.com/blog/entry/77614?#comment-641668That should solve your issue, you have to downgrade your IQSharp version for the quickest fix.
•  » » 4 months ago, # ^ |   0 You need to check that the correct version of the ML library is imported. If you installed or updated your QDK in the past few days, it should be 0.11.2006.403, but the examples by default import 0.11.2004.2825.
 » 4 months ago, # | ← Rev. 2 →   0 I'm trying to test my code for A1 locally using Jupyter Notebooks but I can't seem to run the Solve() function. It gives me the error Got an argument of type Qubit, expecting one of type (Qubit => Unit is Adj + Ctl) instead..What is type (Qubit => Unit is Adj + Ctl)? As far as I understood, it is a callable that supports both controlled and adjoint. Can I do something like Solve(X(q)) or Solve(X) ?
•  » » 4 months ago, # ^ |   0 Qubit => Unit means a function that takes a Qubit as argument and returns Unit (essentially a void function, if you're used to C/C++/Java). The signature suggests that it operates on qubits, and the "output" is given by the state in which it leaves the qubit. The Adj + Ctl means that the operation has an adjoint and a controlled version available, which is true of (for instance) X. So indeed Solve(X); is a correct line of code if Solve has the signature you describe.
•  » » » 4 months ago, # ^ |   0 Thanks for explaining what it means. But when I run the following code for example, Codeopen Microsoft.Quantum.Diagnostics; open Microsoft.Quantum.Measurement; operation DoTask (): Unit { Solve(X); } I get C:/snippet_.qs(7,5): error QS5011: Expecting expression of type Unit. Only expressions of type Unit can be used as expression statements. Solve()open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Diagnostics; operation Solve (unitary : (Qubit => Unit is Adj+Ctl)) : Int { using (q = Qubit()){ //DumpMachine(); unitary(q); let ans = M(q); Reset(q); if(ans == Zero){ return 0; } else{ return 1; } } }
•  » » » » 4 months ago, # ^ |   0 Solve returns a value, and you need to somehow use it — assign to a variable or print in a Message.
•  » » » » » 4 months ago, # ^ |   0 Ahh.. ofcourse. Thank you!
 » 4 months ago, # |   0 This post contains spoilers for D1. SpoilerI'm stuck on getting the machine learning problems to work. From the correct submissions (and the comments on this post, before that) I realize the correct solution to D1 is to have a single PauliY gate, controlled on nothing, with a parameter of pi (and possibly some bias).If I try to run the example code from this website (in particular with the Python host file), and the only change I make is that I split the json file into training and validation data (because the code assumes that the json file contains both) then after running for a long time it just... reports the initial parameters it started with, with a gigantic miss rate (near 50%).If I change the ClassifierStructure function into the following:  function ClassifierStructure() : ControlledRotation[] { return [ ControlledRotation((0, new Int[0]), PauliY, 0) ]; } and I hardcode the correct value for the rotation in the Python file:  parameter_starting_points = [ [3.1415] ] it runs much quicker, but it does not change the parameter at all, yet it reports, again, a nearly 50% miss rate.Additionally, sometimes when I run host.py I get a whole bunch of errors of the form fail: Microsoft.Quantum.IQSharp.Workspace[0] QS5022: No identifier with the name "ControlledRotation" exists.But whether or not I get these errors seems somewhat non-deterministic: it doesn't happen every time.What is going on?
•  » » 4 months ago, # ^ |   +8 I haven't tried running this data with the website code; if you run it with the code from https://github.com/microsoft/MLADS2020-QuantumClassification, which is what I did, it will learn. To improve the learning speed and push the model away from the starting parameters, I had to increase LearningRate parameter and reduce Tolerance (https://github.com/microsoft/MLADS2020-QuantumClassification/blob/master/QuantumClassification/Backend.qs#L44).
•  » » » 4 months ago, # ^ |   0 Ah, thank you. That seems to have worked. That gives me some confidence in the contest next weekend.
•  » » » » 4 months ago, # ^ |   0 It is similar to classical ML — you have to experiment with model structure and hyperparameters to figure out what works best for the exact problem you're solving.
•  » » » » » 4 months ago, # ^ |   0 Sure, but if I were programming in PyTorch and my parameters weren't updating I would know how to get the gradient I am using for the update and print some statistics (max, min, mean, variance) to see if the hyperparameters are the problem or there is just a bug in my code (or something wrong with my installation of the backend). Q# is still a little arcane to me.
•  » » » » » 4 months ago, # ^ |   0 How do I find out what hyperparameters are available to me, and what they mean (i.e. what their definition is)? It is not meaningfully specified here or here.
•  » » » » » » 4 months ago, # ^ |   +8 There is an issue with the docs generation pipeline which causes user-defined types lose most of their documentation :-( You can find the comments in the source here.
•  » » » » » » » 4 months ago, # ^ |   0 Thanks!
 » 4 months ago, # |   +10 Is Q# compilation supposed to be very slow?I run it as in this tutorial by creating a project in VS Code and running "dotnet run" in the console. It takes about 15 seconds to compile a basic program.
 » 4 months ago, # |   0 Question about allowed operationsProblem 'C' (of Warmup) states: you are not allowed to use any gates except the Pauli gates (X, Y and Z), the Hadamard gate and the controlled versions of those so I expected I am allowed to use X, Y, Z, H, CX=CNOT, CY, CZ, CH, but not anything else, most importantly, CCNOT, which I thought I need to implement myself. Meanwhile, the solution with CCNOT worked: https://codeforces.com/contest/1356/submission/83551196Can you please clarify if this is a mistake of testing or if I misunderstand something?
•  » » 4 months ago, # ^ |   0 CCNOT is a controlled version of X — just with several controls. So you can do CCCNOT etc. I'll clarify this for the main round, thank you for pointing this out!
•  » » » 4 months ago, # ^ |   0 Thanks for clarification! I thought implementing CCNOT from 1-2 qubit operations was part of the challenge. Now I see people use CCNOT or even 'Controlled' keywork.I took a look at last year's solutions to see what exactly was banned for this year (preparing state directly with Ry, without any measurements or loops).
 » 4 months ago, # | ← Rev. 2 →   0 So last year's Winter problems have used ancilla qubits in implementing oracles. However as was mentioned previously we cannot use Reset/ResetAll in operations that need to be auto adjoint. So the solutions don't reset at all and it works. Why is this so? Does the Q# compiler auto reset them? (It seems that one needs to Reset using adjoint self. I still find it weird though. Also the solutions haven't used reset but the same code on my pc requires me to reset. Weird)
•  » » 4 months ago, # ^ |   0 I am not sure I understand your question, but the testing code allocates the qubits for you, passes this qubits as parameters to your code and at the end resets the allocated qubits.But if you allocate qubits yourself (for testing or for some problems) then your need to reset those specific qubits.
•  » » 4 months ago, # ^ |   +10 There are two ways to return the qubits to 0 state after you're done with them. Reset is a shorthand for "measure, and if measurement result is 1, apply an X gate" — this way collapses superposition, if the qubit was not in a basis state |0⟩ or |1⟩. This is good if the qubit is not entangled with the other qubits and you don't care what happens to it. For example, if you used an extra qubit in the |-⟩ state to implement phase kickback trick, it's not going to be entangled with the rest of your qubits, and you can just measure it — that measurement will not affect the rest of the system.But quite often your ancilla qubits will be entangled with the rest of the system, and then you cannot measure them, because this will collapse not just the state of the ancilla, but also the state of the rest of the system. Here is the simplest example: if you have the main qubit and the ancilla qubit in a state (|00⟩ + |11⟩), and you wanted to prepare the main qubit in the |0⟩+|1⟩ state, you cannot just measure the ancilla to get rid of it, since that will collapse the full system to |00⟩ or |11⟩, affecting the state of the main qubit as well. In this case you need to return the extra qubits to |0⟩ state coherently, using uncomputation — and that's what you'll want to do when implementing oracles.
•  » » » 4 months ago, # ^ |   0 I think I now get why the language forces you to manually reset qubits with runtime exceptions. Just to be sure: is my understanding correct that there will be no runtime checks on real quantum hardware? (since there is no way to check it without doing measurements and collapsing states) It will just give you weird results.
•  » » » » 4 months ago, # ^ | ← Rev. 2 →   +5 Yes, on real quantum hardware the runtime software won't be able to track the full state of the system, so you're on your own :-) That's part of the reason why we want to enforce this on the simulator — if you're writing your code for hardware, you'll be better off troubleshooting this kind of issues on small instances of the problem in simulation before you run it on hardware and spend a lot of time figuring out why your results don't make sense :-)
 » 4 months ago, # |   0 How do you implement -Z operation from A5? (for testing)I used: X(q); Z(q); X(q); It seems like there should be some build-in gate to do negation directly, but I couldn't find any.
•  » » 4 months ago, # ^ |   0 You can do a gate which applies a global phase using R gate with PauliI argument. But for the global phase of -1 XZXZ might be the more intuitive way.
•  » » » 4 months ago, # ^ |   0 Thanks. Thought, there would be something simple like 'Negate', although not sure if it's used often.
 » 4 months ago, # |   +8 How do you test your code?I create operations for testing and comment out the line with @EntryPoint() just before submitting the solution. Sample solution. I see many participants don't have any testing code in their submissions.How do they test then?
•  » » 4 months ago, # ^ |   +5 I write my code in a jupyter notebook, with testing code next to it. Once I want to submit I copy the code to a new text file and submit that. This workflow is terrible and I wouldn't recommend it to anyone. :^)
•  » » » 4 months ago, # ^ |   0 I like Jupyter Notebooks for Python ML work. I didn't know there is an extension for Q#.How does it work? Code completion is probably very bad (it's bad even for Python).Is it fast? Basic scripts take 15 seconds to compile with 'dotnet run' and I am not sure it is supposed to take that long.
•  » » » » 4 months ago, # ^ | ← Rev. 3 →   0 In my current solutions file, these are the first three cells: Jupyter notebook contents// A1 open Microsoft.Quantum.Intrinsic; operation SolveA1 (unitary : (Qubit => Unit is Adj+Ctl)) : Int { using(q = Qubit()) { unitary(q); mutable result = 1; if(M(q) == Zero) { set result = 0; } Reset(q); return result; } }  open Microsoft.Quantum.Diagnostics; open Microsoft.Quantum.Measurement; operation SolveTestA1 () : Unit { let i = SolveA1(I); Message($"I={i}"); let x = SolveA1(X); Message($"X={x}"); }  %simulate SolveTestA1 Running all three of these cells takes about 3 seconds.To hand in the code, I copy the content of the first cell into a text file, add the correct namespace, and change the name from SolveA1 to Solve.
•  » » 4 months ago, # ^ |   +13 I create an additional operation called test, and then call it using python. No need for commenting.To use this method you need to install the dependencies listed here: https://docs.microsoft.com/en-us/quantum/install-guide/pyinstallSample solution: 83561027Sample python script: import qsharp from Solution import test test.simulate() 
•  » » » 4 months ago, # ^ |   +8 I'll check Python host. Is it fast? Basic scripts take 15 seconds to compile with 'dotnet run' and I am not sure it is supposed to take that long.You have a cool minimalistic solution for problem 'C' by the way:)
•  » » » » 4 months ago, # ^ |   0 For me it takes 9 seconds if I need to build the file and 3 seconds otherwise. My computer has 8 2.3GHz i9 cores.And I'm glad you liked my solution to C.
 » 4 months ago, # |   0 Could this be a reason for a runtime error?Controlled X([Qi], Qj)//some more statementsand then doing Controlled X([Qj], Qi)
•  » » 4 months ago, # ^ |   0 No
•  » » 4 months ago, # ^ |   0 Yes, actually. If this is in a task, where the qubits have to be reset to the zero state, then this probably won't put them in a zero state. I would need to see the task and the rest of the code for more information. Maybe doing Controlled X([Qi], Qj) in the end instead would solve the error.
•  » » » 4 months ago, # ^ |   0 The code is for task B1 increment https://codeforces.com/contest/1356/submission/83904158 I used N extra qubits to store whether a carry needs to be added or not, but I get a runtime error, I am unsure what caused it but I believe using a CNOT with controls and targets switched/overlapped after an earlier CNOT caused it.
•  » » » » 4 months ago, # ^ | ← Rev. 2 →   0 I think you got the right intuition. I can see two reasons for why the ancillas are not uncomputed/reset properly: 1. The state of register is different in the end, so you apply different operations to the ancillas. 2. You need to do the uncomputations in REVERSE order. So for (i in (l - 2) .. -1 .. 0) etc.But you can also solve the problem without ancillas, and I see you also have also submitted such a solution.
•  » » » » » 4 months ago, # ^ |   0 Thanks! Got it finally https://codeforces.com/contest/1356/submission/84058945. Yes, but I could think of recursive solution only after seeing the editorial.
•  » » » 4 months ago, # ^ |   0 in general it would'nt matter as long as he didnt change state of either qubit