當前位置: 首頁>>代碼示例>>Python>>正文


Python sympy.eye方法代碼示例

本文整理匯總了Python中sympy.eye方法的典型用法代碼示例。如果您正苦於以下問題:Python sympy.eye方法的具體用法?Python sympy.eye怎麽用?Python sympy.eye使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sympy的用法示例。


在下文中一共展示了sympy.eye方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: prepare_channel_operator_list

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def prepare_channel_operator_list(ops_list):
        """
        Prepares a list of channel operators.

        Args:
            ops_list (List): The list of operators to prepare

        Returns:
            List: The channel operator list
        """
        # convert to sympy matrices and verify that each singleton is
        # in a tuple; also add identity matrix
        from sympy import Matrix, eye
        result = []
        for ops in ops_list:
            if not isinstance(ops, tuple) and not isinstance(ops, list):
                ops = [ops]
            result.append([Matrix(op) for op in ops])
        n = result[0][0].shape[0]  # grab the dimensions from the first element
        result = [[eye(n)]] + result
        return result

    # pylint: disable=invalid-name 
開發者ID:Qiskit,項目名稱:qiskit-aer,代碼行數:25,代碼來源:noise_transformation.py

示例2: test_cu3

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def test_cu3():
    E = eye(2)
    UPPER = Matrix([[1, 0], [0, 0]])
    LOWER = Matrix([[0, 0], [0, 1]])
    theta, phi, lambd = symbols("theta phi lambd")
    U = Circuit().rz(lambd)[0].ry(theta)[0].rz(phi)[0].run_with_sympy_unitary()

    actual_1 = Circuit().cu3(theta, phi, lambd)[0, 1].run(backend="sympy_unitary")
    expected_1 = reduce(TensorProduct, [E, UPPER]) + reduce(TensorProduct, [U, LOWER])
    print("actual")
    print(simplify(actual_1))
    print("expected")
    print(simplify(expected_1))
    print("diff")
    print(simplify(actual_1 - expected_1))
    assert simplify(actual_1 - expected_1) == zeros(4) 
開發者ID:Blueqat,項目名稱:Blueqat,代碼行數:18,代碼來源:test_sympy.py

