Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick fix #1385

Merged
merged 3 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions qiskit/quantum_info/operators/unitary.py

This file was deleted.

38 changes: 37 additions & 1 deletion test/python/quantum_info/test_quaternions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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