I would like to make a resource estimate based on Azure resource estimator.
However, the circuits I am interested in depend on some classical parameters: for this reason, I would like to make a modular script with sub-portions of the quantum circuits in separated parts.
I tried to do the following code (which does not work).
import qsharp.azure
targets = qsharp.azure.connect(
resourceId = "/subscriptions/MYSUBSCRIPTION",
location = "westeurope")
qsharp.azure.target("microsoft.estimator")
qsharp.azure.target("microsoft.estimator")
%%qsharp
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Arrays;
operation subCircuit(q: Qubit[], x: Array[], n: Int) {
for index in 0 .. n
{
H(q[index]); // Apply Hadamard on qubit "index"
Rx(2.0*x[index],q[index]); // After the Hadamard, apply a Rx rotation on the qubit "index" of angle 2.0*x[index]
}
}
operation AlgoTest() : Result[] {
let n=3; // Number of qubits
let x=[0.,1.,2.]; // Vector x
mutable resultArray = [Zero, size = 3];
use q = Qubit[n];
subCircuit(q,x,n);
for i in IndexRange(q) {
set resultArray w/= i <- M(q[i]);
}
return resultArray;
}
result = qsharp.azure.execute(AlgoTest)
My questions:
As you see, I wanted to separate a sub-portion of my example algorithm subCircuit
inside another function AlgoTest
. However, the script returns several errors.
I know that I am probably not using good syntax, in particular, to define operation subCircuit, but this is precisely why I am asking this question. I looked at the documentation of operations and functions but the explanations are very obscure. Having an example of a working script doing what I want would be helpful for me to understand the syntax.
The errors returned are below (but overall I am not surprized there are errors because I am not using the good syntax, my question is precisely to understand which syntax is expected by the program, which is not very clear from the documentations -- perhaps I am not looking at the good place --):
fail: Microsoft.Quantum.IQSharp.Snippets[0] QS3212 (/snippet_.qs:Microsoft.VisualStudio.LanguageServer.Protocol.Range): Expecting return type annotation. The argument tuple needs to be followed by a colon and the return type of the callable. fail: Microsoft.Quantum.IQSharp.Snippets[0] QS3035 (/snippet_.qs:Microsoft.VisualStudio.LanguageServer.Protocol.Range): Unexpected code fragment. fail: Microsoft.Quantum.IQSharp.Snippets[0] QS3036 (/snippet_.qs:Microsoft.VisualStudio.LanguageServer.Protocol.Range): An expression used as a statement must be a call expression. fail: Microsoft.Quantum.IQSharp.Snippets[0] QS6005 (/snippet_.qs:Microsoft.VisualStudio.LanguageServer.Protocol.Range): No type with the name "Array" exists in any of the open namespaces. /snippet_.qs(7,53): error QS3212: Expecting return type annotation. The argument tuple needs to be followed by a colon and the return type of the callable. /snippet_.qs(28,8): error QS3035: Unexpected code fragment. /snippet_.qs(28,1): error QS3036: An expression used as a statement must be a call expression. /snippet_.qs(7,37): error QS6005: No type with the name "Array" exists in any of the open namespaces.