:py:mod:`qsearch.gates` ======================= .. py:module:: qsearch.gates .. autoapi-nested-parse:: This module defines the Gate class, which represents a quantum gate, as well as implementations of many common Gates. Through the use of KroneckerGate and ProductGate, Gates can be formed for complex circuit structures. The matrix and mat_jac functions are used for numerical optimization of parameterized gates. The assemble function is used to generate an intermediate language of tuples that can be used by Assemblers to output descriptions of quantum circuits in other formats. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: qsearch.gates.Gate qsearch.gates.IdentityGate qsearch.gates.XGate qsearch.gates.YGate qsearch.gates.ZGate qsearch.gates.SXGate qsearch.gates.ZXZXZGate qsearch.gates.XZXZGate qsearch.gates.U3Gate qsearch.gates.U2Gate qsearch.gates.U1Gate qsearch.gates.SingleQutritGate qsearch.gates.CSUMGate qsearch.gates.CPIGate qsearch.gates.CPIPhaseGate qsearch.gates.CNOTGate qsearch.gates.CZGate qsearch.gates.ISwapGate qsearch.gates.XXGate qsearch.gates.NonadjacentCNOTGate qsearch.gates.UGate qsearch.gates.UpgradedConstantGate qsearch.gates.CUGate qsearch.gates.CNOTRootGate qsearch.gates.KroneckerGate qsearch.gates.ProductGate Attributes ~~~~~~~~~~ .. autoapisummary:: qsearch.gates.native_from_object .. py:data:: native_from_object .. py:class:: Gate This class shows the framework for working with quantum gates in Qsearch. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:method:: matrix(v) :abstractmethod: Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: mat_jac(v) Generates a matrix and the jacobian(s) using the given vector of input parameters. It is not required to implement mat_jac for constant gates, nor is it required when using gradient-free Solvers. The jacobian matrices will be complex valued, and should be the elementwise partial derivative with respect to each of the parameters. There should be self.num_inputs matrices in the array, with the ith entry being the partial derivative with respect to v[i]. See U3Gate for an example implementation. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A tuple of the same unitary that would be returned by matrix(v), and an array of Jacobian matrices. :rtype: tuple .. py:method:: assemble(v, i=0) :abstractmethod: Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __eq__(other) Return self==value. .. py:method:: __hash__() Return hash(self). .. py:method:: copy() .. py:method:: _parts() .. py:method:: __copy__() .. py:method:: __deepcopy__(memo) .. py:method:: __repr__() Return repr(self). .. py:method:: validate_structure() .. py:class:: IdentityGate(qudits=1, d=2) Bases: :py:obj:`Gate` Represents an identity gate of any number of qudits of any size. :param qudits: The number of qudits represented by this identity. :param d: The size of qudits represented by this identity (2 for qubits, 3 for qutrits, etc.) .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: XGate Bases: :py:obj:`Gate` Represents a parameterized X rotation on one qubit. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: mat_jac(v) Generates a matrix and the jacobian(s) using the given vector of input parameters. It is not required to implement mat_jac for constant gates, nor is it required when using gradient-free Solvers. The jacobian matrices will be complex valued, and should be the elementwise partial derivative with respect to each of the parameters. There should be self.num_inputs matrices in the array, with the ith entry being the partial derivative with respect to v[i]. See U3Gate for an example implementation. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A tuple of the same unitary that would be returned by matrix(v), and an array of Jacobian matrices. :rtype: tuple .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: YGate Bases: :py:obj:`Gate` Represents a parameterized Y rotation on one qubit. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: mat_jac(v) Generates a matrix and the jacobian(s) using the given vector of input parameters. It is not required to implement mat_jac for constant gates, nor is it required when using gradient-free Solvers. The jacobian matrices will be complex valued, and should be the elementwise partial derivative with respect to each of the parameters. There should be self.num_inputs matrices in the array, with the ith entry being the partial derivative with respect to v[i]. See U3Gate for an example implementation. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A tuple of the same unitary that would be returned by matrix(v), and an array of Jacobian matrices. :rtype: tuple .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: ZGate Bases: :py:obj:`Gate` Represents a parameterized Z rotation on one qubit. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: mat_jac(v) Generates a matrix and the jacobian(s) using the given vector of input parameters. It is not required to implement mat_jac for constant gates, nor is it required when using gradient-free Solvers. The jacobian matrices will be complex valued, and should be the elementwise partial derivative with respect to each of the parameters. There should be self.num_inputs matrices in the array, with the ith entry being the partial derivative with respect to v[i]. See U3Gate for an example implementation. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A tuple of the same unitary that would be returned by matrix(v), and an array of Jacobian matrices. :rtype: tuple .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: SXGate Bases: :py:obj:`Gate` Represents a sqrt(X) rotation on one qubit, which is equivalent to XGate() with a paramter of pi/2, up to an overall phase. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: ZXZXZGate Bases: :py:obj:`Gate` Represents an arbitrary parameterized single-qubit gate, decomposed into 3 parameterized Z gates separated by X(PI/2) gates. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: mat_jac(v) Generates a matrix and the jacobian(s) using the given vector of input parameters. It is not required to implement mat_jac for constant gates, nor is it required when using gradient-free Solvers. The jacobian matrices will be complex valued, and should be the elementwise partial derivative with respect to each of the parameters. There should be self.num_inputs matrices in the array, with the ith entry being the partial derivative with respect to v[i]. See U3Gate for an example implementation. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A tuple of the same unitary that would be returned by matrix(v), and an array of Jacobian matrices. :rtype: tuple .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: XZXZGate Bases: :py:obj:`Gate` Represents a partially parameterized single qubit gate, equivalent to ZXZXZ but without the first Z gate. This is useful because that first Z gate can commute through the control of a CNOT, thereby reducing the number of parameters we need to solve for. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: mat_jac(v) Generates a matrix and the jacobian(s) using the given vector of input parameters. It is not required to implement mat_jac for constant gates, nor is it required when using gradient-free Solvers. The jacobian matrices will be complex valued, and should be the elementwise partial derivative with respect to each of the parameters. There should be self.num_inputs matrices in the array, with the ith entry being the partial derivative with respect to v[i]. See U3Gate for an example implementation. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A tuple of the same unitary that would be returned by matrix(v), and an array of Jacobian matrices. :rtype: tuple .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: U3Gate Bases: :py:obj:`Gate` Represents an arbitrary parameterized single qubit gate, parameterized in the same way as IBM's U3 gate. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: mat_jac(v) Generates a matrix and the jacobian(s) using the given vector of input parameters. It is not required to implement mat_jac for constant gates, nor is it required when using gradient-free Solvers. The jacobian matrices will be complex valued, and should be the elementwise partial derivative with respect to each of the parameters. There should be self.num_inputs matrices in the array, with the ith entry being the partial derivative with respect to v[i]. See U3Gate for an example implementation. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A tuple of the same unitary that would be returned by matrix(v), and an array of Jacobian matrices. :rtype: tuple .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __eq__(other) Return self==value. .. py:method:: __repr__() Return repr(self). .. py:class:: U2Gate Bases: :py:obj:`Gate` Represents a parameterized single qubit gate, parameterized in the same way as IBM's U2 gate. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: mat_jac(v) Generates a matrix and the jacobian(s) using the given vector of input parameters. It is not required to implement mat_jac for constant gates, nor is it required when using gradient-free Solvers. The jacobian matrices will be complex valued, and should be the elementwise partial derivative with respect to each of the parameters. There should be self.num_inputs matrices in the array, with the ith entry being the partial derivative with respect to v[i]. See U3Gate for an example implementation. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A tuple of the same unitary that would be returned by matrix(v), and an array of Jacobian matrices. :rtype: tuple .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __eq__(other) Return self==value. .. py:method:: __repr__() Return repr(self). .. py:class:: U1Gate Bases: :py:obj:`Gate` Represents an parameterized single qubit gate, parameterized in the same way as IBM's U1 gate. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: mat_jac(v) Generates a matrix and the jacobian(s) using the given vector of input parameters. It is not required to implement mat_jac for constant gates, nor is it required when using gradient-free Solvers. The jacobian matrices will be complex valued, and should be the elementwise partial derivative with respect to each of the parameters. There should be self.num_inputs matrices in the array, with the ith entry being the partial derivative with respect to v[i]. See U3Gate for an example implementation. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A tuple of the same unitary that would be returned by matrix(v), and an array of Jacobian matrices. :rtype: tuple .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __eq__(other) Return self==value. .. py:method:: __repr__() Return repr(self). .. py:class:: SingleQutritGate Bases: :py:obj:`Gate` This gate represents an arbitrary parameterized single-qutrit gate. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: mat_jac(v) Generates a matrix and the jacobian(s) using the given vector of input parameters. It is not required to implement mat_jac for constant gates, nor is it required when using gradient-free Solvers. The jacobian matrices will be complex valued, and should be the elementwise partial derivative with respect to each of the parameters. There should be self.num_inputs matrices in the array, with the ith entry being the partial derivative with respect to v[i]. See U3Gate for an example implementation. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A tuple of the same unitary that would be returned by matrix(v), and an array of Jacobian matrices. :rtype: tuple .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: CSUMGate Bases: :py:obj:`Gate` Represents the constant two-qutrit gate CSUM Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:attribute:: _csum .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: CPIGate Bases: :py:obj:`Gate` Represents the constant two-qutrit gate CPI. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:attribute:: _cpi .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: CPIPhaseGate Bases: :py:obj:`Gate` Represents the constant two-qutrit gate CPI with phase differences. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: CNOTGate Bases: :py:obj:`Gate` Represents the constant two-qubit gate CNOT. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:attribute:: _cnot .. py:method:: __eq__(other) Return self==value. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: CZGate Bases: :py:obj:`Gate` Represents the constant two-qubit gate Controlled-Z. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:attribute:: _gate .. py:method:: __eq__(other) Return self==value. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: ISwapGate Bases: :py:obj:`Gate` Represents the constant two-qubit gate ISwap. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:attribute:: _gate .. py:method:: __eq__(other) Return self==value. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: XXGate Bases: :py:obj:`Gate` Represents the constant two-qubit gate XX(pi/2). Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:attribute:: _gate .. py:method:: __eq__(other) Return self==value. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: NonadjacentCNOTGate(qudits, control, target) Bases: :py:obj:`Gate` Represents the two-qubit gate CNOT, but between two qubits that are not necessarily next to each other. :param qudits: The total number of qubits that a unitary of the size returned by this gate would represent. For this gate, usually this is the total number of qubits in the larger circuit. :param control: The index of the control qubit, relative to the 0th qubit that would be affected by the unitary returned by this gate. :param target: The index of the target qubit, relative to the 0th qubit that would be affected by the unitary returned by this gate. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:method:: validate_structure() .. py:class:: UGate(U, d=2, gatename='CUSTOM', gateparams=(), gateindices=None) Bases: :py:obj:`Gate` Represents an arbitrary constant gate, defined by the unitary passed to the initializer. :param U: The unitary for the operation that this gate represents, as a numpy ndarray with datatype="complex128". :param d: The size of qudits for the operation that this gate represents. The default is 2, for qubits. :param gatename: A name for this gate, which will get passed to the Assembler at assembly time. :param gateparams: A tuple of parameters that will get passed to the Assembler at assembly time. :param gateindices: A tuple of indices for the qubits that this gate acts on, which will get passed to the Assembler at assembly time. This overrides the default behavior, which is to return a tuple of all the indices starting with the one passed in assemble(v, i), and ending at i+self.qudits .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: UpgradedConstantGate(other, df=3) Bases: :py:obj:`Gate` Represents a constant gate, based on the Gate passed to its initializer, but upgraded to act on qudits of a larger size. :param other: A Gate of a lower qudit size. :param df: The final, upgraded qudit size. The default is 3, for upgrading gates from qubits to qutrits. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: CUGate(U, gatename='Name', gateparams=(), flipped=False) Bases: :py:obj:`Gate` Represents an arbitrary controlled gate, defined by the unitary passed to the initializer. :param U: The unitary to form the controlled-unitary gate, in the form of a numpy ndarray with dtype="complex128" :param gatename: A name for this controlled gate which will get passed to the Assembler at assembly time. :param gateparams: A tuple of parameters that will get passed to the Assembler at assembly time. :param flipped: A boolean flag, which if set to true, will flip the direction of the gate. The default direction is for the control qubit to be the lower indexed qubit. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: CNOTRootGate Bases: :py:obj:`Gate` Represents the sqrt(CNOT) gate. Two sqrt(CNOT) gates in a row will form a CNOT gate. Gates must set the following variables in __init__ self.num_inputs : The number of parameters needed to generate a unitary. This can be 0. self.qudits : The number of qudits acted on by a unitary of the size generated by the gate. For example, this would be 1 for U3, 2 for CNOT. .. py:attribute:: _cnr .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: __repr__() Return repr(self). .. py:class:: KroneckerGate(*subgates) Bases: :py:obj:`Gate` Represents the Kronecker product of a list of gates. This is equivalent to performing those gate in parallel in a quantum circuit. :param \*subgates: An sequence of Gates. KroneckerGate will return the kronecker product of the unitaries returned by those Gates. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: mat_jac(v) Generates a matrix and the jacobian(s) using the given vector of input parameters. It is not required to implement mat_jac for constant gates, nor is it required when using gradient-free Solvers. The jacobian matrices will be complex valued, and should be the elementwise partial derivative with respect to each of the parameters. There should be self.num_inputs matrices in the array, with the ith entry being the partial derivative with respect to v[i]. See U3Gate for an example implementation. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A tuple of the same unitary that would be returned by matrix(v), and an array of Jacobian matrices. :rtype: tuple .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: appending(gate) Returns a new KroneckerGate with the new gate added to the list. :param gate: A Gate to be added to the end of the list of gates in the new KroneckerGate. .. py:method:: _parts() .. py:method:: __deepcopy__(memo) .. py:method:: __repr__() Return repr(self). .. py:method:: validate_structure() .. py:class:: ProductGate(*subgates) Bases: :py:obj:`Gate` Represents a matrix product of Gates. This is equivalent to performing those gates sequentially in a quantum circuit. :param subgates: A list of Gates to be multiplied together. ProductGate returns the matrix product of the unitaries returned by those Gates. .. py:method:: matrix(v) Generates a matrix using the given vector of input parameters. For a constant gate, v will be empty. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A unitary matrix with dtype="complex128", equal in size to d**self.qudits, where d is the intended qudit size (d is 2 for qubits, 3 for qutrits, etc.) :rtype: np.ndarray .. py:method:: mat_jac(v) Generates a matrix and the jacobian(s) using the given vector of input parameters. It is not required to implement mat_jac for constant gates, nor is it required when using gradient-free Solvers. The jacobian matrices will be complex valued, and should be the elementwise partial derivative with respect to each of the parameters. There should be self.num_inputs matrices in the array, with the ith entry being the partial derivative with respect to v[i]. See U3Gate for an example implementation. :param v: A numpy array of real floating point numbers, ranging from 0 to 2*PI. Its size is equal to self.num_inputs :returns: A tuple of the same unitary that would be returned by matrix(v), and an array of Jacobian matrices. :rtype: tuple .. py:method:: assemble(v, i=0) Generates an array of tuples as an intermediate format before being processed by an Assembler for conversion to other circuit formats. :param v: The same numpy array of real floating point numbers that might be passed to matrix(v). :param i: The index of the lowest-indexed qubit that the unitary generated by the gate acts on. :returns: A list of tuples following the format described above. :rtype: list The format of the tuples returned looks like: `("gate", gatename, (*gateparameters), (*gateindices))` Where `gatename` corresponds to a gate that an Assembler will recognize, `gateparameters` corresponds to the parameters for the specified gate (usually but not always calculated from v), and `gateindices` corresponds to the qubit indices that the gate acts on (usually but not always calculated from i). You can also have tuples of the form ("block", *tuples) Where tuples is an array of tuples in this same format. For some helpful examples, look at U3Gate, XZXZGate, CNOTGate, and NonadjacentCNOTGate. .. py:method:: appending(*gates) Returns a new ProductGate with the new gates appended to the end. :param gates: A list of Gates to be appended. .. py:method:: inserting(*gates, depth=-1) Returns a new ProductGate with new `gates` inserted at some index `depth`. :param gates: A list of Gates to be inserted. :param depth: An index in the subgates of the ProductGate after which the new gates will be inserted. The default value of -1 will insert these gates at the begining of the ProductGate. .. py:method:: __deepcopy__(memo) .. py:method:: __repr__() Return repr(self). .. py:method:: validate_structure()