AllowAtMostNQubits operation

Namespace: Microsoft.Quantum.Diagnostics

Package: Microsoft.Quantum.Standard

Between a call to this operation and its adjoint, asserts that at most a given number of additional qubits are allocated with using statements.

operation AllowAtMostNQubits (nQubits : Int, message : String) : Unit is Adj

Input

nQubits : Int

The maximum number of qubits that may be allocated.

message : String

A message to be displayed upon failure.

Output : Unit

Example

The following snippet will fail when executed on machines which support this diagnostic:

within {
    AllowAtMostNQubits(3, "Too many qubits allocated.");
} apply {
    // Fails since this allocates four qubits.
    using (register = Qubit[4]) {
    }
}

Remarks

This operation may be replaced by a no-op on targets which do not support it.