diff --git a/qiskit/quantum_info/operators/unitary.py b/qiskit/quantum_info/operators/unitary.py deleted file mode 100644 index 4732ea22d5f5..000000000000 --- a/qiskit/quantum_info/operators/unitary.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2018, IBM. -# -# This source code is licensed under the Apache License, Version 2.0 found in -# the LICENSE.txt file in the root directory of this source tree. - -""" -A module for common unitary matrix. -""" -import math -import numpy as np - - -def rotation_matrix(angle, axis): - """Generates a rotation matrix for a given angle and axis. - - Args: - angle (float): Rotation angle in radians. - axis (str): Axis for rotation: 'x', 'y', 'z' - - Returns: - ndarray: Rotation matrix. - - Raises: - ValueError: Invalid input axis. - """ - direction = np.zeros(3, dtype=float) - if axis == 'x': - direction[0] = 1 - elif axis == 'y': - direction[1] = 1 - elif axis == 'z': - direction[2] = 1 - else: - raise ValueError('Invalid axis.') - direction = np.asarray(direction, dtype=float) - sin_angle = math.sin(angle) - cos_angle = math.cos(angle) - rot = np.diag([cos_angle, cos_angle, cos_angle]) - rot += np.outer(direction, direction) * (1.0 - cos_angle) - direction *= sin_angle - rot += np.array([ - [0, -direction[2], direction[1]], - [direction[2], 0, -direction[0]], - [-direction[1], direction[0], 0] - ]) - return rot diff --git a/test/python/quantum_info/test_quaternions.py b/test/python/quantum_info/test_quaternions.py index 8bb1f81dad44..88acd1e24284 100644 --- a/test/python/quantum_info/test_quaternions.py +++ b/test/python/quantum_info/test_quaternions.py @@ -6,10 +6,10 @@ # the LICENSE.txt file in the root directory of this source tree. """Tests qiskit/mapper/_quaternion""" +import math import numpy as np import scipy.linalg as la from qiskit.quantum_info.operators.quaternion import quaternion_from_euler -from qiskit.quantum_info.operators.unitary import rotation_matrix from ..common import QiskitTestCase @@ -72,3 +72,39 @@ def test_equiv_quaternions(self): euler = quat1.to_zyz() quat2 = quaternion_from_euler(euler, 'zyz') self.assertTrue(np.allclose(abs(quat1.data.dot(quat2.data)), 1)) + + +def rotation_matrix(angle, axis): + """Generates a rotation matrix for a given angle and axis. + + Args: + angle (float): Rotation angle in radians. + axis (str): Axis for rotation: 'x', 'y', 'z' + + Returns: + ndarray: Rotation matrix. + + Raises: + ValueError: Invalid input axis. + """ + direction = np.zeros(3, dtype=float) + if axis == 'x': + direction[0] = 1 + elif axis == 'y': + direction[1] = 1 + elif axis == 'z': + direction[2] = 1 + else: + raise ValueError('Invalid axis.') + direction = np.asarray(direction, dtype=float) + sin_angle = math.sin(angle) + cos_angle = math.cos(angle) + rot = np.diag([cos_angle, cos_angle, cos_angle]) + rot += np.outer(direction, direction) * (1.0 - cos_angle) + direction *= sin_angle + rot += np.array([ + [0, -direction[2], direction[1]], + [direction[2], 0, -direction[0]], + [-direction[1], direction[0], 0] + ]) + return rot