From c759348a6a2bb45d9db971a3b90fc002e1851285 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Mon, 16 Sep 2024 09:20:53 -0700 Subject: [PATCH] Remove `SwapLabels` --- library/src/tests/canon.rs | 2 +- library/std/src/canon.qs | 25 ++++++------------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/library/src/tests/canon.rs b/library/src/tests/canon.rs index d77a72f879..f43ba87eab 100644 --- a/library/src/tests/canon.rs +++ b/library/src/tests/canon.rs @@ -113,7 +113,7 @@ fn check_swap_labels() { "{ use qs = Qubit[2]; X(qs[0]); - SwapLabels(qs[0], qs[1]); + Relabel(qs, [qs[1], qs[0]]); MResetEachZ(qs) }", &Value::Array(vec![Value::RESULT_ZERO, Value::RESULT_ONE].into()), diff --git a/library/std/src/canon.qs b/library/std/src/canon.qs index 0f3b25770a..bd0fa29cf0 100644 --- a/library/std/src/canon.qs +++ b/library/std/src/canon.qs @@ -247,24 +247,6 @@ namespace Microsoft.Quantum.Canon { return snd; } - /// # Summary - /// Exchanges the labels of two qubits. This can function like a SWAP gate, but without needing to - /// perform any operations on the qubits themselves. The relabeling is done purely in qubit ID management. - /// - /// # Input - /// ## q0 - /// The first qubit to swap. - /// ## q1 - /// The second qubit to swap. - /// - /// # Remarks - /// This operation is useful when you need to swap qubits in a way that does not incur any quantum operations. - /// Note that when compiling for execution on hardware with limited qubit connectivity, this operation - /// may not result in any changes to qubit adjacency and a `SWAP` gate may still be required. - operation SwapLabels(q0 : Qubit, q1 : Qubit) : Unit { - Relabel([q0, q1], [q1, q0]); - } - /// # Summary /// Relabels the qubits in the `current` array with the qubits in the `updated` array. The `updated` array /// must be a valid permutation of the `current` array. @@ -288,6 +270,11 @@ namespace Microsoft.Quantum.Canon { /// Relabel(qubits, newOrder); /// ``` /// After this operation, any use of `qubits[0]` will refer to the qubit that was originally `qubits[2]`, and so on. + /// To exchange the labels on two qubits, the virtual equivalent of a `SWAP` gate, you can use the following code: + /// ```qsharp + /// use (q0, q1) = (Qubit(), Qubit()); + /// Relabel([q0, q1], [q1, q0]); + /// ``` operation Relabel(current : Qubit[], updated : Qubit[]) : Unit { body intrinsic; } @@ -630,6 +617,6 @@ namespace Microsoft.Quantum.Canon { adjoint self; } - export ApplyToEach, ApplyToEachA, ApplyToEachC, ApplyToEachCA, CX, CY, CZ, Fst, Snd, SwapLabels, Relabel, ApplyCNOTChain, ApplyP, ApplyPauli, ApplyPauliFromBitString, ApplyPauliFromInt, ApplyControlledOnInt, ApplyControlledOnBitString, ApplyQFT, SwapReverseRegister, ApplyXorInPlace, ApplyXorInPlaceL; + export ApplyToEach, ApplyToEachA, ApplyToEachC, ApplyToEachCA, CX, CY, CZ, Fst, Snd, Relabel, ApplyCNOTChain, ApplyP, ApplyPauli, ApplyPauliFromBitString, ApplyPauliFromInt, ApplyControlledOnInt, ApplyControlledOnBitString, ApplyQFT, SwapReverseRegister, ApplyXorInPlace, ApplyXorInPlaceL; }