Tag: Q#

Yesterday I wrote that one of the most important news of the last Update of the Microsoft Quantum Development Kit was the support for Mac and Linux. Well, this is achieved because the basis of Q# is the interaction of a host in .Net Core 2.0 and the connection to the Quantum Simulator.
This allows us to work with Microsoft Quantum DevKit using any language that supports .Net. Where C # and F # may be the most popular. And it is on this basis that we can also use Microsoft Quantum DevKit in other platforms, using Visual Studio Code as a development tool

.

From Visual Studio Marketplace we can download an extension for VSCode that allows us to create projects in Microsoft Quantum DevKit. As expected we can also debug, write our Q # code and more with VSCode.

The installation is very simple. We start installing the extension for VSCode

February has been a month of events and sessions; March will be a month more dedicated to study and to build a couple of interesting projects. One of the issues that I have to take up again is Quantum Computing . I’ve already written some posts about it,
and today I find a new version of the Microsoft Quantum Development Kit.

The official article explains the improvements in detail. I will only highlight those that seem most interesting to me

Development in Mac, Linux and Windows environments. As it comes naturally in the Microsoft tools, they are not only contained and run in Windows, Linux and Mac are also supported. (And this is an excellent opportunity to put me once and for all with the Mac)

Python support. Yes, it seems that Python will be in new JavaScript, it is everywhere and how could it be otherwise, Microsoft Quantum Development Kit, also supports Python.

To complete the points I should mention the performance improvements of the simulator and that the DevKit is OpenSource. I guess I’ll have time to write about this in the near future.

When we create a new Q# (extension. qs) file, this new file has a main namespace (usualy our project name) and then it includes a series of namespaces that will be used in our operations. Something similar to this image

The Q# file operation template includes 2 main namespaces to be used

open Microsoft.Quantum.Primitive;

This namespace provides access to basic operations such as the Hadamard gates, X, M, CNOT gates, and more. The implementation of these operations depends on the target machine. This is important because we will have to take into account the process in a simulator or X Quantum Computer.

open Microsoft.Quantum.Canon;

This namespace contains many useful functions for creating larger circuits, combinatorial and generic utilities. The implementation of the operations in the Canon is independent of the target machine, since they are built at the top of the primitive operations.

Yesterday I wrote on the MResetZ() which allows us to get the status of a Qubit and release it. Well, at the end of each Q# operation, all the used Qubits need to be released for the simulator to work properly.

The following sample code will show a bad sample where a Qubit is used and not released correctly:

Microsoft Quantum Development Kit offers us a series of operations that help us to release Qubits: Reset() and ResetAll(). As its name indicates Reset() is intended to release a single Qubit and ResetAll() to release an array of Qubits.

Given a single Qubit, Reset() evaluates the Qubit state and ensures that the Qubit is in the state |0⟩ so it can be safely released.

The following 2 operations show examples of how to use these operations

After an intense week of events, this week it’s my turn to go back to the Quantum Computing studio. In this particular case, to a detail that we have to keep in mind when we work with Q #

When a qubit is in an eigenstate of the measurement operator, i.e., either in |0> or in |1>, we need to reset the Qubit before the end of an operation. Qubits need to be in |0> when they are released, so we have to manually reset the qubit before releasing it using the Z() operation if needed.

Well, let’s take as a basis one in which we initialize a Qubit and apply an operation Hadamard operation as shown in the following code

In line 10 I store the state of the Qubit in the return variable and then on lines 11 to 14 verify that the state of the same is Zero. If not, I need to reset the Qubit to Zero before the end of the operation on line 13.

Well, this code works, and that’s amazing! However when we use the Microsoft Quantum DevKit we also have an operation that allows us to obtain the status of a Qubit and release it in a single operation. This operation is MResetZ(). The same previous code using this operation it is much more nice to read

As we can see, the main change is in line 10 where I assign the state of the Qubit to the return variable and also reset the Qubit to Zero.

Finally, from a Console App I invoke both operations and the result is equal.