Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Simulation/QSharpFoundation/Diagnostics/AssertAllZero.qs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ namespace Microsoft.Quantum.Diagnostics {
///
/// # See Also
/// - AssertQubit
operation AssertAllZero (qubits : Qubit[]) : Unit {
///
/// # Remarks
/// Note that the Adjoint and Controlled versions of this operation will not
/// check the condition.
operation AssertAllZero (qubits : Qubit[]) : Unit is Adj + Ctl {
body (...) {
for qubit in qubits {
AssertQubit(Zero, qubit);
Expand All @@ -39,7 +43,12 @@ namespace Microsoft.Quantum.Diagnostics {
///
/// # See Also
/// - AssertQubitWithinTolerance
operation AssertAllZeroWithinTolerance(qubits : Qubit[], tolerance : Double) : Unit {
///
/// # Remarks
/// Note that the Adjoint and Controlled versions of this operation will not
/// check the condition.
operation AssertAllZeroWithinTolerance(qubits : Qubit[], tolerance : Double) : Unit is Adj + Ctl{

body (...) {
for qubit in qubits {
AssertQubitWithinTolerance(Zero, qubit, tolerance);
Expand All @@ -51,6 +60,7 @@ namespace Microsoft.Quantum.Diagnostics {
controlled (ctrls, ...) {
AssertAllZeroWithinTolerance(qubits, tolerance);
}
controlled adjoint self;
}

}
Expand Down
15 changes: 12 additions & 3 deletions src/Simulation/QSharpFoundation/Diagnostics/AssertQubit.qs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ namespace Microsoft.Quantum.Diagnostics {
/// # Remarks
/// <xref:microsoft.quantum.diagnostics.assertqubitisinstatewithintolerance> allows for asserting
/// arbitrary qubit states rather than only $Z$ eigenstates.
operation AssertQubit (expected : Result, q : Qubit) : Unit {
///
/// Note that the Adjoint and Controlled versions of this operation will not
/// check the condition.
operation AssertQubit (expected : Result, q : Qubit) : Unit is Adj + Ctl {
AssertMeasurement([PauliZ], [q], expected, $"Qubit in invalid state. Expecting: {expected}");
}

Expand All @@ -46,7 +49,10 @@ namespace Microsoft.Quantum.Diagnostics {
/// # Remarks
/// <xref:microsoft.quantum.diagnostics.assertqubitisinstatewithintolerance> allows for asserting
/// arbitrary qubit states rather than only $Z$ eigenstates.
operation AssertQubitWithinTolerance(expected : Result, q : Qubit, tolerance : Double) : Unit {
///
/// Note that the Adjoint and Controlled versions of this operation will not
/// check the condition.
operation AssertQubitWithinTolerance(expected : Result, q : Qubit, tolerance : Double) : Unit is Adj + Ctl {
AssertMeasurementProbability([PauliZ], [q], expected, 1.0, $"Qubit in invalid state. Expecting: {expected} with tolerance {tolerance}", tolerance);
}

Expand Down Expand Up @@ -101,7 +107,10 @@ namespace Microsoft.Quantum.Diagnostics {
/// This is only true under the assumption that Tr(ρ) and Tr(|ψ⟩⟨ψ|) are both 1 (e.g. x₁ = 1/2, y₁ = 1/2).
/// If this is not the case, the function asserts that l∞ distance between
/// (x₂-x₁,x₃-x₁,x₄-x₁,x₄+x₁) and (y₂-y₁,y₃-y₁,y₄-y₁,y₄+y₁) is less than the tolerance parameter.
operation AssertQubitIsInStateWithinTolerance(expected : (Complex, Complex), register : Qubit, tolerance : Double) : Unit {
///
/// Note that the Adjoint and Controlled versions of this operation will not
/// check the condition.
operation AssertQubitIsInStateWithinTolerance(expected : (Complex, Complex), register : Qubit, tolerance : Double) : Unit is Adj + Ctl {
let (a, b) = expected;
let (reA, imA) = a!;
let (reB, imB) = b!;
Expand Down