Skip to content

Commit

Permalink
Remove SwapLabels
Browse files Browse the repository at this point in the history
  • Loading branch information
swernli committed Sep 16, 2024
1 parent 1beedf1 commit c759348
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
2 changes: 1 addition & 1 deletion library/src/tests/canon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
25 changes: 6 additions & 19 deletions library/std/src/canon.qs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;

}

0 comments on commit c759348

Please sign in to comment.