示例3: test_cu3_realvalue

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def test_cu3_realvalue():
    E = eye(2)
    UPPER = Matrix([[1, 0], [0, 0]])
    LOWER = Matrix([[0, 0], [0, 1]])
    theta = pi * 7 / 11
    phi = pi * 5 / 13
    lambd = pi * 8 / 17
    U = Circuit().u3(theta, phi, lambd)[0].run_with_sympy_unitary()
    expected_1 = reduce(TensorProduct, [E, UPPER]) + reduce(TensorProduct, [U, LOWER])
    print(expected_1)

    for i in range(4):
        c = Circuit()
        if i % 2 == 1:
            c.x[0]
        if (i // 2) % 2 == 1:
            c.x[1]
        actual_i = c.cu3(theta.evalf(), phi.evalf(), lambd.evalf())[0, 1].run_with_numpy()
        actual_i = np.array(actual_i).astype(complex).reshape(-1)
        expected_i = np.array(expected_1.col(i)).astype(complex).reshape(-1)
        assert 0.99999 < np.abs(np.dot(actual_i.conj(), expected_i)) < 1.00001 
開發者ID:Blueqat,項目名稱:Blueqat,代碼行數:23,代碼來源:test_sympy.py

示例4: rotation_to_matrix

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def rotation_to_matrix(w):
  wx,wy,wz = w
  theta = sp.sqrt(wx**2 + wy**2 + wz**2 + wy**2 + wz**2) + EPS
  omega = sp.Matrix([[0,-wz,wy],
                     [wz,0,-wx],
                     [-wy,wx,0]])
  R = sp.eye(3) +\
    omega*(sp.sin(theta)/theta) +\
    (omega*omega)*((1-sp.cos(theta))/(theta*theta))
  return R 
開發者ID:geohot,項目名稱:twitchslam,代碼行數:12,代碼來源:optimize_crappy.py

示例5: to_transformation_matrix

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def to_transformation_matrix(translation, orientation_matrix=np.zeros((3, 3))):
    """Convert a tuple (translation_vector, orientation_matrix) to a transformation matrix

    Parameters
    ----------
    translation: numpy.array
        The translation of your frame presented as a 3D vector.
    orientation_matrix: numpy.array
        Optional : The orientation of your frame, presented as a 3x3 matrix.
    """
    matrix = np.eye(4)

    matrix[:-1, :-1] = orientation_matrix
    matrix[:-1, -1] = translation
    return matrix 
開發者ID:Phylliade,項目名稱:ikpy,代碼行數:17,代碼來源:geometry.py

示例6: cartesian_to_homogeneous

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def cartesian_to_homogeneous(cartesian_matrix, matrix_type="numpy"):
    """Converts a cartesian matrix to an homogenous matrix"""
    dimension_x, dimension_y = cartesian_matrix.shape
    # Square matrix
    # Manage different types fo input matrixes
    if matrix_type == "numpy":
        homogeneous_matrix = np.eye(dimension_x + 1)
    elif matrix_type == "sympy":
        homogeneous_matrix = sympy.eye(dimension_x + 1)
    else:
        raise ValueError("Unknown matrix_type: {}".format(matrix_type))
    # Add a column filled with 0 and finishing with 1 to the cartesian matrix to transform it into an homogeneous one
    homogeneous_matrix[:-1, :-1] = cartesian_matrix

    return homogeneous_matrix 
開發者ID:Phylliade,項目名稱:ikpy,代碼行數:17,代碼來源:geometry.py

示例7: get_generating_function

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def get_generating_function(f, T=None):
    """
    Get the generating function

    :param f: function addr
    :param T: edges matrix of the function f
    :return: the generating function
    """

    if not T:
        edges = [(a[0].addr, a[1].addr) for a in f.graph.edges()]
        N = sorted([x for x in f.block_addrs])
        T = []
        for b1 in N:
            T.append([])
            for b2 in N:
                if b1 == b2 or (b1, b2) in edges:
                    T[-1].append(1)
                else:
                    T[-1].append(0)
    else:
        N = T[0]

    T = sympy.Matrix(T)
    z = sympy.var('z')
    I = sympy.eye(len(N))

    tmp = I - z * T
    tmp.row_del(len(N) - 1)
    tmp.col_del(0)
    det_num = tmp.det()
    det_den = (I - z * T).det()
    quot = det_num / det_den
    g_z = ((-1) ** (len(N) + 1)) * quot
    return g_z 
開發者ID:ucsb-seclab,項目名稱:karonte,代碼行數:37,代碼來源:utils.py

示例8: test_dagger_unitary

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def test_dagger_unitary(circuit):
    circuit += circuit.dagger()
    u = sympy.simplify(sympy.trigsimp(circuit.to_unitary()))
    s1, s2 = u.shape
    assert s1 == s2
    assert u == sympy.eye(s1) 
開發者ID:Blueqat,項目名稱:Blueqat,代碼行數:8,代碼來源:test_dagger.py

示例9: test_dagger_unitary2

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def test_dagger_unitary2():
    c = Circuit().h[0].s[0]
    c += c.dagger()
    u = sympy.simplify(c.to_unitary())
    assert u.shape == (2, 2)
    assert u == sympy.eye(2) 
開發者ID:Blueqat,項目名稱:Blueqat,代碼行數:8,代碼來源:test_dagger.py

示例10: test_sympy_backend_for_one_qubit_gate

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def test_sympy_backend_for_one_qubit_gate():
    E = eye(2)
    X = Matrix([[0, 1], [1, 0]])
    Y = Matrix([[0, -I], [I, 0]])
    Z = Matrix([[1, 0], [0, -1]])
    H = Matrix([[1, 1], [1, -1]]) / sqrt(2)
    T = Matrix([[1, 0], [0, exp(I*pi/4)]])
    S = Matrix([[1, 0], [0, exp(I*pi/2)]])

    x, y, z = symbols('x, y, z')
    RX = Matrix([[cos(x / 2), -I * sin(x / 2)], [-I * sin(x / 2), cos(x / 2)]])
    RY = Matrix([[cos(y / 2), -sin(y / 2)], [sin(y / 2), cos(y / 2)]])
    RZ = Matrix([[exp(-I * z / 2), 0], [0, exp(I * z / 2)]])

    actual_1 = Circuit().x[0, 1].y[1].z[2].run(backend="sympy_unitary")
    expected_1 = reduce(TensorProduct, [Z, Y * X, X])
    assert actual_1 == expected_1

    actual_2 = Circuit().y[0].z[3].run(backend="sympy_unitary")
    expected_2 = reduce(TensorProduct, [Z, E, E, Y])
    assert actual_2 == expected_2

    actual_3 = Circuit().x[0].z[3].h[:].t[1].s[2].run(backend="sympy_unitary")
    expected_3 = reduce(TensorProduct, [H * Z, S * H, T * H, H * X])
    assert actual_3 == expected_3

    actual_4 = Circuit().rx(-pi / 2)[0].rz(pi / 2)[1].ry(pi)[2].run(backend="sympy_unitary")
    expected_4 = reduce(TensorProduct, [RY, RZ, RX]).subs([[x, -pi / 2], [y, pi], [z, pi / 2]])
    assert actual_4 == expected_4 
開發者ID:Blueqat,項目名稱:Blueqat,代碼行數:31,代碼來源:test_sympy.py

示例11: test_cu1

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def test_cu1():
    E = eye(2)
    UPPER = Matrix([[1, 0], [0, 0]])
    LOWER = Matrix([[0, 0], [0, 1]])
    lambd = symbols("lambd")
    U = Circuit().rz(lambd)[0].run_with_sympy_unitary()
    U /= U[0, 0]

    actual_1 = Circuit().cu1(lambd)[0, 1].run(backend="sympy_unitary")
    actual_1 /= actual_1[0, 0]
    expected_1 = reduce(TensorProduct, [UPPER, E]) + reduce(TensorProduct, [LOWER, U])
    assert simplify(actual_1 - expected_1) == zeros(4) 
開發者ID:Blueqat,項目名稱:Blueqat,代碼行數:14,代碼來源:test_sympy.py

示例12: test_cswapgate

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def test_cswapgate():
    expected = eye(8)
    expected[4:, 4:] = Circuit().swap[1, 0].to_unitary()
    assert simplify(Circuit().cswap[2, 1, 0].to_unitary() - expected) == zeros(8) 
開發者ID:Blueqat,項目名稱:Blueqat,代碼行數:6,代碼來源:test_sympy.py

示例13: lazy_import

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def lazy_import():
    global eye, symbols, sin, cos, exp, sqrt, pi, I, Matrix, sympy_gate, TensorProduct, sympy
    from sympy import eye, symbols, sin, cos, exp, sqrt, pi, I, Matrix
    from sympy.physics.quantum import TensorProduct
    import sympy 
開發者ID:Blueqat,項目名稱:Blueqat,代碼行數:7,代碼來源:sympy_backend.py

示例14: __init__

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def __init__(self, n_qubits, ignore_global):
        self.n_qubits = n_qubits
        self.matrix_of_circuit = eye(2 ** n_qubits)
        self.ignore_global = ignore_global 
開發者ID:Blueqat,項目名稱:Blueqat,代碼行數:6,代碼來源:sympy_backend.py

示例15: test_sympy_backend_for_two_qubit_gate

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import eye [as 別名]
def test_sympy_backend_for_two_qubit_gate():
    E = eye(2)
    UPPER = Matrix([[1, 0], [0, 0]])
    LOWER = Matrix([[0, 0], [0, 1]])
    X = Matrix([[0, 1], [1, 0]])
    Z = Matrix([[1, 0], [0, -1]])
    H = Matrix([[1, 1], [1, -1]]) / sqrt(2)
    H_3 = reduce(TensorProduct, [H, E, H])
    H_4 = reduce(TensorProduct, [H, E, E, H])
    CX_3 = reduce(TensorProduct, [E, E, UPPER]) + reduce(TensorProduct, [X, E, LOWER])
    CZ_3 = reduce(TensorProduct, [E, E, UPPER]) + reduce(TensorProduct, [Z, E, LOWER])
    CX_4 = reduce(TensorProduct, [E, E, E, UPPER]) + reduce(TensorProduct, [X, E, E, LOWER])
    CZ_4 = reduce(TensorProduct, [E, E, E, UPPER]) + reduce(TensorProduct, [Z, E, E, LOWER])

    actual_1 = Circuit().cx[0, 3].run(backend="sympy_unitary")
    assert actual_1 == CX_4

    actual_2 = Circuit().cx[1, 3].x[4].run(backend="sympy_unitary")
    expected_2 = reduce(TensorProduct, [X, CX_3, E])
    assert actual_2 == expected_2

    actual_3 = Circuit().cz[0, 3].run(backend="sympy_unitary")
    assert actual_3 == CZ_4

    actual_4 = Circuit().cz[1, 3].x[4].run(backend="sympy_unitary")
    expected_4 = reduce(TensorProduct, [X, CZ_3, E])
    assert actual_4 == expected_4

    actual_5 = Circuit().cx[3, 0].run(backend="sympy_unitary")
    assert actual_5 == H_4 * CX_4 * H_4

    actual_6 = Circuit().cx[3, 1].x[4].run(backend="sympy_unitary")
    assert actual_6 == reduce(TensorProduct, [X, H_3 * CX_3 * H_3, E])

    actual_7 = Circuit().cz[3, 0].run(backend="sympy_unitary")
    assert actual_7 == CZ_4

    actual_8 = Circuit().cz[3, 1].x[4].run(backend="sympy_unitary")
    assert actual_8 == reduce(TensorProduct, [X, CZ_3, E])

    x, y, z = symbols('x, y, z')
    RX = Matrix([[cos(x / 2), -I * sin(x / 2)], [-I * sin(x / 2), cos(x / 2)]])
    RY = Matrix([[cos(y / 2), -sin(y / 2)], [sin(y / 2), cos(y / 2)]])
    RZ = Matrix([[exp(-I * z / 2), 0], [0, exp(I * z / 2)]])
    CRX_3 = reduce(TensorProduct, [UPPER, E, E]) + reduce(TensorProduct, [LOWER, E, RX])
    CRY_4 = reduce(TensorProduct, [E, UPPER, E, E]) + reduce(TensorProduct, [E, LOWER, RY, E])
    CRZ_3 = reduce(TensorProduct, [E, E, UPPER]) + reduce(TensorProduct, [RZ, E, LOWER])

    actual_9 = Circuit().crx(x)[2, 0].run(backend="sympy_unitary")
    assert simplify(actual_9) == CRX_3

    actual_10 = Circuit().cry(y)[2, 1].i[3].run(backend="sympy_unitary")
    assert simplify(actual_10) == CRY_4

    actual_11 = Circuit().crz(z)[0, 2].run(backend="sympy_unitary")
    assert simplify(actual_11) == CRZ_3 
開發者ID:Blueqat,項目名稱:Blueqat,代碼行數:58,代碼來源:test_sympy.py


注:本文中的sympy.eye方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。