Skip to content

Commit

Permalink
quick fix (Qiskit#1385)
Browse files Browse the repository at this point in the history
* Adding quick fix

* Cleaning up

* Linting
  • Loading branch information
jaygambetta authored Nov 30, 2018
1 parent 7b5b99a commit 8cac29d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 49 deletions.
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

0 comments on commit 8cac29d

Please sign in to comment.