mindquantum.core.gates.gene_univ_two_params_gate
- mindquantum.core.gates.gene_univ_two_params_gate(name, matrix_generator, diff_matrix_generator_1, diff_matrix_generator_2)[source]
Generate a customer parameterized gate with two parameters.
Note
The elements in the matrix need to be explicitly written in complex number form, especially for multi qubits gate.
- Parameters
name (str) – The name of this gate.
matrix_generator (Union[FunctionType, MethodType]) – A function that takes two arguments to generate a unitary matrix.
diff_matrix_generator_1 (Union[FunctionType, MethodType]) – A function that takes two arguments to generate the derivative of matrix with respect to first parameter.
diff_matrix_generator_2 (Union[FunctionType, MethodType]) – A function that takes two arguments to generate the derivative of matrix with respect to second parameter.
- Returns
_TwoParamNonHerm, a customer parameterized gate with two parameters.
Examples
>>> import numpy as np >>> from mindquantum.core.gates import gene_univ_two_params_gate >>> from mindquantum.core.circuit import Circuit >>> def matrix(a, b): ... ep = 0.5 * (1 + np.exp(1j * a * b)) ... em = 0.5 * (1 - np.exp(1j * a * b)) ... return np.array([[ep, em], [em, ep]]) >>> def diff_matrix1(a, b): ... m = 0.5j * b * np.exp(1j * a * b) ... return np.array([[m, -m], [-m, m]]) >>> def diff_matrix2(a, b): ... m = 0.5j * a * np.exp(1j * a * b) ... return np.array([[m, -m], [-m, m]]) >>> TestGate = gene_univ_two_params_gate('Test', matrix, diff_matrix1, diff_matrix2) >>> circ = Circuit().x(0) >>> circ += TestGate('a', 'b').on(0) >>> circ.get_qs(pr={'a': 1.2, 'b': 0.8}) array([0.21324001-0.40959578j, 0.78675999+0.40959578j])