Gates
– Manipulating quantum states¶
-
squanch.gates.
H
(qubit)[source]¶ Applies the Hadamard transform to the specified qubit, updating the qsystem state.
cache_id
:H
Parameters: qubit (Qubit) – the qubit to apply the operator to
-
squanch.gates.
X
(qubit)[source]¶ Applies the Pauli-X (NOT) operation to the specified qubit, updating the qsystem state.
cache_id
:X
Parameters: qubit (Qubit) – the qubit to apply the operator to
-
squanch.gates.
Y
(qubit)[source]¶ Applies the Pauli-Y operation to the specified qubit, updating the qsystem state.
cache_id
:Y
Parameters: qubit (Qubit) – the qubit to apply the operator to
-
squanch.gates.
Z
(qubit)[source]¶ Applies the Pauli-Z operation to the specified qubit, updating the qsystem state.
cache_id
:Z
Parameters: qubit (Qubit) – the qubit to apply the operator to
-
squanch.gates.
RX
(qubit, angle)[source]¶ Applies the single qubit X-rotation operator to the specified qubit, updating the qsystem state.
cache_id
:Rx*
, where * is angle/piParameters: - qubit (Qubit) – the qubit to apply the operator to
- angle (float) – the angle by which to rotate
-
squanch.gates.
RY
(qubit, angle)[source]¶ Applies the single qubit Y-rotation operator to the specified qubit, updating the qsystem state.
cache_id
:Ry*
, where * is angle/piParameters: - qubit (Qubit) – the qubit to apply the operator to
- angle (float) – the angle by which to rotate
-
squanch.gates.
RZ
(qubit, angle)[source]¶ Applies the single qubit Z-rotation operator to the specified qubit, updating the qsystem state.
cache_id
:Rz*
, where * is angle/piParameters: - qubit (Qubit) – the qubit to apply the operator to
- angle (float) – the angle by which to rotate
-
squanch.gates.
PHASE
(qubit, angle)[source]¶ Applies the phase operation from control on target, mapping |1> to e^(i*angle)|1>.
cache_id
:PHASE*
, where * is angle/piParameters: - qubit (Qubit) – the qubit to apply the operator to
- angle (float) – the phase angle to apply
-
squanch.gates.
CNOT
(control, target)[source]¶ Applies the controlled-NOT operation from control on target. This gate takes two qubit arguments to construct an arbitrary CNOT matrix.
cache_id
:CNOTi,j,N
, where i and j are control and target indices and N is num_qubitsParameters:
-
squanch.gates.
TOFFOLI
(control1, control2, target)[source]¶ Applies the Toffoli (or controlled-controlled-NOT) operation from control on target. This gate takes three qubit arguments to construct an arbitrary CCNOT matrix.
cache_id
:CCNOTi,j,k,N
, where i and j are control indices and k target indices and N is num_qubitsParameters:
-
squanch.gates.
CU
(control, target, unitary)[source]¶ Applies the controlled-unitary operation from control on target. This gate takes control and target qubit arguments and a unitary operator to apply
cache_id
:CUi,j,<str(unitary)>,N
, where i and j are control and target indices and N is num_qubitsParameters:
-
squanch.gates.
CPHASE
(control, target, angle)[source]¶ Applies the controlled-phase operation from control on target. This gate takes control and target qubit arguments and a rotation angle, and calls CU(control, target, np.array([[1, 0], [0, np.exp(1j * angle)]])).
Parameters:
-
squanch.gates.
SWAP
(q1, q2)[source]¶ Applies the SWAP operator to two qubits, switching the states. This gate is implemented by three CNOT operations and thus has no
cache_id
. :param q1: the first qubit :param q2: the second qubit
-
squanch.gates.
expand
(operator, index, num_qubits, cache_id=None)[source]¶ Apply a k-qubit quantum gate to act on n-qubits by filling the rest of the spaces with identity operators
Parameters: - operator (np.array) – the single- or n-qubit operator to apply
- index (int) – if specified, the index of the qubit to perform the operation on
- num_qubits (int) – the number of qubits in the system
- cache_id (str) – a character identifier to cache gates and their expansions in memory
Returns: the expanded n-qubit operator