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
33 changes: 33 additions & 0 deletions src/Simulation/QsharpCore/Arrays/Enumeration.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Quantum.Arrays {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;

/// # Summary
/// Given an array, returns a range over the indices of that array, suitable
/// for use in a for loop.
///
/// # Type Parameters
/// ## 'TElement
/// The type of elements of the array.
///
/// # Input
/// ## array
/// An array for which a range of indices should be returned.
///
/// # Output
/// A range over all indices of the array.
///
/// # Example
/// The following `for` loops are equivalent:
/// ```Q#
/// for (idx in IndexRange(array)) { ... }
/// for (idx in IndexRange(array)) { ... }
/// ```
function IndexRange<'TElement>(array : 'TElement[]) : Range {
return 0..(Length(array) - 1);
}

}
45 changes: 45 additions & 0 deletions src/Simulation/QsharpCore/Canon/NoOp.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Quantum.Canon {

/// # Summary
/// Performs the identity operation (no-op) on an argument.
///
/// # Description
/// This operation takes a value of any type and does nothing to it.
/// This can be useful whenever an input of an operation type is expected,
/// but no action should be taken.
/// For instance, if a particular error correction syndrome indicates that
/// no error has occurred, `NoOp<Qubit[]>` may be the correct recovery
/// procedure.
/// Similarly, if an operation expects a state preparation procedure as
/// input, `NoOp<Qubit[]>` can be used to prepare the state
/// $\ket{0 \cdots 0}$.
///
/// # Input
/// ## input
/// A value to be ignored.
///
/// # Remarks
/// In almost all cases, the type parameter for `NoOp` needs to be specified
/// explicitly. For instance, `NoOp<Qubit>` is identical to
/// <xref:microsoft.quantum.intrinsic.i>.
///
/// # See Also
/// - Microsoft.Quantum.Intrinsic.I
operation NoOp<'T>(input : 'T) : Unit is Adj + Ctl {
}


/// # Summary
/// Ignores the output of an operation or function.
///
/// # Input
/// ## value
/// A value to be ignored.
function Ignore<'T> (value : 'T) : Unit {
return ();
}

}
72 changes: 72 additions & 0 deletions src/Simulation/QsharpCore/Diagnostics/Assert.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Quantum.Diagnostics {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;

/// # Summary
/// Asserts that measuring the given qubits in the given Pauli basis will
/// always have the given result.
///
/// # Input
/// ## bases
/// A measurement effect to assert the probability of, expressed as a
/// multi-qubit Pauli operator.
/// ## qubits
/// A register on which to make the assertion.
/// ## result
/// The expected result of `Measure(bases, qubits)`.
/// ## msg
/// A message to be reported if the assertion fails.
///
/// # Remarks
/// Note that the Adjoint and Controlled versions of this operation will not
/// check the condition.
///
/// # See Also
/// - Microsoft.Quantum.Diagnostics.AssertMeasurementProbability
operation AssertMeasurement(bases : Pauli[], qubits : Qubit[], result : Result, msg : String) : Unit
is Adj + Ctl {
body intrinsic;
}


/// # Summary
/// Asserts that measuring the given qubits in the given Pauli basis will have the given result
/// with the given probability, within some tolerance.
///
/// # Input
/// ## bases
/// A measurement effect to assert the probability of, expressed as a
/// multi-qubit Pauli operator.
/// ## qubits
/// A register on which to make the assertion.
/// ## result
/// An expected result of `Measure(bases, qubits)`.
/// ## prob
/// The probability with which the given result is expected.
/// ## msg
/// A message to be reported if the assertion fails.
///
/// # Example
/// ```qsharp
/// using (register = Qubit()) {
/// H(register);
/// AssertProb([PauliZ], [register], One, 0.5,
/// "Measuring in conjugate basis did not give 50/50 results.", 1e-5);
/// }
/// ```
///
/// # Remarks
/// Note that the Adjoint and Controlled versions of this operation will not
/// check the condition.
///
/// # See Also
/// - Microsoft.Quantum.Diagnostics.AssertMeasurement
operation AssertMeasurementProbability(bases : Pauli[], qubits : Qubit[], result : Result, prob : Double, msg : String, tol : Double) : Unit
is Adj + Ctl {
body intrinsic;
}

}
60 changes: 4 additions & 56 deletions src/Simulation/QsharpCore/Intrinsic.qs
Original file line number Diff line number Diff line change
Expand Up @@ -27,68 +27,16 @@ namespace Microsoft.Quantum.Intrinsic {
}


/// # Summary
/// Asserts that measuring the given qubits in the given Pauli basis will
/// always have the given result.
///
/// # Input
/// ## bases
/// A measurement effect to assert the probability of, expressed as a
/// multi-qubit Pauli operator.
/// ## qubits
/// A register on which to make the assertion.
/// ## result
/// The expected result of `Measure(bases, qubits)`.
/// ## msg
/// A message to be reported if the assertion fails.
///
/// # Remarks
/// Note that the Adjoint and Controlled versions of this operation will not
/// check the condition.
///
/// # See Also
/// - AssertProb
@Deprecated("Microsoft.Quantum.Diagnostics.AssertMeasurement")
operation Assert (bases : Pauli[], qubits : Qubit[], result : Result, msg : String) : Unit
is Adj + Ctl {
body intrinsic;
Microsoft.Quantum.Diagnostics.AssertMeasurement(bases, qubits, result, msg);
}


/// # Summary
/// Asserts that measuring the given qubits in the given Pauli basis will have the given result
/// with the given probability, within some tolerance.
///
/// # Input
/// ## bases
/// A measurement effect to assert the probability of, expressed as a
/// multi-qubit Pauli operator.
/// ## qubits
/// A register on which to make the assertion.
/// ## result
/// An expected result of `Measure(bases, qubits)`.
/// ## prob
/// The probability with which the given result is expected.
/// ## msg
/// A message to be reported if the assertion fails.
///
/// # Example
/// ```qsharp
/// using (register = Qubit()) {
/// H(register);
/// AssertProb([PauliZ], [register], One, 0.5,
/// "Measuring in conjugate basis did not give 50/50 results.", 1e-5);
/// }
/// ```
///
/// # Remarks
/// Note that the Adjoint and Controlled versions of this operation will not
/// check the condition.
///
/// # See Also
/// - Assert
@Deprecated("Microsoft.Quantum.Diagnostics.AssertMeasurementProbability")
operation AssertProb (bases : Pauli[], qubits : Qubit[], result : Result, prob : Double, msg : String, tol : Double) : Unit
is Adj + Ctl {
body intrinsic;
Microsoft.Quantum.Diagnostics.AssertMeasurementProbability(bases, qubits, result, prob, msg, tol);
}


Expand Down
Loading