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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Microsoft.Quantum.Intrinsic {
H(target);
}
apply {
Controlled Z([control1, control2], target);
CCZ(control1, control2, target);
}
}
controlled (ctls, ...) {
Expand Down
42 changes: 42 additions & 0 deletions src/Simulation/TargetDefinitions/Decompositions/CX.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

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

/// # Summary
/// Applies the controlled-X (CX) gate to a pair of qubits.
///
/// # Description
/// This operation can be simulated by the unitary matrix
/// $$
/// \begin{align}
/// \left(\begin{matrix}
/// 1 & 0 & 0 & 0 \\\\
/// 0 & 1 & 0 & 0 \\\\
/// 0 & 0 & 0 & 1 \\\\
/// 0 & 0 & 1 & 0
/// \end{matrix}\right)
/// \end{align},
/// $$
/// where rows and columns are organized as in the quantum concepts guide.
///
/// # Input
/// ## control
/// Control qubit for the CX gate.
/// ## target
/// Target qubit for the CX gate.
///
/// # Remarks
/// Equivalent to:
/// ```qsharp
/// Controlled X([control], target);
/// ```
/// and to:
/// ```qsharp
/// CNOT(control, target);
/// ```
operation CX(control : Qubit, target : Qubit) : Unit is Adj + Ctl{
CNOT(control, target);
}
}
46 changes: 46 additions & 0 deletions src/Simulation/TargetDefinitions/Decompositions/CYFromCNOT.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

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

/// # Summary
/// Applies the controlled-Y (CY) gate to a pair of qubits.
///
/// # Description
/// This operation can be simulated by the unitary matrix
/// $$
/// \begin{align}
/// 1 & 0 & 0 & 0 \\\\
/// 0 & 1 & 0 & 0 \\\\
/// 0 & 0 & 0 & -i \\\\
/// 0 & 0 & i & 0
/// \end{align},
/// $$
/// where rows and columns are organized as in the quantum concepts guide.
///
/// # Input
/// ## control
/// Control qubit for the CY gate.
/// ## target
/// Target qubit for the CY gate.
///
/// # Remarks
/// Equivalent to:
/// ```qsharp
/// Controlled Y([control], target);
/// ```
operation CY(control : Qubit, target : Qubit) : Unit {
body (...) {
within {
MapPauli(target, PauliX, PauliY);
}
apply {
CNOT(control, target);
}
}
adjoint self;
controlled distribute;
controlled adjoint self;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

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

/// # Summary
/// Applies the controlled-Z (CZ) gate to a pair of qubits.
///
/// # Description
/// This operation can be simulated by the unitary matrix
/// $$
/// \begin{align}
/// 1 & 0 & 0 & 0 \\\\
/// 0 & 1 & 0 & 0 \\\\
/// 0 & 0 & 1 & 0 \\\\
/// 0 & 0 & 0 & -1
/// \end{align},
/// $$
/// where rows and columns are organized as in the quantum concepts guide.
///
/// # Input
/// ## control
/// Control qubit for the CZ gate.
/// ## target
/// Target qubit for the CZ gate.
///
/// # Remarks
/// Equivalent to:
/// ```qsharp
/// Controlled Z([control], target);
/// ```
operation CZ(control : Qubit, target : Qubit) : Unit {
body (...) {
ApplyControlledZ(control, target);
}
controlled (ctls, ...) {
if Length(ctls) == 0 {
ApplyControlledZ(control, target);
}
elif Length(ctls) == 1 {
CCZ(ctls[0], control, target);
}
else {
ApplyWithLessControlsA(Controlled CZ, (ctls, (control, target)));
}
}
adjoint self;
}
}
17 changes: 17 additions & 0 deletions src/Simulation/TargetDefinitions/Decompositions/Utils.qs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ namespace Microsoft.Quantum.Intrinsic {
H(target);
}

internal operation CCZ (control1 : Qubit, control2 : Qubit, target : Qubit) : Unit is Adj {
// [Page 15 of arXiv:1206.0758v3](https://arxiv.org/pdf/1206.0758v3.pdf#page=15)
Adjoint T(control1);
Adjoint T(control2);
CNOT(target, control1);
T(control1);
CNOT(control2, target);
CNOT(control2, control1);
T(target);
Adjoint T(control1);
CNOT(control2, target);
CNOT(target, control1);
Adjoint T(target);
T(control1);
CNOT(control2, control1);
}

