Help me deploy Azure quantum service as a python program.

Alok GV 0 Reputation points

Hey, I have been following the instructions provided in the link below.

my python code :

import qsharp

import azure.quantum

workspace = azure.quantum.Workspace(

resource_id = "myActualId",

location = "location"


qsharp.init(project_root = '/myrootfolder')


MyProgram = qsharp.compile("Sample.RandomNBits(4)")

MyTarget = workspace.get_targets("rigetti.sim.qvm")

job = MyTarget.submit(MyProgram, "MyPythonJob", shots=10)

results = job.get_results()

print("\nResults: ", results)

My source.qs file:

namespace Sample {

operation Random() : Result {

use q = Qubit();


let result = M(q);


return result


operation RandomNBits(N: Int): Result[] {

mutable results = [];

for i in 0 .. N - 1 {

let r = Random();

set results += [r];


return results



I'm Getting the following error :

ll_str = get_interpreter().qir(entry_expr)

module.QSharpError: Qsc.Resolve.NotFound

× name error

╰─▶ RandomNBits not found


1 │ Sample.RandomNBits(4)

· ───────────



× type error

╰─▶ insufficient type information to infer type


1 │ Sample.RandomNBits(4)

· ─────────────────────


help: provide a type annotation Thanks for your help in advance ,

Azure Quantum
Azure Quantum
An Azure service that provides quantum computing and optimization solutions.
62 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Prrudram-MSFT 22,921 Reputation points

    Hello @Alok GV

    Thank you for reaching out to the Microsoft Q&A platform.

    There is a typo in the example for that article. If you have followed the steps as written and the python file is in the /src folder, you would need to set the project to qsharp.init(project_root = '../../myrootfolder'). Azure quntum product team is working to clarify the steps in that article and republish it.

    If I have answered your query, please click "Accept as answer" as a token of appreciation

    0 comments No comments