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
Show all changes
29 commits
Select commit Hold shift + click to select a range
6920eee
Improve code quality with experimental linter.
cgranade Jan 8, 2020
ac42658
Fixed a couple mistakes in previous cleanup.
cgranade Jan 8, 2020
5e97944
More fixes to resolve linting issues.
cgranade Jan 8, 2020
b2f7de1
Remove extraneous comment.
cgranade Jan 8, 2020
829c680
Applied feedback from #198.
cgranade Jan 8, 2020
c0f5580
Applying more documentation fixes suggested by linter.
cgranade Jan 8, 2020
30decd3
Fix to deprecation stub.
cgranade Jan 8, 2020
0c294d3
Whitespace fix noted by @ScottCarda-MS.
cgranade Jan 8, 2020
15b647c
Fixed minor mistake introduced with previous code quality fix.
cgranade Jan 8, 2020
9dbc67f
Incorporated more feedback from @ScottCarda-MS.
cgranade Jan 8, 2020
38a25b7
Merge branch 'master' into cgranade/code-quality
Jan 13, 2020
acf4067
Update Standard/src/Arrays/Map.qs
Jan 14, 2020
9cdbe19
Update Standard/src/Canon/Combinators/ApplyIf.qs
Jan 14, 2020
43ae0aa
Update Standard/src/Canon/Combinators/ApplyIf.qs
Jan 14, 2020
bbd5d98
Update Standard/src/Canon/Combinators/ApplyIf.qs
Jan 14, 2020
e3a93c0
Update Standard/src/Arithmetic/Integer.qs
Jan 14, 2020
101dc90
Update Standard/src/Arithmetic/Integer.qs
Jan 14, 2020
9ad1810
Update Standard/src/Canon/Combinators/ApplyIf.qs
Jan 14, 2020
90e50dc
Update Standard/src/Arithmetic/Integer.qs
Jan 14, 2020
18e3f46
Update Standard/src/Arithmetic/Integer.qs
Jan 14, 2020
f75d87c
Update Standard/src/Arithmetic/Integer.qs
Jan 14, 2020
2660918
Update Standard/src/Arithmetic/Integer.qs
Jan 14, 2020
80ef13b
Addressing feedback, lots of indentation fixes.
cgranade Jan 14, 2020
817f033
Merge branch 'cgranade/code-quality' of github.com:Microsoft/QuantumL…
cgranade Jan 14, 2020
dd86e36
Deprecate the stack data structure.
cgranade Jan 14, 2020
f3152d3
Slight improvements to phase est operations.
cgranade Jan 14, 2020
a4f50f9
Add missing characteristics to CNOTChainTarget.
cgranade Jan 14, 2020
06a349e
CCNOTChainTarget → ApplyCNOTChainWithTarget
cgranade Jan 14, 2020
37b95d9
Workaround for kata oracle counting.
cgranade Jan 15, 2020
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
5 changes: 0 additions & 5 deletions Standard/src/AmplitudeAmplification/StandardAlgorithms.qs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ namespace Microsoft.Quantum.AmplitudeAmplification {
return ReflectionPhases(startPhases, targetPhases);
}

// We use the phases in "Fixed-Point Amplitude Amplification with an
// Optimal Number of Queires" [YoderLowChuang2014]
// See also "Methodology of composite quantum gates" [LowYoderChuang2016]
// for phases in the `RotationPhases` format

/// # Summary
/// Computes partial reflection phases for fixed-point amplitude
/// amplification.
Expand Down
132 changes: 85 additions & 47 deletions Standard/src/Arithmetic/ApplyDual.qs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ namespace Microsoft.Quantum.Arithmetic {
op(phaseLE);
Adjoint QFTLE(target);
}

adjoint invert;
}


/// # See Also
/// - @"microsoft.quantum.canon.applyphaseleoperationonle"
operation ApplyPhaseLEOperationOnLEC (op : (PhaseLittleEndian => Unit is Ctl), target : LittleEndian) : Unit
Expand All @@ -63,7 +63,7 @@ namespace Microsoft.Quantum.Arithmetic {
op(phaseLE);
Adjoint QFTLE(target);
}

