This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Improve core Q# API consistency #286
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a1cfb61
Move NoOp.qs from QuantumLibraries.
cgranade c796f39
Remove deprecated primitives.
cgranade 306f93f
Move diagnostics into diagnostics namespace.
cgranade b1925ce
Adapt AB#3758 regression test.
cgranade c80fad4
Move IndexRange as well.
cgranade 7bd91ba
Fixed typo in IndexRange namespace.
cgranade 74120e9
Merge branch 'master' into cgranade/move-noop
29e2db5
Fixed AllocateQubit2 test.
cgranade 62c8735
Merge branch 'cgranade/move-noop' of https://github.com/microsoft/qsh…
cgranade 7b36274
Merge branch 'master' into cgranade/move-noop
de2a93b
Fix AllocateQubit2Test.
cgranade dba0f78
Merge branch 'cgranade/move-noop' of https://github.com/microsoft/qsh…
cgranade d7efdeb
Merge branch 'master' into cgranade/move-noop
51b4258
Merge branch 'master' into cgranade/move-noop
c0657fe
Merge branch 'master' into cgranade/move-noop
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 (); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.