quimb.tensor.circuit.gates ========================== .. py:module:: quimb.tensor.circuit.gates .. autoapi-nested-parse:: Gate definitions, registries, and the ``Gate`` class for circuits. Attributes ---------- .. autoapisummary:: quimb.tensor.circuit.gates.ALL_GATES quimb.tensor.circuit.gates.ONE_QUBIT_GATES quimb.tensor.circuit.gates.TWO_QUBIT_GATES quimb.tensor.circuit.gates.ALL_PARAM_GATES quimb.tensor.circuit.gates.ONE_QUBIT_PARAM_GATES quimb.tensor.circuit.gates.TWO_QUBIT_PARAM_GATES quimb.tensor.circuit.gates.GATE_TAGS quimb.tensor.circuit.gates.GATE_SIZE quimb.tensor.circuit.gates.CONSTANT_GATES quimb.tensor.circuit.gates.PARAM_GATES quimb.tensor.circuit.gates.SPECIAL_GATES quimb.tensor.circuit.gates._MPS_METHODS Classes ------- .. autoapisummary:: quimb.tensor.circuit.gates.Gate Functions --------- .. autoapisummary:: quimb.tensor.circuit.gates.recursive_stack quimb.tensor.circuit.gates.register_constant_gate quimb.tensor.circuit.gates.register_param_gate quimb.tensor.circuit.gates.register_special_gate quimb.tensor.circuit.gates.rx_gate_param_gen quimb.tensor.circuit.gates.ry_gate_param_gen quimb.tensor.circuit.gates.rz_gate_param_gen quimb.tensor.circuit.gates.u3_gate_param_gen quimb.tensor.circuit.gates.u2_gate_param_gen quimb.tensor.circuit.gates.u1_gate_param_gen quimb.tensor.circuit.gates.cu3_param_gen quimb.tensor.circuit.gates.cu2_param_gen quimb.tensor.circuit.gates.cu1_param_gen quimb.tensor.circuit.gates.crx_param_gen quimb.tensor.circuit.gates.cry_param_gen quimb.tensor.circuit.gates.crz_param_gen quimb.tensor.circuit.gates.fsim_param_gen quimb.tensor.circuit.gates.fsimg_param_gen quimb.tensor.circuit.gates.givens_param_gen quimb.tensor.circuit.gates.givens2_param_gen quimb.tensor.circuit.gates.xx_plus_yy_param_gen quimb.tensor.circuit.gates.xx_minus_yy_param_gen quimb.tensor.circuit.gates.rxx_param_gen quimb.tensor.circuit.gates.ryy_param_gen quimb.tensor.circuit.gates.rzz_param_gen quimb.tensor.circuit.gates.su4_gate_param_gen quimb.tensor.circuit.gates.apply_swap quimb.tensor.circuit.gates.build_controlled_gate_htn quimb.tensor.circuit.gates._apply_controlled_gate_mps quimb.tensor.circuit.gates._apply_controlled_gate_htn quimb.tensor.circuit.gates._apply_controlled_gate_eager quimb.tensor.circuit.gates.apply_controlled_gate quimb.tensor.circuit.gates._cached_param_gate_build quimb.tensor.circuit.gates.sample_bitstring_from_prob_ndarray quimb.tensor.circuit.gates.rehearsal_dict quimb.tensor.circuit.gates.parse_to_gate Module Contents --------------- .. py:function:: recursive_stack(x) .. py:data:: ALL_GATES .. py:data:: ONE_QUBIT_GATES .. py:data:: TWO_QUBIT_GATES .. py:data:: ALL_PARAM_GATES .. py:data:: ONE_QUBIT_PARAM_GATES .. py:data:: TWO_QUBIT_PARAM_GATES .. py:data:: GATE_TAGS .. py:data:: GATE_SIZE .. py:data:: CONSTANT_GATES .. py:data:: PARAM_GATES .. py:data:: SPECIAL_GATES .. py:function:: register_constant_gate(name, G, num_qubits, tag=None) .. py:function:: register_param_gate(name, param_fn, num_qubits, tag=None) .. py:function:: register_special_gate(name, fn, num_qubits, tag=None, array=None) .. py:function:: rx_gate_param_gen(params) .. py:function:: ry_gate_param_gen(params) .. py:function:: rz_gate_param_gen(params) .. py:function:: u3_gate_param_gen(params) .. py:function:: u2_gate_param_gen(params) .. py:function:: u1_gate_param_gen(params) .. py:function:: cu3_param_gen(params) .. py:function:: cu2_param_gen(params) .. py:function:: cu1_param_gen(params) .. py:function:: crx_param_gen(params) Parametrized controlled X-rotation. .. py:function:: cry_param_gen(params) Parametrized controlled Y-rotation. .. py:function:: crz_param_gen(params) Parametrized controlled Z-rotation. .. py:function:: fsim_param_gen(params) .. py:function:: fsimg_param_gen(params) .. py:function:: givens_param_gen(params) .. py:function:: givens2_param_gen(params) .. py:function:: xx_plus_yy_param_gen(params) .. py:function:: xx_minus_yy_param_gen(params) .. py:function:: rxx_param_gen(params) Parametrized two qubit XX-rotation. .. math:: \mathrm{RXX}(\theta) = \exp(-i \frac{\theta}{2} X_i X_j) .. py:function:: ryy_param_gen(params) Parametrized two qubit YY-rotation. .. math:: \mathrm{RYY}(\theta) = \exp(-i \frac{\theta}{2} Y_i Y_j) .. py:function:: rzz_param_gen(params) Parametrized two qubit ZZ-rotation. .. math:: \mathrm{RZZ}(\theta) = \exp(-i \frac{\theta}{2} Z_i Z_j) .. py:function:: su4_gate_param_gen(params) See https://arxiv.org/abs/quant-ph/0308006 - Fig. 7. params: # theta1, phi1, lamda1, # theta2, phi2, lamda2, # theta3, phi3, lamda3, # theta4, phi4, lamda4, # t1, t2, t3, .. py:data:: _MPS_METHODS .. py:function:: apply_swap(psi, i, j, **gate_opts) .. py:function:: build_controlled_gate_htn(ncontrol, gate, upper_inds, lower_inds, tags_each=None, tags_all=None, bond_ind=None) Build a low rank hyper tensor network (CP-decomp like) representation of a multi controlled gate. .. py:function:: _apply_controlled_gate_mps(psi, gate, tags=None, **gate_opts) Apply a multi-controlled gate to a state represented as an MPS. .. py:function:: _apply_controlled_gate_htn(psi, gate, tags=None, propagate_tags='register', **gate_opts) .. py:function:: _apply_controlled_gate_eager(psi, gate, tags=None, **gate_opts) Apply a multi-controlled gate to a state whose gates are eagerly contracted (e.g. a dense statevector): insert the low-rank HTN representation of the gate, then contract the resulting tensor network back into the dense state. This avoids ever forming the full ``2**(2N)`` dense operator. .. py:function:: apply_controlled_gate(psi, gate, tags=None, contract='auto-split-gate', propagate_tags='register', **gate_opts) .. py:function:: _cached_param_gate_build(fn, params) .. py:class:: Gate(label, params, qubits=None, controls=None, round=None, parametrize=False) A simple class for storing the details of a quantum circuit gate. :param label: The name or 'identifier' of the gate. :type label: str :param params: The parameters of the gate. :type params: Iterable[float] :param qubits: Which qubits the gate acts on. :type qubits: Iterable[int], optional :param controls: Which qubits are the controls. :type controls: Iterable[int], optional :param round: If given, which round or layer the gate is part of. :type round: int, optional :param parametrize: Whether the gate will correspond to a parametrized tensor. :type parametrize: bool, optional .. py:attribute:: __slots__ :value: ('_label', '_params', '_qubits', '_controls', '_round', '_parametrize', '_tag', '_special',... .. py:attribute:: _label .. py:attribute:: _params .. py:attribute:: _round .. py:attribute:: _parametrize :value: False .. py:attribute:: _tag .. py:attribute:: _special .. py:attribute:: _constant .. py:attribute:: _array :value: None .. py:method:: from_raw(U, qubits=None, controls=None, round=None) :classmethod: .. py:method:: copy() .. py:property:: label .. py:property:: params .. py:property:: qubits .. py:property:: total_qubit_count .. py:property:: controls .. py:property:: round .. py:property:: special .. py:property:: parametrize .. py:property:: tag .. py:method:: copy_with(**kwargs) Take a copy of this gate but with some attributes changed. .. py:method:: build_array() Build the array representation of the gate. For controlled gates this *excludes* the control qubits. .. py:property:: array .. py:method:: build_mpo(L=None, **kwargs) Build an MPO representation of this gate. .. py:method:: __repr__() .. py:function:: sample_bitstring_from_prob_ndarray(p, seed=None) Sample a bitstring from n-dimensional tensor ``p`` of probabilities. .. rubric:: Examples >>> import numpy as np >>> p = np.zeros(shape=(2, 2, 2, 2, 2)) >>> p[0, 1, 0, 1, 1] = 1.0 >>> sample_bitstring_from_prob_ndarray(p) '01011' .. py:function:: rehearsal_dict(tn, tree) .. py:function:: parse_to_gate(gate_id, *gate_args, params=None, qubits=None, controls=None, gate_round=None, parametrize=None) Map all types of gate specification into a `Gate` object.