controlled (controls, ...)
{
QFTLE(target);
Expand All @@ -72,8 +72,8 @@ namespace Microsoft.Quantum.Arithmetic {
Adjoint QFTLE(target);
}
}


/// # See Also
/// - @"microsoft.quantum.canon.applyphaseleoperationonle"
operation ApplyPhaseLEOperationOnLECA (op : (PhaseLittleEndian => Unit is Adj + Ctl), target : LittleEndian) : Unit
Expand All @@ -85,21 +85,21 @@ namespace Microsoft.Quantum.Arithmetic {
op(phaseLE);
Adjoint QFTLE(target);
}

adjoint invert;

controlled (controls, ...)
{
QFTLE(target);
let phaseLE = PhaseLittleEndian(target!);
Controlled op(controls, phaseLE);
Adjoint QFTLE(target);
}

controlled adjoint invert;
}


/// # Summary
/// Applies an operation that takes a
/// <xref:microsoft.quantum.arithmetic.phaselittleendian> register as input
Expand All @@ -118,56 +118,94 @@ namespace Microsoft.Quantum.Arithmetic {
///
/// # See Also
/// - Microsoft.Quantum.Canon.ApplyLEOperationonPhaseLEA
/// - Microsoft.Quantum.Canon.ApplyLEOperationonPhaseLEA
/// - Microsoft.Quantum.Canon.ApplyLEOperationonPhaseLEC
/// - Microsoft.Quantum.Canon.ApplyLEOperationonPhaseLECA
operation ApplyLEOperationOnPhaseLE (op : (LittleEndian => Unit), target : PhaseLittleEndian) : Unit
{
let targetLE = LittleEndian(target!);
ApplyWith(Adjoint QFTLE, op, targetLE);
}





/// # Summary
/// Applies an operation that takes a
/// <xref:microsoft.quantum.arithmetic.phaselittleendian> register as input
/// on a target register of type <xref:microsoft.quantum.arithmetic.littleendian>.
///
/// # Input
/// ## op
/// The operation to be applied.
/// ## target
/// The register to which the operation is applied.
///
/// # Remarks
/// The register is transformed to `LittleEndian` by the use of
/// <xref:microsoft.quantum.canon.qftle> and is then returned to
/// its original representation after application of `op`.
///
/// # See Also
/// - Microsoft.Quantum.Canon.ApplyLEOperationonPhaseLE
operation ApplyLEOperationOnPhaseLEA (op : (LittleEndian => Unit is Adj), target : PhaseLittleEndian) : Unit
{
body (...)
{
let targetLE = LittleEndian(target!);
ApplyWithA(Adjoint QFTLE, op, targetLE);
}

adjoint invert;
/// - Microsoft.Quantum.Canon.ApplyLEOperationonPhaseLEC
/// - Microsoft.Quantum.Canon.ApplyLEOperationonPhaseLECA
operation ApplyLEOperationOnPhaseLEA (op : (LittleEndian => Unit is Adj), target : PhaseLittleEndian)
: Unit is Adj {
let targetLE = LittleEndian(target!);
ApplyWithA(Adjoint QFTLE, op, targetLE);
}




/// # Summary
/// Applies an operation that takes a
/// <xref:microsoft.quantum.arithmetic.phaselittleendian> register as input
/// on a target register of type <xref:microsoft.quantum.arithmetic.littleendian>.
///
/// # Input
/// ## op
/// The operation to be applied.
/// ## target
/// The register to which the operation is applied.
///
/// # Remarks
/// The register is transformed to `LittleEndian` by the use of
/// <xref:microsoft.quantum.canon.qftle> and is then returned to
/// its original representation after application of `op`.
///
/// # See Also
/// - Microsoft.Quantum.Canon.ApplyLEOperationonPhaseLE
operation ApplyLEOperationOnPhaseLEC (op : (LittleEndian => Unit is Ctl), target : PhaseLittleEndian) : Unit
{
body (...)
{
let targetLE = LittleEndian(target!);
ApplyWithC(Adjoint QFTLE, op, targetLE);
}

controlled distribute;
/// - Microsoft.Quantum.Canon.ApplyLEOperationonPhaseLEA
/// - Microsoft.Quantum.Canon.ApplyLEOperationonPhaseLECA
operation ApplyLEOperationOnPhaseLEC (op : (LittleEndian => Unit is Ctl), target : PhaseLittleEndian)
: Unit is Ctl {
let targetLE = LittleEndian(target!);
ApplyWithC(Adjoint QFTLE, op, targetLE);
}




/// # Summary
/// Applies an operation that takes a
/// <xref:microsoft.quantum.arithmetic.phaselittleendian> register as input
/// on a target register of type <xref:microsoft.quantum.arithmetic.littleendian>.
///
/// # Input
/// ## op
/// The operation to be applied.
/// ## target
/// The register to which the operation is applied.
///
/// # Remarks
/// The register is transformed to `LittleEndian` by the use of
/// <xref:microsoft.quantum.canon.qftle> and is then returned to
/// its original representation after application of `op`.
///
/// # See Also
/// - Microsoft.Quantum.Canon.ApplyLEOperationonPhaseLE
operation ApplyLEOperationOnPhaseLECA (op : (LittleEndian => Unit is Adj + Ctl), target : PhaseLittleEndian) : Unit
{
body (...)
{
let targetLE = LittleEndian(target!);
ApplyWithCA(Adjoint QFTLE, op, targetLE);
}

adjoint invert;
controlled distribute;
controlled adjoint distribute;
/// - Microsoft.Quantum.Canon.ApplyLEOperationonPhaseLEA
/// - Microsoft.Quantum.Canon.ApplyLEOperationonPhaseLEC
operation ApplyLEOperationOnPhaseLECA(op : (LittleEndian => Unit is Adj + Ctl), target : PhaseLittleEndian)
: Unit is Adj + Ctl {
let targetLE = LittleEndian(target!);
ApplyWithCA(Adjoint QFTLE, op, targetLE);
}

}
46 changes: 23 additions & 23 deletions Standard/src/Arithmetic/Arithmetic.qs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ namespace Microsoft.Quantum.Arithmetic {
open Microsoft.Quantum.Arrays;

/// # Summary
/// Applies `X` operations to qubits in a little-endian register based on 1 bits in an integer.
/// Applies a bitwise-XOR operation between a classical integer and an
/// integer represented by a register of qubits.
///
/// # Description
/// Applies `X` operations to qubits in a little-endian register based on
/// 1 bits in an integer.
///
/// Let us denote `value` by a and let y be an unsigned integer encoded in `target`,
/// then `InPlaceXorLE` performs an operation given by the following map:
Expand All @@ -19,21 +24,20 @@ namespace Microsoft.Quantum.Arithmetic {
/// An integer which is assumed to be non-negative.
/// ## target
/// A quantum register which is used to store `value` in little-endian encoding.
operation ApplyXorInPlace(value : Int, target : LittleEndian) : Unit {
body (...) {
ApplyToEachCA(
CControlledCA(X),
Zip(IntAsBoolArray(value, Length(target!)), target!)
);
}

adjoint auto;
controlled auto;
controlled adjoint auto;
operation ApplyXorInPlace(value : Int, target : LittleEndian)
: Unit is Adj + Ctl {
ApplyToEachCA(
CControlledCA(X),
Zip(IntAsBoolArray(value, Length(target!)), target!)
);
}

/// # Summary
/// This computes the Majority function in-place on 3 qubits.
/// Applies the three-qubit majority operation in-place on a register of
/// qubits.
///
/// # Description
/// This operation computes the majority function in-place on 3 qubits.
///
/// If we denote output qubit as $z$ and input qubits as $x$ and $y$,
/// the operation performs the following transformation:
Expand All @@ -45,17 +49,13 @@ namespace Microsoft.Quantum.Arithmetic {
/// and stored in this qubit.
/// ## input
/// Second and third input qubits.
operation InPlaceMajority(output: Qubit, input: Qubit[]) : Unit {
body (...) {
if (Length(input) == 2) {
MAJ(input[0], input[1], output);
} else {
fail $"The in-place majority operation on {Length(input)} is qubits not yet implemented.";
}
operation ApplyMajorityInPlace(output: Qubit, input: Qubit[])
: Unit is Adj + Ctl {
if (Length(input) == 2) {
MAJ(input[0], input[1], output);
} else {
fail $"The in-place majority operation on {Length(input)} is qubits not yet implemented.";
}
adjoint auto;
controlled auto;
adjoint controlled auto;
}

/// # Summary
Expand Down
7 changes: 4 additions & 3 deletions Standard/src/Arithmetic/Asserts.qs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ namespace Microsoft.Quantum.Arithmetic {
open Microsoft.Quantum.Diagnostics;

/// # Summary
/// Asserts that the probability of a specific state of a quantum register has the
/// expected value.
///
/// Asserts that the probability of a specific state of a quantum register has the
/// expected value.
///
/// # Description
/// Given an $n$-qubit quantum state $\ket{\psi}=\sum^{2^n-1}_{j=0}\alpha_j \ket{j}$,
/// asserts that the probability $|\alpha_j|^2$ of the state $\ket{j}$ indexed by $j$
/// has the expected value.
Expand Down
16 changes: 10 additions & 6 deletions Standard/src/Arithmetic/Comparators.qs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ namespace Microsoft.Quantum.Arithmetic {
open Microsoft.Quantum.Arrays;

/// # Summary
/// This unitary tests if two integers `x` and `y` stored in equal-size qubit registers
/// satisfy `x > y`. If true, 1 is XORed into an output
/// qubit. Otherwise, 0 is XORed into an output qubit.
/// This operation tests if an integer represented by a register of qubits
/// is greater than another integer, applying an XOR of the result onto an
/// output qubit.
///
/// In other words, this unitary $U$ satisfies:
/// # Description
/// Given two integers `x` and `y` stored in equal-size qubit registers,
/// this operation checks if they satisfy `x > y`. If true, 1 is
/// XORed into an output qubit. Otherwise, 0 is XORed into an output qubit.
/// In other words, this operation can be represented by the unitary
/// $$
/// \begin{align}
/// U\ket{x}\ket{y}\ket{z}=\ket{x}\ket{y}\ket{z\oplus (x>y)}.
/// U\ket{x}\ket{y}\ket{z} = \ket{x}\ket{y}\ket{z\oplus (x>y)}.
/// \end{align}
/// $$.
/// $$
///
/// # Input
/// ## x
Expand Down
17 changes: 16 additions & 1 deletion Standard/src/Arithmetic/Deprecated.qs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Microsoft.Quantum.Canon {
operation ApplyReversedOpBigEndianA(op : (BigEndian => Unit is Adj), register : LittleEndian) : Unit is Adj {
ApplyReversedOpBEA(op, register);
}

/// # Deprecated
/// Please use @"Microsoft.Quantum.Arithmetic.ApplyReversedOpBEC".
@Deprecated("Microsoft.Quantum.Arithmetic.ApplyReversedOpBEC")
Expand Down Expand Up @@ -193,4 +193,19 @@ namespace Microsoft.Quantum.Canon {
CopyMostSignificantBit(from, target);
}

/// # Deprecated
/// Please use @"microsoft.quantum.canon.applycnotchain".
@Deprecated("Microsoft.Quantum.Canon.ApplyCNOTChain")
operation CascadeCNOT (register : Qubit[]) : Unit is Adj + Ctl {
Microsoft.Quantum.Canon.ApplyCNOTChain(register);
}

/// # Deprecated
/// Please use @"microsoft.quantum.arithmetic.applymajorityinplace".
@Deprecated("Microsoft.Quantum.Arithmetic.ApplyMajorityInPlace")
operation InPlaceMajority(output: Qubit, input: Qubit[])
: Unit is Adj + Ctl {
ApplyMajorityInPlace(output, input);
}

}
Loading