-
Notifications
You must be signed in to change notification settings - Fork 97
QIR
Quantum Intermediate Representation (QIR) is a program representation based on LLVM IR. The specification is developed by the QIR Alliance.
QIR specifies different profiles for different hardware capabilities. The Q# compiler can generate QIR that is compatible with the 'Base' profile, which is limited to programs that can be represented as a sequence of operations. The compiler can also generate QIR that is compatible with the adaptive profile. The 'Adaptive_RI' profile allows additional capabilities such as mid-circuit measurement, branching based on measurement results or performing classical integer computations at runtime, and gets its name from the adaptive profile and two extensions: qubit reset support and integer computation.
Q# code that runs in the local simulator is not limited to any subset of QIR described in a 'profile'. We refer to this as Unrestricted
. When developing Q# code, you can set the target profile via either the "Set the Azure Quantum QIR target profile" command (as shown below) or clicking on the editor status bar which will display the current target profile (either "QIR base", "Unrestricted" or "QIR Adaptive RI" if the experimental settings are enabled).
If the current program is not compatible with the selected target profile, you will get errors in the editor when targeting "QIR Base" or "QIR Adaptive RI". If the program is compatible, you can view the generated QIR via the "Get QIR for the current Q# program" menu item (also shown in the clipping above).
The following sections describe errors that can be encountered when compiling Q# with a specific profile, along with examples and possible mitigations. These errors come from the Runtime Capabilities Check pass that validates the capabilities used by the program are compatible with the capabilities of the configured target profile.
Code: Qsc.CapabilitiesCk.UseOfDynamicBool
This indicates the program is using Boolean values that depend on qubit measurement when the configured target profile does not support Boolean variables. This usually occurs when compiling against the 'Base' profile, which does not allow for any branching based on measurement results. For example, the following code uses a dynamic bool to apply a gate operation to a qubit:
use q = Qubit();
H(q);
if M(q) == One {
X(q);
}
The comparison of a measurement result to the literals One
, Zero
, or to another measurement result cannot be included in a program compiled for a target without support for Boolean variables.
Code: Qsc.CapabilitiesCk.UseOfDynamicInt
This indicates the program is using integer values that depend on qubit measurement when the configured target profile does not support integer variables. This can happen when compiling against target profiles that do not support the adaptive profile with the integer computation extension. For example, the following code calculates a dynamic integer:
mutable x = 0;
use qs = Qubit[3];
for q in qs {
H(q);
if M(q) == One {
set x += 1;
}
}
The use of integer computation that depends on measurement results cannot be included in a program compiled for a target that does not support integer variables and computation.
Code: Qsc.CapabilitiesCk.UseOfDynamicPauli
Code: Qsc.CapabilitiesCk.UseOfDynamicPauli
Code: Qsc.CapabilitiesCk.UseOfDynamicDouble
Code: Qsc.CapabilitiesCk.UseOfDynamicQubit
Code: Qsc.CapabilitiesCk.UseOfDynamicResult
Code: Qsc.CapabilitiesCk.UseOfDynamicTuple
Code: Qsc.CapabilitiesCk.UseOfDynamicBigInt
Code: Qsc.CapabilitiesCk.UseOfDynamicString
Code: Qsc.CapabilitiesCk.UseOfDynamicExponent
Code: Qsc.CapabilitiesCk.UseOfDynamicallSizedArray
Code: Qsc.CapabilitiesCk.UseOfDynamicUdt
Code: Qsc.CapabilitiesCk.UseOfDynamicArrowFunction
Code: Qsc.CapabilitiesCk.UseOfDynamicArrowOperation
Code: Qsc.CapabilitiesCk.CallToCyclicFunctionWithDynamicArg
Code: Qsc.CapabilitiesCk.CyclicOperationSpec
Code: `Qsc.CapabilitiesCk.CallToCyclicOperation
Code: Qsc.CapabilitiesCk.CallToDynamicCallee
Code: Qsc.CapabilitiesCk.MeasurementWithinDynamicScope
Code: Qsc.CapabilitiesCk.UseOfDynamicIndex
Code: `Qsc.CapabilitiesCk.ReturnWithinDynamicScope
Code: Qsc.CapabilitiesCk.LoopWithDynamicCondition
Code: Qsc.CapabilitiesCk.UseOfBoolOutput
Code: Qsc.CapabilitiesCk.UseOfDoubleOutput
Code: Qsc.CapabilitiesCk.UseOfIntOutput
Code: Qsc.CapabilitiesCk.UseOfAdvancedOutput