:py:mod:`qsearch.gatesets` ========================== .. py:module:: qsearch.gatesets .. autoapi-nested-parse:: This module defines the Gateset class, which represents the allowed gates and topology for a specific quantum computer. Several Implementations of Gateset are also defined here. Several aliases are also defined, for the most common use cases. .. attribute:: ZXZXZCNOTLinear A Gateset that uses CNOT and the ZXZXZ single qubit parameterization with the linear topology. .. attribute:: U3CNOTLinear A Gateset that uses CNOT and the U3 single qubit parameterization with the linear topology. .. attribute:: QubitCNOTLinear A Gateset that uses CNOT and the U3 single qubit parameterization with the linear topology, except it uses an XZXZ instead of a U3 after the control qubit of each CNOT. This results in a gateset that covers the same search space as U3CNOTLinear, but with fewer redundant parameters, and therefore faster runtime. .. attribute:: QubitCNOTRing Uses U3 and XZXZ like QubitCNOTLinear, but includes a NonadjacentCNOTGate to add a link from the last qubit to the 0th. .. attribute:: QubitCNOTAdjacencyList Similar to QubitCNOTLinear and QubitCNOTRing, but takes in an adjacency list which uses NonadjacentCNOTGate to define work with a custom topology. .. attribute:: QutritCPIPhaseLinear A qutrit gateset that uses the CPIPhase gate as its two-qutrit gate, with a linear topology. .. attribute:: QutritCNOTLinear A qutrit gateset that uses an upgraded version of the CNOT gate as its two-qutrit gate, with a linear topology. .. attribute:: DefaultQubit The default Gateset for working with qubits. Currently is equivalent to QubitCNOTLinear. .. attribute:: DefaultQutrit The default Gateset for working with qutrits. Currently is equivalent to QutritCPIPhaseLinear. .. attribute:: Default The overall default Gateset, which is equivalent to DefaultQubit. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: qsearch.gatesets.Gateset qsearch.gatesets.ZXZXZCNOTLinear qsearch.gatesets.U3CNOTLinear qsearch.gatesets.QubitCNOTLinear qsearch.gatesets.QubitCNOTRing qsearch.gatesets.QubitCZLinear qsearch.gatesets.QubitISwapLinear qsearch.gatesets.QubitXXLinear qsearch.gatesets.QubitCNOTAdjacencyList qsearch.gatesets.QutritCPIPhaseLinear qsearch.gatesets.QutritCNOTLinear Functions ~~~~~~~~~ .. autoapisummary:: qsearch.gatesets.linear_topology qsearch.gatesets.fill_row qsearch.gatesets.find_last_3_cnots_linear Attributes ~~~~~~~~~~ .. autoapisummary:: qsearch.gatesets.DefaultQubit qsearch.gatesets.DefaultQutrit qsearch.gatesets.Default .. py:class:: Gateset This class defines the supported gates and topology for a specific quantum hardware. Gatesets must set the value of d in their initializer, which represents the size of qudits that are supported (e.g. 2 for qubits or 3 for qutrits). .. py:method:: initial_layer(qudits) The initial layer in the compilation. Usually a layer of parameterized single-qudit gates. :param qudits: The number of qudits in this circuit. :returns: A single Gate representing an initial layer for the circuit :rtype: qsearch.gates.Gate .. py:method:: search_layers(qudits) A set of possible multi-qubit gates for searching. Usually this is a two-qudit gate followed by two single-qudit gates, for every allowed placement of the two-qudit gate. This defines the branching factor of the search tree. :param qudits: The number of qudits in this circuit :returns: A list of tuples of (gate,weight) where Gate is the Gate representing that possible placement of the two-qudit gate, and weight is the weight or cost of adding that gate in that placement to the final circuit. :rtype: list .. py:method:: branching_factor(qudits) Returns an integer indicating the expected branching factor. Usually this is automatically determined from search_layers, but it may need to be overridden if successors is overridden. :param qudits: The number of qudits in this circuit :returns: An integer indicating the expecte branching factor :rtype: int .. py:method:: successors(circ, qudits=None) Returns a list of Gates that are successors in the search tree to the input Gate, circ, representing a current ansatz circuit. :param circ: The curret ansatz Gate. :param qudits: The number of qudits in this circuit. :returns: A list of tuples of (gate, weight) where gate is a Gate that is a successor to circ, and weight is the cost or weight of moving to gate from circ. :rtype: list .. py:method:: __eq__(other) Return self==value. .. py:class:: ZXZXZCNOTLinear Bases: :py:obj:`Gateset` A Gateset for working with CNOT and single-qubit gates parameterized with ZXZXZGate on the linear topology. Gatesets must set the value of d in their initializer, which represents the size of qudits that are supported (e.g. 2 for qubits or 3 for qutrits). .. py:method:: initial_layer(n) The initial layer in the compilation. Usually a layer of parameterized single-qudit gates. :param qudits: The number of qudits in this circuit. :returns: A single Gate representing an initial layer for the circuit :rtype: qsearch.gates.Gate .. py:method:: search_layers(n) A set of possible multi-qubit gates for searching. Usually this is a two-qudit gate followed by two single-qudit gates, for every allowed placement of the two-qudit gate. This defines the branching factor of the search tree. :param qudits: The number of qudits in this circuit :returns: A list of tuples of (gate,weight) where Gate is the Gate representing that possible placement of the two-qudit gate, and weight is the weight or cost of adding that gate in that placement to the final circuit. :rtype: list .. py:class:: U3CNOTLinear Bases: :py:obj:`Gateset` A Gateset for working with CNOT and single-qubit gates parameterized with U3Gate on the linear topology. Gatesets must set the value of d in their initializer, which represents the size of qudits that are supported (e.g. 2 for qubits or 3 for qutrits). .. py:method:: initial_layer(n) The initial layer in the compilation. Usually a layer of parameterized single-qudit gates. :param qudits: The number of qudits in this circuit. :returns: A single Gate representing an initial layer for the circuit :rtype: qsearch.gates.Gate .. py:method:: search_layers(n) A set of possible multi-qubit gates for searching. Usually this is a two-qudit gate followed by two single-qudit gates, for every allowed placement of the two-qudit gate. This defines the branching factor of the search tree. :param qudits: The number of qudits in this circuit :returns: A list of tuples of (gate,weight) where Gate is the Gate representing that possible placement of the two-qudit gate, and weight is the weight or cost of adding that gate in that placement to the final circuit. :rtype: list .. py:class:: QubitCNOTLinear(single_gate=U3Gate(), single_alt=XZXZGate()) Bases: :py:obj:`Gateset` A Gateset for working with CNOT and single-qubit gates parameterized with U3Gate and XZXZGate on the linear topology. This Gateset covers the same search space but uses fewer parameters than ZXZXZCNOTLinear and U3CNOTLinear. :param single_gate: A qsearch.gates.Gate object used as the single-qubit gate placed after the target side of a CNOT. :param single_alt: A qsearch.gates.Gate object used as the single-qubit gate placed after the control side of a CNOT. Gatesets must set the value of d in their initializer, which represents the size of qudits that are supported (e.g. 2 for qubits or 3 for qutrits). .. py:method:: initial_layer(n) The initial layer in the compilation. Usually a layer of parameterized single-qudit gates. :param qudits: The number of qudits in this circuit. :returns: A single Gate representing an initial layer for the circuit :rtype: qsearch.gates.Gate .. py:method:: search_layers(n) A set of possible multi-qubit gates for searching. Usually this is a two-qudit gate followed by two single-qudit gates, for every allowed placement of the two-qudit gate. This defines the branching factor of the search tree. :param qudits: The number of qudits in this circuit :returns: A list of tuples of (gate,weight) where Gate is the Gate representing that possible placement of the two-qudit gate, and weight is the weight or cost of adding that gate in that placement to the final circuit. :rtype: list .. py:method:: branching_factor(qudits) Returns an integer indicating the expected branching factor. Usually this is automatically determined from search_layers, but it may need to be overridden if successors is overridden. :param qudits: The number of qudits in this circuit :returns: An integer indicating the expecte branching factor :rtype: int .. py:method:: successors(circ, qudits=None) Returns a list of Gates that are successors in the search tree to the input Gate, circ, representing a current ansatz circuit. :param circ: The curret ansatz Gate. :param qudits: The number of qudits in this circuit. :returns: A list of tuples of (gate, weight) where gate is a Gate that is a successor to circ, and weight is the cost or weight of moving to gate from circ. :rtype: list .. py:class:: QubitCNOTRing(single_gate=U3Gate(), single_alt=XZXZGate()) Bases: :py:obj:`Gateset` A Gateset for working with CNOT and single-qubit gates parameterized with U3Gate and XZXZGate on the ring topology. :param single_gate: A qsearch.gates.Gate object used as the single-qubit gate placed after the target side of a CNOT. :param single_alt: A qsearch.gates.Gate object used as the single-qubit gate placed after the control side of a CNOT. Gatesets must set the value of d in their initializer, which represents the size of qudits that are supported (e.g. 2 for qubits or 3 for qutrits). .. py:method:: initial_layer(n) The initial layer in the compilation. Usually a layer of parameterized single-qudit gates. :param qudits: The number of qudits in this circuit. :returns: A single Gate representing an initial layer for the circuit :rtype: qsearch.gates.Gate .. py:method:: search_layers(n) A set of possible multi-qubit gates for searching. Usually this is a two-qudit gate followed by two single-qudit gates, for every allowed placement of the two-qudit gate. This defines the branching factor of the search tree. :param qudits: The number of qudits in this circuit :returns: A list of tuples of (gate,weight) where Gate is the Gate representing that possible placement of the two-qudit gate, and weight is the weight or cost of adding that gate in that placement to the final circuit. :rtype: list .. py:class:: QubitCZLinear Bases: :py:obj:`Gateset` A Gateset for working with CZ and single-qubit gates parameterized with U3Gate and XZXZGate on the linear topology. Gatesets must set the value of d in their initializer, which represents the size of qudits that are supported (e.g. 2 for qubits or 3 for qutrits). .. py:method:: initial_layer(n) The initial layer in the compilation. Usually a layer of parameterized single-qudit gates. :param qudits: The number of qudits in this circuit. :returns: A single Gate representing an initial layer for the circuit :rtype: qsearch.gates.Gate .. py:method:: search_layers(n) A set of possible multi-qubit gates for searching. Usually this is a two-qudit gate followed by two single-qudit gates, for every allowed placement of the two-qudit gate. This defines the branching factor of the search tree. :param qudits: The number of qudits in this circuit :returns: A list of tuples of (gate,weight) where Gate is the Gate representing that possible placement of the two-qudit gate, and weight is the weight or cost of adding that gate in that placement to the final circuit. :rtype: list .. py:method:: branching_factor(qudits) Returns an integer indicating the expected branching factor. Usually this is automatically determined from search_layers, but it may need to be overridden if successors is overridden. :param qudits: The number of qudits in this circuit :returns: An integer indicating the expecte branching factor :rtype: int .. py:method:: successors(circ, qudits=None) Returns a list of Gates that are successors in the search tree to the input Gate, circ, representing a current ansatz circuit. :param circ: The curret ansatz Gate. :param qudits: The number of qudits in this circuit. :returns: A list of tuples of (gate, weight) where gate is a Gate that is a successor to circ, and weight is the cost or weight of moving to gate from circ. :rtype: list .. py:class:: QubitISwapLinear Bases: :py:obj:`Gateset` A Gateset for working with ISwap and single-qubit gates parameterized with U3Gate and XZXZGate on the linear topology. Gatesets must set the value of d in their initializer, which represents the size of qudits that are supported (e.g. 2 for qubits or 3 for qutrits). .. py:method:: initial_layer(n) The initial layer in the compilation. Usually a layer of parameterized single-qudit gates. :param qudits: The number of qudits in this circuit. :returns: A single Gate representing an initial layer for the circuit :rtype: qsearch.gates.Gate .. py:method:: search_layers(n) A set of possible multi-qubit gates for searching. Usually this is a two-qudit gate followed by two single-qudit gates, for every allowed placement of the two-qudit gate. This defines the branching factor of the search tree. :param qudits: The number of qudits in this circuit :returns: A list of tuples of (gate,weight) where Gate is the Gate representing that possible placement of the two-qudit gate, and weight is the weight or cost of adding that gate in that placement to the final circuit. :rtype: list .. py:method:: branching_factor(qudits) Returns an integer indicating the expected branching factor. Usually this is automatically determined from search_layers, but it may need to be overridden if successors is overridden. :param qudits: The number of qudits in this circuit :returns: An integer indicating the expecte branching factor :rtype: int .. py:method:: successors(circ, qudits=None) Returns a list of Gates that are successors in the search tree to the input Gate, circ, representing a current ansatz circuit. :param circ: The curret ansatz Gate. :param qudits: The number of qudits in this circuit. :returns: A list of tuples of (gate, weight) where gate is a Gate that is a successor to circ, and weight is the cost or weight of moving to gate from circ. :rtype: list .. py:class:: QubitXXLinear Bases: :py:obj:`Gateset` A Gateset for working with ISwap and single-qubit gates parameterized with U3Gate and XZXZGate on the linear topology. Gatesets must set the value of d in their initializer, which represents the size of qudits that are supported (e.g. 2 for qubits or 3 for qutrits). .. py:method:: initial_layer(n) The initial layer in the compilation. Usually a layer of parameterized single-qudit gates. :param qudits: The number of qudits in this circuit. :returns: A single Gate representing an initial layer for the circuit :rtype: qsearch.gates.Gate .. py:method:: search_layers(n) A set of possible multi-qubit gates for searching. Usually this is a two-qudit gate followed by two single-qudit gates, for every allowed placement of the two-qudit gate. This defines the branching factor of the search tree. :param qudits: The number of qudits in this circuit :returns: A list of tuples of (gate,weight) where Gate is the Gate representing that possible placement of the two-qudit gate, and weight is the weight or cost of adding that gate in that placement to the final circuit. :rtype: list .. py:method:: branching_factor(qudits) Returns an integer indicating the expected branching factor. Usually this is automatically determined from search_layers, but it may need to be overridden if successors is overridden. :param qudits: The number of qudits in this circuit :returns: An integer indicating the expecte branching factor :rtype: int .. py:method:: successors(circ, qudits=None) Returns a list of Gates that are successors in the search tree to the input Gate, circ, representing a current ansatz circuit. :param circ: The curret ansatz Gate. :param qudits: The number of qudits in this circuit. :returns: A list of tuples of (gate, weight) where gate is a Gate that is a successor to circ, and weight is the cost or weight of moving to gate from circ. :rtype: list .. py:class:: QubitCNOTAdjacencyList(adjacency, single_gate=U3Gate(), single_alt=XZXZGate()) Bases: :py:obj:`Gateset` A Gateset for working with CNOT and single-qubit gates parameterized with U3Gate and XZXZGate on a custom topology, specified in the initializer. Allows the specification of a custom topology through an adjacency list. For example, this is how you would specifiy the ring topology for 3 qubits: `[(0,1), (1,2), (2,1)]` It is not recommended to add bi-directional links, because with the arbitrary parameterized single qubit gates everywhere, such links would be redundant. :param adjacency: A list of tuples specifying which CNOT placements are allowed. The tuples must be in the form of (control, target). :param single_gate: A qsearch.gates.Gate object used as the single-qubit gate placed after the target side of a CNOT. :param single_alt: A qsearch.gates.Gate object used as the single-qubit gate placed after the control side of a CNOT. .. py:method:: initial_layer(n) The initial layer in the compilation. Usually a layer of parameterized single-qudit gates. :param qudits: The number of qudits in this circuit. :returns: A single Gate representing an initial layer for the circuit :rtype: qsearch.gates.Gate .. py:method:: search_layers(n) A set of possible multi-qubit gates for searching. Usually this is a two-qudit gate followed by two single-qudit gates, for every allowed placement of the two-qudit gate. This defines the branching factor of the search tree. :param qudits: The number of qudits in this circuit :returns: A list of tuples of (gate,weight) where Gate is the Gate representing that possible placement of the two-qudit gate, and weight is the weight or cost of adding that gate in that placement to the final circuit. :rtype: list .. py:class:: QutritCPIPhaseLinear Bases: :py:obj:`Gateset` A Gateset for working with CPIPhase and single-qutrit gates on the linear topology. Gatesets must set the value of d in their initializer, which represents the size of qudits that are supported (e.g. 2 for qubits or 3 for qutrits). .. py:method:: initial_layer(n) The initial layer in the compilation. Usually a layer of parameterized single-qudit gates. :param qudits: The number of qudits in this circuit. :returns: A single Gate representing an initial layer for the circuit :rtype: qsearch.gates.Gate .. py:method:: search_layers(n) A set of possible multi-qubit gates for searching. Usually this is a two-qudit gate followed by two single-qudit gates, for every allowed placement of the two-qudit gate. This defines the branching factor of the search tree. :param qudits: The number of qudits in this circuit :returns: A list of tuples of (gate,weight) where Gate is the Gate representing that possible placement of the two-qudit gate, and weight is the weight or cost of adding that gate in that placement to the final circuit. :rtype: list .. py:class:: QutritCNOTLinear Bases: :py:obj:`Gateset` A hybrid Gateset for working with CNOT and single-qutrit gates on the linear topology. Gatesets must set the value of d in their initializer, which represents the size of qudits that are supported (e.g. 2 for qubits or 3 for qutrits). .. py:method:: initial_layer(n) The initial layer in the compilation. Usually a layer of parameterized single-qudit gates. :param qudits: The number of qudits in this circuit. :returns: A single Gate representing an initial layer for the circuit :rtype: qsearch.gates.Gate .. py:method:: search_layers(n) A set of possible multi-qubit gates for searching. Usually this is a two-qudit gate followed by two single-qudit gates, for every allowed placement of the two-qudit gate. This defines the branching factor of the search tree. :param qudits: The number of qudits in this circuit :returns: A list of tuples of (gate,weight) where Gate is the Gate representing that possible placement of the two-qudit gate, and weight is the weight or cost of adding that gate in that placement to the final circuit. :rtype: list .. py:function:: linear_topology(double_gate, single_gate, n, d, identity_gate=None, single_alt=None, double_weight=1, single_weight=0, skip_index=None) .. py:function:: fill_row(gate, n) .. py:function:: find_last_3_cnots_linear(circuit) .. py:data:: DefaultQubit .. py:data:: DefaultQutrit .. py:data:: Default