Edit

Share via


Different types of target profiles in Azure Quantum

Quantum devices are still an emerging technology and unfortunately not all of them can run every Q# program. As such, you need to keep some restrictions in mind while you develop quantum programs. The target profile types define the capabilities of the quantum devices that you target with your Q# programs. The Quantum Development Kit (QDK) has a set of different target profile types, which together support all the capabilities of the current quantum devices that are available in Azure Quantum.

This article discusses the different types of target profiles in Azure Quantum, their limitations, and how to configure them in the QDK.

Target profiles and their limitations

Currently, Azure Quantum and the QDK manage different target profiles, depending on their ability to run quantum intermediate representation (QIR) programs.

  • Unrestricted: This profile can run any QIR program, and thus any Q# program, within the limits of memory for simulators or the number of qubits for physical quantum computers.
  • Base: This profile can run any Q# program that doesn't require the use of the results from qubit measurements to control the program flow. Within a Q# program that's targeted for this kind of QPU, values of type Result don't support equality comparison.
  • Adaptive RI: This profile has limited ability to use the results from qubit measurements to control the program flow. Within a Q# program that's targeted for this kind of QPU, you can compare values of type Result as part of conditions within if statements in operations, allowing mid-circuit measurement.
    • Adaptive RIF: This profile has the same capabilities as the Adaptive RI profile, but also supports floating point operations.

Create and run programs for Unrestricted target profile

Unrestricted target profiles can run all Q# program, so you can write Q# code without the need to consider functionality restrictions. Azure Quantum doesn't provide any actual device targets that support this profile. However, you can run Unrestricted Q# programs that have this profile on the simulators that are provided with the QDK.

Configure Unrestricted target profile

If you don't manually set your QIR target profile, then the compiler automatically sets the target profile for you. The compiler chooses the most restrictive profile that still allows your program to run on the Azure Quantum device target that you choose.

To manually set the QIR target profile to Unrestricted, choose one of the following options:

  • If you set up a Q# project, then add the following command to your project's qsharp.json file:

    {
      "targetProfile": "unrestricted"
    }
    
  • If you're working in a .qs file that isn't part of a Q# project, then set the target profile directly in your Q# code. To do so, include @EntryPoint(Unrestricted) right before the entrypoint operation in your program, even when that operation is the default Main.

  • In Python, call the qsharp.init method to set the target profile.

    qsharp.init(target_profile=qsharp.TargetProfile.Unrestricted) 
    

Create and run programs for Base target profile

Base target profiles can run a wide variety of Q# applications, with the constraint that they can't use results from qubit measurements to control the program flow. More specifically, values of type Result don't support equality comparison.

For example, you can't run the following FlipQubitOnZero operation on a Base target:

    @EntryPoint(Base)
    operation FlipQubitOnZero() : Unit {
        use q = Qubit();
        if M(q) == Zero {
            X(q);
        }
    }

The FlipQubitOnZero operation fails when you run this code on a Base target because the target device can't use the result of a qubit measurement to perform conditional logic while the quantum algorithm is running. If you plan to run algorithms on a Base target device, then make sure that your code doesn't contain any if blocks for conditional branching that rely on measured qubits to evaluate a logical condition.

Configure Base target profile

To manually set the QIR target profile to Base, choose one of the following options:

  • If you set up a Q# project, then add the following command to your project's qsharp.json file:

    {
      "targetProfile": "base"
    }
    
  • If you're working in a .qs file that isn't part of a Q# project, then set the target profile directly in your Q# code. To do so, include @EntryPoint(Base) right before the entrypoint operation in your program, even when that operation is the default Main.

  • In Python, call the qsharp.init method to set the target profile.

    qsharp.init(target_profile=qsharp.TargetProfile.Base) 
    

Supported targets for Base target profile

For now, Azure Quantum provides access to the following Base targets:

Provider Simulator QPU
IonQ ionq.simulator ionq.qpu.*
Rigetti rigetti.sim.* rigetti.qpu.*

To learn more about these providers in Azure Quantum, see IonQ provider and Rigetti provider.

Create and run programs for Adaptive RI target profile

Adaptive RI target profiles can run a wider variety of Q# applications than Base profiles, but still have some limitations. Unlike Base target profiles, Adaptive RI targets support mid-circuit measurements.

With mid-circuit measurements, you can selectively measure qubits at any point in the quantum program, not just the end. You can then use the measurement results for other operations in your program, like conditional branching with if blocks. The qubits that you measure mid-circuit collapse to a classical state (zero or one), but the non-measured qubits remain in their quantum state.

When you measure a qubit in Q#, a value of type Result is returned. If you want to use this result in a conditional statement, you have to directly compare in the conditional statement. The corresponding conditional blocks may not contain return or set statements.

For example, the following Q# code is allowed in a Adaptive RI target:

@EntryPoint(Adaptive_RI)
operation MeasureQubit(q : Qubit) : Result { 
    return M(q); 
}

operation SetToZero(q : Qubit) : Unit {
     if MeasureQubit(q) == One { X(q); }
}

Configure Adaptive RI target profile

To manually set the QIR target profile to Adaptive RI, choose one of the following options:

  • If you set up a Q# project, then add the following command to your project's qsharp.json file:

    {
      "targetProfile": "adaptive_ri"
    }
    
  • If you're working in a .qs file that isn't part of a Q# project, then set the target profile directly in your Q# code. To do so, include @EntryPoint(Adaptive_RI) right before the entrypoint operation in your program, even when that operation is the default Main.

  • In Python, call the qsharp.init method to set the target profile.

    qsharp.init(target_profile=qsharp.TargetProfile.Adaptive_RI) 
    

Supported targets for Adaptive RI target profile

For now, Quantinuum is the only provider in Azure Quantum that has Adaptive RI targets.

  • Emulators: quantinuum.sim.h2-1e and quantinuum.sim.h2-2e
  • QPUs: quantinuum.qpu.h2-1 and quantinuum.qpu.h2-2

For more information on Quantinuum's offerings in Azure Quantum, see Quantinuum Emulators.

Create and run programs for Adaptive RIF target profile

Adaptive RIF target profiles have all the capabilities of Adaptive RI profiles, but also support Q# programs that contain floating point calculations.

For example, the following Q# code is allowed in a Adaptive RIF target:

@EntryPoint(Adaptive_RIF)
operation DynamicFloat() : Double {
    use q = Qubit();
    H(q);
    mutable f = 0.0;
    if M(q) == One {
        f = 0.5;
    }
    Reset(q);
    return f;
}

Configure Adaptive RIF target profile

To manually set the QIR target profile to Adaptive RIF, choose one of the following options:

  • If you set up a Q# project, then add the following command to your project's qsharp.json file:

    {
      "targetProfile": "adaptive_rif"
    }
    
  • If you're working in a .qs file that isn't part of a Q# project, then set the target profile directly in your Q# code. To do so, include @EntryPoint(Adaptive_RIF) right before the entrypoint operation in your program, even when that operation is the default Main.

  • In Python, call the qsharp.init method to set the target profile.

    qsharp.init(target_profile=qsharp.TargetProfile.Adaptive_RIF) 
    

Supported targets for Adaptive RI target profile

For now, Azure Quantum doesn't have Adaptive RIF targets. However, you can run programs for Adaptive RIF targets on the local simulator in the QDK.