page_type | author | description | ms.author | ms.date | languages | products | |||||
---|---|---|---|---|---|---|---|---|---|---|---|
sample |
cgranade |
Generate random numbers in parallel on quantum hardware, using the Azure Quantum service |
chgranad@microsoft.com |
01/25/2021 |
|
|
This sample demonstrates how to use Q# and the Azure Quantum service together to build a quantum random number generator (QRNG). In particular, this sample uses a register of qubits rather than a single qubit to draw random numbers several bits at a time, avoiding the need for intermediate measurement.
This sample is implemented as a standalone executable, such that no C# or Python host is needed.
The program takes one command-line option, --n-qubits
, to control the number of qubits used to sample a random number.
This sample can be run in one of three different ways, depending on your preferred environment:
- Q# standalone at the command-line
- Q# standalone from Jupyter Notebook
- Q# from a Python host program
dotnet run -- --simulator QuantumSimulator --n-qubits=4
Make sure that you have created and selected a quantum workspace, and then run the following at the command line, substituting TARGET
with the target that you would like to run against (e.g.: ionq.qpu
or quantinuum.qpu.h1
):
az quantum execute --target-id TARGET -- --n-qubits=4
For a full list of available quantum computing targets, run:
az quantum target list --output table
Make sure that you have followed the Q# + Jupyter Notebook quickstart for the Quantum Development Kit, and then start a new Jupyter Notebook session from the folder containing this sample:
cd parallel-qrng
jupyter notebook
Once Jupyter starts, open the ParallelQrng.ipynb
notebook and follow the instructions there.
Make sure that you have followed the Q# + Python quickstart for the Quantum Development Kit, and then run Python from within the folder containing this sample.
The Python host program takes as command-line arguments the resource, location, and target IDs to submit your Azure Quantum service job to.
When running the command below, make sure to replace the example resource ID with the ID for your workspace, replace LOCATION
with the location for your workspace, and replace TARGET_ID
with the target that you would like to submit to (e.g.: ionq.simulator
). The information for resource ID, location, and available targets can be found in the Azure Portal.
cd parallel-qrng/python-host
python parallel_qrng.py /subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP_NAME/providers/Microsoft.Quantum/Workspaces/WORKSPACE_NAME LOCATION TARGET_ID
For a full list of available quantum computing targets, run:
az quantum target list --output table
⚠️ This sample makes use of paid services on Azure Quantum. The cost of running this sample with the provided parameters on IonQ in a Pay-As-You-Go subscription is approximately $1-$2 USD (or the equivalent amount in your local currency). This quantity is only an approximate estimate and should not be used as a binding reference. The cost of the service might vary depending on your region, demand and other factors.
- ParallelQrng.csproj: Main Q# project file for this sample.
- ParallelQrng.qs: Main Q# program for this sample.
- ParallelQrng.ipynb: IQ# notebook for this sample.
- parallel_qrng.py: Host program for running this sample from Python.