From 3a2dbde6d4a92d26eb97a9c9330c615c515e7e7a Mon Sep 17 00:00:00 2001 From: cjwood Date: Wed, 4 Apr 2018 11:08:43 -0400 Subject: [PATCH] renamed qiskit_simulator extensions to qasm_simulator_cpp, added basic tests --- qiskit/backends/_qasm_simulator_cpp.py | 5 +++++ .../__init__.py | 3 ++- .../load.py | 0 .../noise.py | 0 .../rzz.py | 1 + .../save.py | 0 .../snapshot.py | 0 .../wait.py | 0 setup.py.in | 2 +- test/python/test_local_qasm_simulator_cpp.py | 17 ++++++++--------- 10 files changed, 17 insertions(+), 11 deletions(-) rename qiskit/extensions/{qiskit_simulator => qasm_simulator_cpp}/__init__.py (94%) rename qiskit/extensions/{qiskit_simulator => qasm_simulator_cpp}/load.py (100%) rename qiskit/extensions/{qiskit_simulator => qasm_simulator_cpp}/noise.py (100%) rename qiskit/extensions/{qiskit_simulator => qasm_simulator_cpp}/rzz.py (98%) rename qiskit/extensions/{qiskit_simulator => qasm_simulator_cpp}/save.py (100%) rename qiskit/extensions/{qiskit_simulator => qasm_simulator_cpp}/snapshot.py (100%) rename qiskit/extensions/{qiskit_simulator => qasm_simulator_cpp}/wait.py (100%) diff --git a/qiskit/backends/_qasm_simulator_cpp.py b/qiskit/backends/_qasm_simulator_cpp.py index ea5bdc93476e..901b62d6ad9f 100644 --- a/qiskit/backends/_qasm_simulator_cpp.py +++ b/qiskit/backends/_qasm_simulator_cpp.py @@ -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() @@ -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): diff --git a/qiskit/extensions/qiskit_simulator/__init__.py b/qiskit/extensions/qasm_simulator_cpp/__init__.py similarity index 94% rename from qiskit/extensions/qiskit_simulator/__init__.py rename to qiskit/extensions/qasm_simulator_cpp/__init__.py index b3f712efd1be..d63f9954bee6 100644 --- a/qiskit/extensions/qiskit_simulator/__init__.py +++ b/qiskit/extensions/qasm_simulator_cpp/__init__.py @@ -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 diff --git a/qiskit/extensions/qiskit_simulator/load.py b/qiskit/extensions/qasm_simulator_cpp/load.py similarity index 100% rename from qiskit/extensions/qiskit_simulator/load.py rename to qiskit/extensions/qasm_simulator_cpp/load.py diff --git a/qiskit/extensions/qiskit_simulator/noise.py b/qiskit/extensions/qasm_simulator_cpp/noise.py similarity index 100% rename from qiskit/extensions/qiskit_simulator/noise.py rename to qiskit/extensions/qasm_simulator_cpp/noise.py diff --git a/qiskit/extensions/qiskit_simulator/rzz.py b/qiskit/extensions/qasm_simulator_cpp/rzz.py similarity index 98% rename from qiskit/extensions/qiskit_simulator/rzz.py rename to qiskit/extensions/qasm_simulator_cpp/rzz.py index 2ebc60d0f1f7..e55edace6fa4 100644 --- a/qiskit/extensions/qiskit_simulator/rzz.py +++ b/qiskit/extensions/qasm_simulator_cpp/rzz.py @@ -28,6 +28,7 @@ class RZZGate(Gate): + """Two-qubit ZZ-rotation gate.""" def __init__(self, theta, ctl, tgt, circ=None): """Create new rzz gate.""" diff --git a/qiskit/extensions/qiskit_simulator/save.py b/qiskit/extensions/qasm_simulator_cpp/save.py similarity index 100% rename from qiskit/extensions/qiskit_simulator/save.py rename to qiskit/extensions/qasm_simulator_cpp/save.py diff --git a/qiskit/extensions/qiskit_simulator/snapshot.py b/qiskit/extensions/qasm_simulator_cpp/snapshot.py similarity index 100% rename from qiskit/extensions/qiskit_simulator/snapshot.py rename to qiskit/extensions/qasm_simulator_cpp/snapshot.py diff --git a/qiskit/extensions/qiskit_simulator/wait.py b/qiskit/extensions/qasm_simulator_cpp/wait.py similarity index 100% rename from qiskit/extensions/qiskit_simulator/wait.py rename to qiskit/extensions/qasm_simulator_cpp/wait.py diff --git a/setup.py.in b/setup.py.in index 5e06b512c941..179dac211158 100644 --- a/setup.py.in +++ b/setup.py.in @@ -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", diff --git a/test/python/test_local_qasm_simulator_cpp.py b/test/python/test_local_qasm_simulator_cpp.py index 39af41d41e23..31a000f33b5c 100644 --- a/test/python/test_local_qasm_simulator_cpp.py +++ b/test/python/test_local_qasm_simulator_cpp.py @@ -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 @@ -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'] @@ -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'}, @@ -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'}, @@ -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': { @@ -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'},