torchquantum.functional#

MIT License

Copyright (c) 2020-present TorchQuantum Authors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Functions#

apply_unitary_einsum(state, mat, wires)

Apply the unitary to the statevector using torch.einsum method.

apply_unitary_bmm(state, mat, wires)

Apply the unitary to the statevector using torch.bmm method.

gate_wrapper(name, mat, method, q_device, wires)

Perform the phaseshift gate.

reset(q_device, wires[, inverse])

rx_matrix(params)

Compute unitary matrix for rx gate.

ry_matrix(params)

Compute unitary matrix for ry gate.

rz_matrix(params)

Compute unitary matrix for rz gate.

phaseshift_matrix(params)

Compute unitary matrix for phaseshift gate.

rot_matrix(params)

Compute unitary matrix for rot gate.

multirz_matrix(params, n_wires)

Compute unitary matrix for multiqubit RZ gate.

rxx_matrix(params)

Compute unitary matrix for RXX gate.

ryy_matrix(params)

Compute unitary matrix for RYY gate.

rzz_matrix(params)

Compute unitary matrix for RZZ gate.

rzx_matrix(params)

Compute unitary matrix for RZX gate.

crx_matrix(params)

Compute unitary matrix for CRX gate.

cry_matrix(params)

Compute unitary matrix for CRY gate.

crz_matrix(params)

Compute unitary matrix for CRZ gate.

crot_matrix(params)

Compute unitary matrix for CRot gate.

u1_matrix(params)

Compute unitary matrix for U1 gate.

cu1_matrix(params)

Compute unitary matrix for CU1 gate.

u2_matrix(params)

Compute unitary matrix for U2 gate.

cu2_matrix(params)

Compute unitary matrix for CU2 gate.

u3_matrix(params)

Compute unitary matrix for U3 gate.

cu3_matrix(params)

Compute unitary matrix for CU3 gate.

qubitunitary_matrix(params)

Compute unitary matrix for Qubitunitary gate.

qubitunitaryfast_matrix(params)

Compute unitary matrix for Qubitunitary fast gate.

qubitunitarystrict_matrix(params)

Compute unitary matrix for Qubitunitary strict gate.

multicnot_matrix(n_wires)

Compute unitary matrix for Multi qubit CNOT gate.

multixcnot_matrix(n_wires)

Compute unitary matrix for Multi qubit XCNOT gate.

hadamard(q_device, wires[, params, n_wires, ...])

Perform the hadamard gate.

shadamard(q_device, wires[, params, ...])

Perform the shadamard gate.

paulix(q_device, wires[, params, n_wires, ...])

Perform the Pauli X gate.

pauliy(q_device, wires[, params, n_wires, ...])

Perform the Pauli Y gate.

pauliz(q_device, wires[, params, n_wires, ...])

Perform the Pauli Z gate.

i(q_device, wires[, params, n_wires, ...])

Perform the I gate.

s(q_device, wires[, params, n_wires, ...])

Perform the s gate.

t(q_device, wires[, params, n_wires, ...])

Perform the t gate.

sx(q_device, wires[, params, n_wires, ...])

Perform the sx gate.

cnot(q_device, wires[, params, n_wires, ...])

Perform the cnot gate.

cz(q_device, wires[, params, n_wires, ...])

Perform the cz gate.

cy(q_device, wires[, params, n_wires, ...])

Perform the cy gate.

rx(q_device, wires[, params, n_wires, ...])

Perform the rx gate.

ry(q_device, wires[, params, n_wires, ...])

Perform the ry gate.

rz(q_device, wires[, params, n_wires, ...])

Perform the rz gate.

rxx(q_device, wires[, params, n_wires, ...])

Perform the rxx gate.

ryy(q_device, wires[, params, n_wires, ...])

Perform the ryy gate.

rzz(q_device, wires[, params, n_wires, ...])

Perform the rzz gate.

zz(q_device, wires[, params, n_wires, ...])

Perform the rzz gate.

rzx(q_device, wires[, params, n_wires, ...])

Perform the rzx gate.

