AssertMeasurement operation

Warning

This documentation refers to the Classic QDK, which has been replaced by the Modern QDK.

Please see https://aka.ms/qdk.api for the API documentation for the Modern QDK.

Namespace: Microsoft.Quantum.Diagnostics

Package: Microsoft.Quantum.QSharp.Foundation

Asserts that measuring the given qubits in the given Pauli basis will always have the given result.

operation AssertMeasurement (bases : Pauli[], qubits : Qubit[], result : Result, msg : String) : Unit is Adj + Ctl

Input

bases : Pauli[]

A measurement effect to assert the probability of, expressed as a multi-qubit Pauli operator.

qubits : Qubit[]

A register on which to make the assertion.

result : Result

The expected result of Measure(bases, qubits).

msg : String

A message to be reported if the assertion fails.

Output : Unit

Example

The following snippet will execute without errors on the full-state simulator:

use q = Qubit();
within {
    H(q);
} apply {
    AssertMeasurement([PauliX], [q], Zero, "Expected |+⟩ state.");
}

Remarks

Note that the Adjoint and Controlled versions of this operation will not check the condition.

See Also