Skip to content

Commit

Permalink
renamed qiskit_simulator extensions to qasm_simulator_cpp, added basi…
Browse files Browse the repository at this point in the history
…c tests
  • Loading branch information
chriseclectic committed Apr 4, 2018
1 parent 3d58337 commit 3a2dbde
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions qiskit/backends/_qasm_simulator_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class QASMSimulatorEncoder(json.JSONEncoder):
complex numbers z as lists [z.real, z.imag]
ndarrays as nested lists.
"""

# pylint: disable=method-hidden,arguments-differ
def default(self, obj):
if isinstance(obj, np.ndarray):
return obj.tolist()
Expand All @@ -159,7 +161,10 @@ class QASMSimulatorDecoder(json.JSONDecoder):
def __init__(self, *args, **kwargs):
json.JSONDecoder.__init__(self, object_hook=self.object_hook, *args, **kwargs)

# pylint: disable=method-hidden
def object_hook(self, obj):
"""Special decoding rules for simulator output."""

for key in ['U_error', 'density_matrix']:
# JSON is a complex matrix
if key in obj and isinstance(obj[key], list):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
from .load import load
from .noise import noise
from .save import save
from .uzz import uzz
from .snapshot import snapshot
from .rzz import rzz
from .wait import wait
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


class RZZGate(Gate):
"""Two-qubit ZZ-rotation gate."""

def __init__(self, theta, ctl, tgt, circ=None):
"""Create new rzz gate."""
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ packages = ["qiskit",
"qiskit.dagcircuit",
"qiskit.extensions",
"qiskit.extensions.standard",
"qiskit.extensions.qiskit_simulator",
"qiskit.extensions.qasm_simulator_cpp",
"qiskit.extensions.quantum_initializer",
"qiskit.mapper",
"qiskit.qasm",
Expand Down
17 changes: 8 additions & 9 deletions test/python/test_local_qasm_simulator_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
from numpy.linalg import norm

import qiskit
import qiskit.backends._qasm_simulator_cpp as QasmSimulatorCpp
import numpy as np
from numpy.linalg import norm
from qiskit import ClassicalRegister
from qiskit import QuantumCircuit
from qiskit import QuantumJob
from qiskit import QuantumRegister
from qiskit import _openquantumcompiler as openquantumcompiler
from qiskit.backends import _qasm_simulator_cpp as QasmSimulatorCpp

from .common import QiskitTestCase


Expand Down Expand Up @@ -190,7 +189,7 @@ def test_qobj_measure_opt(self):
'quantum_state': np.array([1 / np.sqrt(2), 0, 0, 1 / np.sqrt(2)])}
}

for name in expected_data.keys():
for name in expected_data:
# Check counts:
counts = result.get_counts(name)
expected_counts = expected_data[name]['counts']
Expand Down Expand Up @@ -227,7 +226,7 @@ def test_qobj_reset(self):
'y reset': {'quantum_state': np.array([1, 0])},
'h reset': {'quantum_state': np.array([1, 0])}
}
for name in expected_data.keys():
for name in expected_data:
# Check snapshot is |0> state
snapshots = result.get_data(name).get('snapshots', {})
self.assertEqual(set(snapshots), {'0'},
Expand Down Expand Up @@ -350,7 +349,7 @@ def test_qobj_single_qubit_gates(self):
'quantum_state': np.array([1 / np.sqrt(2), 0.5 - 0.5j])}
}

for name in expected_data.keys():
for name in expected_data:
# Check snapshot
snapshots = result.get_data(name).get('snapshots', {})
self.assertEqual(set(snapshots), {'0'},
Expand Down Expand Up @@ -399,9 +398,9 @@ def test_qobj_two_qubit_gates(self):
'h0 h1 cz01': {'quantum_state': np.array([0.5, 0.5, 0.5, -0.5])},
'h0 h1 cz10': {'quantum_state': np.array([0.5, 0.5, 0.5, -0.5])},
'h0 rzz01': {
'quantum_state': np.array([1 / np.sqrt(2), 1j / np.sqrt(2), 0 , 0])},
'quantum_state': np.array([1 / np.sqrt(2), 1j / np.sqrt(2), 0, 0])},
'h0 rzz10': {
'quantum_state': np.array([1 / np.sqrt(2), 1j / np.sqrt(2), 0 , 0])},
'quantum_state': np.array([1 / np.sqrt(2), 1j / np.sqrt(2), 0, 0])},
'h1 rzz01': {
'quantum_state': np.array([1 / np.sqrt(2), 0, 1j / np.sqrt(2), 0])},
'h1 rzz10': {
Expand All @@ -410,7 +409,7 @@ def test_qobj_two_qubit_gates(self):
'h0 h1 rzz10': {'quantum_state': np.array([0.5, 0.5j, 0.5j, 0.5])}
}

for name in expected_data.keys():
for name in expected_data:
# Check snapshot
snapshots = result.get_data(name).get('snapshots', {})
self.assertEqual(set(snapshots), {'0'},
Expand Down

0 comments on commit 3a2dbde

Please sign in to comment.