zx(q_device, wires[, params, n_wires, ...])

Perform the rzx gate.

swap(q_device, wires[, params, n_wires, ...])

Perform the swap gate.

sswap(q_device, wires[, params, n_wires, ...])

Perform the sswap gate.

cswap(q_device, wires[, params, n_wires, ...])

Perform the cswap gate.

toffoli(q_device, wires[, params, n_wires, ...])

Perform the toffoli gate.

phaseshift(q_device, wires[, params, ...])

Perform the phaseshift gate.

p(q_device, wires[, params, n_wires, ...])

Perform the phaseshift gate.

cp(q_device, wires[, params, n_wires, ...])

Perform the cu1 gate.

rot(q_device, wires[, params, n_wires, ...])

Perform the rot gate.

multirz(q_device, wires[, params, n_wires, ...])

Perform the multi qubit RZ gate.

crx(q_device, wires[, params, n_wires, ...])

Perform the crx gate.

cry(q_device, wires[, params, n_wires, ...])

Perform the cry gate.

crz(q_device, wires[, params, n_wires, ...])

Perform the crz gate.

crot(q_device, wires[, params, n_wires, ...])

Perform the crot gate.

u1(q_device, wires[, params, n_wires, ...])

Perform the u1 gate.

u2(q_device, wires[, params, n_wires, ...])

Perform the u2 gate.

u3(q_device, wires[, params, n_wires, ...])

Perform the u3 gate.

u(q_device, wires[, params, n_wires, ...])

Perform the u3 gate.

cu1(q_device, wires[, params, n_wires, ...])

Perform the cu1 gate.

cu2(q_device, wires[, params, n_wires, ...])

Perform the cu2 gate.

cu3(q_device, wires[, params, n_wires, ...])

Perform the cu3 gate.

cu(q_device, wires[, params, n_wires, ...])

Perform the cu gate. :param q_device: The QuantumDevice. :type q_device: tq.QuantumDevice :param wires: Which qubit(s) to apply the gate. :type wires: Union[List[int], int] :param params: Parameters (if any) of the gate. Default to None. :type params: torch.Tensor, optional :param n_wires: Number of qubits the gate is applied to. Default to None. :type n_wires: int, optional :param static: Whether use static mode computation. Default to False. :type static: bool, optional :param parent_graph: Parent QuantumGraph of current operation. Default to None. :type parent_graph: tq.QuantumGraph, optional :param inverse: Whether inverse the gate. Default to False. :type inverse: bool, optional :param comp_method: Use 'bmm' or 'einsum' method to perform :type comp_method: bool, optional :param matrix vector multiplication. Default to 'bmm'.:.

qubitunitary(q_device, wires[, params, ...])

Perform the qubitunitary gate.

qubitunitaryfast(q_device, wires[, params, ...])

Perform the qubitunitaryfast gate.

qubitunitarystrict(q_device, wires[, ...])

Perform the qubitunitarystrict = gate.

multicnot(q_device, wires[, params, ...])

Perform the multi qubit cnot gate.

multixcnot(q_device, wires[, params, ...])

Perform the multi qubit xcnot gate.

x(q_device, wires[, params, n_wires, ...])

Perform the Pauli X gate.

y(q_device, wires[, params, n_wires, ...])

Perform the Pauli Y gate.

z(q_device, wires[, params, n_wires, ...])

Perform the Pauli Z gate.

zz(q_device, wires[, params, n_wires, ...])

Perform the rzz gate.

cx(q_device, wires[, params, n_wires, ...])

Perform the cnot gate.

ccnot(q_device, wires[, params, n_wires, ...])

Perform the toffoli gate.

ccx(q_device, wires[, params, n_wires, ...])

Perform the toffoli gate.

reset(q_device, wires[, inverse])

singleexcitation(q_device, wires[, params, ...])

Perform the single excitation gate.

ecr(q_device, wires[, params, n_wires, ...])

Perform the echoed cross-resonance gate.

echoedcrossresonance(q_device, wires[, ...])

Perform the echoed cross-resonance gate.