internal function ReducedDyadicFraction (numerator : Int, denominatorPowerOfTwo : Int) : (Int, Int) {
if (numerator == 0) { return (0,0); }
mutable num = numerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

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

/// # Summary
/// Applies the Pauli $Y$ gate.
Expand All @@ -27,19 +28,14 @@ namespace Microsoft.Quantum.Intrinsic {
ApplyUncontrolledY(qubit);
}
elif (Length(ctls) == 1) {
within {
MapPauli(qubit, PauliX, PauliY);
}
apply {
CNOT(ctls[0], qubit);
}
CY(ctls[0], qubit);
}
elif (Length(ctls) == 2) {
within {
MapPauli(qubit, PauliZ, PauliY);
}
apply {
Controlled Z(ctls, qubit);
CCZ(ctls[0], ctls[1], qubit);
}
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

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

/// # Summary
/// Applies the Pauli $Z$ gate.
Expand Down Expand Up @@ -30,20 +31,7 @@ namespace Microsoft.Quantum.Intrinsic {
ApplyControlledZ(ctls[0], qubit);
}
elif (Length(ctls) == 2) {
// [Page 15 of arXiv:1206.0758v3](https://arxiv.org/pdf/1206.0758v3.pdf#page=15)
Adjoint T(ctls[0]);
Adjoint T(ctls[1]);
CNOT(qubit, ctls[0]);
T(ctls[0]);
CNOT(ctls[1], qubit);
CNOT(ctls[1], ctls[0]);
T(qubit);
Adjoint T(ctls[0]);
CNOT(ctls[1], qubit);
CNOT(qubit, ctls[0]);
Adjoint T(qubit);
T(ctls[0]);
CNOT(ctls[1], ctls[0]);
CCZ(ctls[0], ctls[1], qubit);
}
else {
ApplyWithLessControlsA(Controlled Z, (ctls, qubit));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<QSharpCompile Include="..\TargetDefinitions\Decompositions\AssertOperationsEqualReferenced.qs" />
<QSharpCompile Include="..\TargetDefinitions\Decompositions\CCNOTFromCCZ.qs" />
<QSharpCompile Include="..\TargetDefinitions\Decompositions\CNOTFromSinglyControlled.qs" />
<QSharpCompile Include="..\TargetDefinitions\Decompositions\CX.qs" />
<QSharpCompile Include="..\TargetDefinitions\Decompositions\CYFromCNOT.qs" />
<QSharpCompile Include="..\TargetDefinitions\Decompositions\CZFromSinglyControlled.qs" />
<QSharpCompile Include="..\TargetDefinitions\Decompositions\ExpFracFromExpUtil.qs" />
<QSharpCompile Include="..\TargetDefinitions\Decompositions\ExpFromExpUtil.qs" />
<QSharpCompile Include="..\TargetDefinitions\Decompositions\ExpUtil.qs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<QsharpCompile Include="..\TargetDefinitions\Decompositions\AssertOperationsEqualReferenced.qs" />
<QsharpCompile Include="..\TargetDefinitions\Decompositions\CCNOTFromCCZ.qs" />
<QsharpCompile Include="..\TargetDefinitions\Decompositions\CNOTFromSinglyControlled.qs" />
<QSharpCompile Include="..\TargetDefinitions\Decompositions\CX.qs" />
<QSharpCompile Include="..\TargetDefinitions\Decompositions\CYFromCNOT.qs" />
<QSharpCompile Include="..\TargetDefinitions\Decompositions\CZFromSinglyControlled.qs" />
<QsharpCompile Include="..\TargetDefinitions\Decompositions\ExpFracFromExpUtil.qs" />
<QsharpCompile Include="..\TargetDefinitions\Decompositions\ExpFromExpUtil.qs" />
<QsharpCompile Include="..\TargetDefinitions\Decompositions\ExpUtil.qs" />
Expand Down