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)[源代码]
基于双参数幺正矩阵生成自定义参数化门。
说明
矩阵中的元素需要显示的定义为复数,特别是对于多比特门。
- 参数:
name (str) - 此门的名称。
matrix_generator (Union[FunctionType, MethodType]) - 采用两个参数生成幺正矩阵的函数或方法。
diff_matrix_generator_1 (Union[FunctionType, MethodType]) - 采用两个参数生成幺正矩阵对第一个参数的导数的函数或方法。
diff_matrix_generator_2 (Union[FunctionType, MethodType]) - 采用两个参数生成幺正矩阵对第二个参数的导数的函数或方法。
- 返回:
_TwoParamNonHerm,自定义的双参数化门。
样例:
>>> 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])