From 9d7ab72c725f8074113db39029862a130aff17f9 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 4 Mar 2019 13:34:06 -0500 Subject: [PATCH 01/32] count operations pass --- qiskit/transpiler/passes/__init__.py | 1 + qiskit/transpiler/passes/count_operations.py | 19 ++++++++ .../transpiler/test_count_operations_pass.py | 43 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 qiskit/transpiler/passes/count_operations.py create mode 100644 test/python/transpiler/test_count_operations_pass.py diff --git a/qiskit/transpiler/passes/__init__.py b/qiskit/transpiler/passes/__init__.py index 653d03d124bb..d1fa2e29cc55 100644 --- a/qiskit/transpiler/passes/__init__.py +++ b/qiskit/transpiler/passes/__init__.py @@ -10,6 +10,7 @@ from .unroller import Unroller from .cx_cancellation import CXCancellation from .fixed_point import FixedPoint +from .count_operations import CountOperations from .optimize_1q_gates import Optimize1qGates from .decompose import Decompose from .unroll_3q_or_more import Unroll3qOrMore diff --git a/qiskit/transpiler/passes/count_operations.py b/qiskit/transpiler/passes/count_operations.py new file mode 100644 index 000000000000..2e1534ce1452 --- /dev/null +++ b/qiskit/transpiler/passes/count_operations.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019, 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. + +""" Updates property_set['amount_of_operations'] with the amount of operations in the dag +""" +from qiskit.transpiler._basepasses import AnalysisPass + + +class CountOperations(AnalysisPass): + """ Updates property_set['amount_of_operations'] with the amount of operations in the dag + """ + + def run(self, dag): + self.property_set['amount_of_operations'] = dag.size() + return dag diff --git a/test/python/transpiler/test_count_operations_pass.py b/test/python/transpiler/test_count_operations_pass.py new file mode 100644 index 000000000000..dc0b8fa4e415 --- /dev/null +++ b/test/python/transpiler/test_count_operations_pass.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019, 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. + +"""CountOperations pass testing""" + +import unittest + +from qiskit import QuantumCircuit, QuantumRegister +from qiskit.converters import circuit_to_dag +from qiskit.transpiler.passes import CountOperations +from qiskit.test import QiskitTestCase + + +class TestCountGatesPass(QiskitTestCase): + """ Tests for PropertySet methods. """ + + def test_empty_dag(self): + """ When pass_that_updates_the_property is not passed, there are no requirements. """ + self.assertEqual(len(self.pass_.requires), 0) + + def test_count_h_and_cx(self): + qr = QuantumRegister(2) + circuit = QuantumCircuit(qr) + circuit.h(qr[0]) + circuit.h(qr[0]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[1], qr[0]) + circuit.cx(qr[1], qr[0]) + dag = circuit_to_dag(circuit) + + pass_ = CountOperations() + _ = pass_.run(dag) + self.assertEqual(pass_.property_set['amount_of_operations'], 8) + +if __name__ == '__main__': + unittest.main() From 9b98f9bb1509351ad5c3c7401448fe4fc3374309 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 4 Mar 2019 14:13:55 -0500 Subject: [PATCH 02/32] empty dag test --- .../python/transpiler/test_count_operations_pass.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/python/transpiler/test_count_operations_pass.py b/test/python/transpiler/test_count_operations_pass.py index dc0b8fa4e415..82380dd6acce 100644 --- a/test/python/transpiler/test_count_operations_pass.py +++ b/test/python/transpiler/test_count_operations_pass.py @@ -19,10 +19,17 @@ class TestCountGatesPass(QiskitTestCase): """ Tests for PropertySet methods. """ def test_empty_dag(self): - """ When pass_that_updates_the_property is not passed, there are no requirements. """ - self.assertEqual(len(self.pass_.requires), 0) + """ Empty DAG has 0 amount of operations """ + circuit = QuantumCircuit() + dag = circuit_to_dag(circuit) + + pass_ = CountOperations() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['amount_of_operations'], 0) def test_count_h_and_cx(self): + """ A dag with 8 operations """ qr = QuantumRegister(2) circuit = QuantumCircuit(qr) circuit.h(qr[0]) @@ -37,7 +44,9 @@ def test_count_h_and_cx(self): pass_ = CountOperations() _ = pass_.run(dag) + self.assertEqual(pass_.property_set['amount_of_operations'], 8) + if __name__ == '__main__': unittest.main() From f9b9cffd91d3deac619e68e1326f113e3b232604 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 11 Mar 2019 13:43:58 -0400 Subject: [PATCH 03/32] rename --- qiskit/transpiler/passes/__init__.py | 2 +- qiskit/transpiler/passes/count_operations.py | 19 ----------------- .../transpiler/passes/resource_estimation.py | 21 +++++++++++++++++++ .../transpiler/test_count_operations_pass.py | 8 +++---- 4 files changed, 26 insertions(+), 24 deletions(-) delete mode 100644 qiskit/transpiler/passes/count_operations.py create mode 100644 qiskit/transpiler/passes/resource_estimation.py diff --git a/qiskit/transpiler/passes/__init__.py b/qiskit/transpiler/passes/__init__.py index d1fa2e29cc55..ddc8bea432bc 100644 --- a/qiskit/transpiler/passes/__init__.py +++ b/qiskit/transpiler/passes/__init__.py @@ -10,7 +10,7 @@ from .unroller import Unroller from .cx_cancellation import CXCancellation from .fixed_point import FixedPoint -from .count_operations import CountOperations +from .resource_estimation import ResourceEstimation from .optimize_1q_gates import Optimize1qGates from .decompose import Decompose from .unroll_3q_or_more import Unroll3qOrMore diff --git a/qiskit/transpiler/passes/count_operations.py b/qiskit/transpiler/passes/count_operations.py deleted file mode 100644 index 2e1534ce1452..000000000000 --- a/qiskit/transpiler/passes/count_operations.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2019, 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. - -""" Updates property_set['amount_of_operations'] with the amount of operations in the dag -""" -from qiskit.transpiler._basepasses import AnalysisPass - - -class CountOperations(AnalysisPass): - """ Updates property_set['amount_of_operations'] with the amount of operations in the dag - """ - - def run(self, dag): - self.property_set['amount_of_operations'] = dag.size() - return dag diff --git a/qiskit/transpiler/passes/resource_estimation.py b/qiskit/transpiler/passes/resource_estimation.py new file mode 100644 index 000000000000..484c8f0a5ef5 --- /dev/null +++ b/qiskit/transpiler/passes/resource_estimation.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019, 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. + +""" Updates 'size', 'depth', and 'width' in the property set. +""" +from qiskit.transpiler.basepasses import AnalysisPass + + +class ResourceEstimation(AnalysisPass): + """ Updates 'size', 'depth', and 'width' in the property set. + """ + + def run(self, dag): + self.property_set['size'] = dag.size() + self.property_set['depth'] = dag.depth() + self.property_set['width'] = dag.width() + return dag diff --git a/test/python/transpiler/test_count_operations_pass.py b/test/python/transpiler/test_count_operations_pass.py index 82380dd6acce..cd4b3ea4a73e 100644 --- a/test/python/transpiler/test_count_operations_pass.py +++ b/test/python/transpiler/test_count_operations_pass.py @@ -5,13 +5,13 @@ # 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. -"""CountOperations pass testing""" +"""ResourceEstimation pass testing""" import unittest from qiskit import QuantumCircuit, QuantumRegister from qiskit.converters import circuit_to_dag -from qiskit.transpiler.passes import CountOperations +from qiskit.transpiler.passes import ResourceEstimation from qiskit.test import QiskitTestCase @@ -23,7 +23,7 @@ def test_empty_dag(self): circuit = QuantumCircuit() dag = circuit_to_dag(circuit) - pass_ = CountOperations() + pass_ = ResourceEstimation() _ = pass_.run(dag) self.assertEqual(pass_.property_set['amount_of_operations'], 0) @@ -42,7 +42,7 @@ def test_count_h_and_cx(self): circuit.cx(qr[1], qr[0]) dag = circuit_to_dag(circuit) - pass_ = CountOperations() + pass_ = ResourceEstimation() _ = pass_.run(dag) self.assertEqual(pass_.property_set['amount_of_operations'], 8) From c04fc5a90de58d51e0de6cbe7df2b22ab26309b9 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 11 Mar 2019 14:18:46 -0400 Subject: [PATCH 04/32] test --- qiskit/dagcircuit/_dagcircuit.py | 3 ++- .../transpiler/test_count_operations_pass.py | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/qiskit/dagcircuit/_dagcircuit.py b/qiskit/dagcircuit/_dagcircuit.py index 9488351f9d17..a33817b0555d 100644 --- a/qiskit/dagcircuit/_dagcircuit.py +++ b/qiskit/dagcircuit/_dagcircuit.py @@ -621,7 +621,8 @@ def depth(self): if not nx.is_directed_acyclic_graph(self.multi_graph): raise DAGCircuitError("not a DAG") - return nx.dag_longest_path_length(self.multi_graph) - 1 + depth = nx.dag_longest_path_length(self.multi_graph) - 1 + return depth if depth != -1 else 0 def width(self): """Return the total number of qubits used by the circuit.""" diff --git a/test/python/transpiler/test_count_operations_pass.py b/test/python/transpiler/test_count_operations_pass.py index cd4b3ea4a73e..723d0348c850 100644 --- a/test/python/transpiler/test_count_operations_pass.py +++ b/test/python/transpiler/test_count_operations_pass.py @@ -15,7 +15,7 @@ from qiskit.test import QiskitTestCase -class TestCountGatesPass(QiskitTestCase): +class TestResourceEstimationPass(QiskitTestCase): """ Tests for PropertySet methods. """ def test_empty_dag(self): @@ -26,14 +26,16 @@ def test_empty_dag(self): pass_ = ResourceEstimation() _ = pass_.run(dag) - self.assertEqual(pass_.property_set['amount_of_operations'], 0) + self.assertEqual(pass_.property_set['size'], 0) + self.assertEqual(pass_.property_set['depth'], 0) + self.assertEqual(pass_.property_set['width'], 0) def test_count_h_and_cx(self): """ A dag with 8 operations """ qr = QuantumRegister(2) circuit = QuantumCircuit(qr) circuit.h(qr[0]) - circuit.h(qr[0]) + circuit.h(qr[1]) circuit.cx(qr[0], qr[1]) circuit.cx(qr[0], qr[1]) circuit.cx(qr[0], qr[1]) @@ -45,7 +47,24 @@ def test_count_h_and_cx(self): pass_ = ResourceEstimation() _ = pass_.run(dag) - self.assertEqual(pass_.property_set['amount_of_operations'], 8) + self.assertEqual(pass_.property_set['size'], 8) + self.assertEqual(pass_.property_set['depth'], 7) + self.assertEqual(pass_.property_set['width'], 2) + + def test_depth_one(self): + """ A dag with operations in parallel and depth 1""" + qr = QuantumRegister(2) + circuit = QuantumCircuit(qr) + circuit.h(qr[0]) + circuit.h(qr[1]) + dag = circuit_to_dag(circuit) + + pass_ = ResourceEstimation() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['size'], 2) + self.assertEqual(pass_.property_set['depth'], 1) + self.assertEqual(pass_.property_set['width'], 2) if __name__ == '__main__': From 9ad1e22f6bee9f72b9ae588c9872d64fba2c5782 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 11 Mar 2019 15:20:15 -0400 Subject: [PATCH 05/32] test rename --- ..._count_operations_pass.py => test_resource_estimation_pass.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/python/transpiler/{test_count_operations_pass.py => test_resource_estimation_pass.py} (100%) diff --git a/test/python/transpiler/test_count_operations_pass.py b/test/python/transpiler/test_resource_estimation_pass.py similarity index 100% rename from test/python/transpiler/test_count_operations_pass.py rename to test/python/transpiler/test_resource_estimation_pass.py From 3307b28f50a6872204ff75f3ead6a19aa49905d0 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 11 Mar 2019 15:23:14 -0400 Subject: [PATCH 06/32] test name --- test/python/transpiler/test_resource_estimation_pass.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/python/transpiler/test_resource_estimation_pass.py b/test/python/transpiler/test_resource_estimation_pass.py index 723d0348c850..710d719de598 100644 --- a/test/python/transpiler/test_resource_estimation_pass.py +++ b/test/python/transpiler/test_resource_estimation_pass.py @@ -30,8 +30,8 @@ def test_empty_dag(self): self.assertEqual(pass_.property_set['depth'], 0) self.assertEqual(pass_.property_set['width'], 0) - def test_count_h_and_cx(self): - """ A dag with 8 operations """ + def test_purly_qubits(self): + """ A dag with 8 operations and no classic bits""" qr = QuantumRegister(2) circuit = QuantumCircuit(qr) circuit.h(qr[0]) From 0cd5bd02cabb9e3fab4205073bda547b6c742ce0 Mon Sep 17 00:00:00 2001 From: Ali Javadi-Abhari Date: Wed, 13 Mar 2019 10:42:38 -0400 Subject: [PATCH 07/32] Update qiskit/transpiler/passes/resource_estimation.py Co-Authored-By: 1ucian0 --- qiskit/transpiler/passes/resource_estimation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qiskit/transpiler/passes/resource_estimation.py b/qiskit/transpiler/passes/resource_estimation.py index 484c8f0a5ef5..4e6d1ec5c33d 100644 --- a/qiskit/transpiler/passes/resource_estimation.py +++ b/qiskit/transpiler/passes/resource_estimation.py @@ -5,7 +5,8 @@ # 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. -""" Updates 'size', 'depth', and 'width' in the property set. +"""Writes circuit resources to the property set +('size', 'depth', 'width', 'count_ops', 'num_tensor_factors') """ from qiskit.transpiler.basepasses import AnalysisPass From 3d01256a5002621f550784d654311d9c0ca895d0 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Wed, 13 Mar 2019 10:45:59 -0400 Subject: [PATCH 08/32] count_ops --- qiskit/transpiler/passes/resource_estimation.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/qiskit/transpiler/passes/resource_estimation.py b/qiskit/transpiler/passes/resource_estimation.py index 484c8f0a5ef5..17e7acf4771b 100644 --- a/qiskit/transpiler/passes/resource_estimation.py +++ b/qiskit/transpiler/passes/resource_estimation.py @@ -11,11 +11,21 @@ class ResourceEstimation(AnalysisPass): - """ Updates 'size', 'depth', and 'width' in the property set. + """ Updates 'size', 'depth', 'width', and 'count_ops' in the property set. """ def run(self, dag): self.property_set['size'] = dag.size() self.property_set['depth'] = dag.depth() self.property_set['width'] = dag.width() + op_dict = {} + for node in self.node_nums_in_topological_order(): + nd = self.multi_graph.node[node] + name = nd["name"] + if nd["type"] == "op": + if name not in op_dict: + op_dict[name] = 1 + else: + op_dict[name] += 1 + self.property_set['count_ops'] = op_dict return dag From 4dc0828faca3d0fa5fce83361643a4d405ccbf91 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Wed, 13 Mar 2019 10:50:08 -0400 Subject: [PATCH 09/32] count_ops --- qiskit/transpiler/passes/resource_estimation.py | 6 +++--- test/python/transpiler/test_resource_estimation_pass.py | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/qiskit/transpiler/passes/resource_estimation.py b/qiskit/transpiler/passes/resource_estimation.py index 02aa901cdbec..3db3abed5845 100644 --- a/qiskit/transpiler/passes/resource_estimation.py +++ b/qiskit/transpiler/passes/resource_estimation.py @@ -6,7 +6,7 @@ # the LICENSE.txt file in the root directory of this source tree. """Writes circuit resources to the property set -('size', 'depth', 'width', 'count_ops', 'num_tensor_factors') +('size', 'depth', 'width', and 'count_ops') """ from qiskit.transpiler.basepasses import AnalysisPass @@ -20,8 +20,8 @@ def run(self, dag): self.property_set['depth'] = dag.depth() self.property_set['width'] = dag.width() op_dict = {} - for node in self.node_nums_in_topological_order(): - nd = self.multi_graph.node[node] + for node in dag.node_nums_in_topological_order(): + nd = dag.node(node) name = nd["name"] if nd["type"] == "op": if name not in op_dict: diff --git a/test/python/transpiler/test_resource_estimation_pass.py b/test/python/transpiler/test_resource_estimation_pass.py index 710d719de598..5b470c21343f 100644 --- a/test/python/transpiler/test_resource_estimation_pass.py +++ b/test/python/transpiler/test_resource_estimation_pass.py @@ -29,6 +29,7 @@ def test_empty_dag(self): self.assertEqual(pass_.property_set['size'], 0) self.assertEqual(pass_.property_set['depth'], 0) self.assertEqual(pass_.property_set['width'], 0) + self.assertDictEqual(pass_.property_set['count_ops'], {}) def test_purly_qubits(self): """ A dag with 8 operations and no classic bits""" @@ -50,6 +51,7 @@ def test_purly_qubits(self): self.assertEqual(pass_.property_set['size'], 8) self.assertEqual(pass_.property_set['depth'], 7) self.assertEqual(pass_.property_set['width'], 2) + self.assertDictEqual(pass_.property_set['count_ops'], {'cx': 6, 'h': 2}) def test_depth_one(self): """ A dag with operations in parallel and depth 1""" @@ -65,6 +67,7 @@ def test_depth_one(self): self.assertEqual(pass_.property_set['size'], 2) self.assertEqual(pass_.property_set['depth'], 1) self.assertEqual(pass_.property_set['width'], 2) + self.assertDictEqual(pass_.property_set['count_ops'], {'h': 2}) if __name__ == '__main__': From af57631b5a4039250f3acbda467d9dd1410451f2 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Wed, 13 Mar 2019 10:51:15 -0400 Subject: [PATCH 10/32] lint --- qiskit/transpiler/passes/resource_estimation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qiskit/transpiler/passes/resource_estimation.py b/qiskit/transpiler/passes/resource_estimation.py index 3db3abed5845..b5eb2e0b2265 100644 --- a/qiskit/transpiler/passes/resource_estimation.py +++ b/qiskit/transpiler/passes/resource_estimation.py @@ -21,9 +21,9 @@ def run(self, dag): self.property_set['width'] = dag.width() op_dict = {} for node in dag.node_nums_in_topological_order(): - nd = dag.node(node) - name = nd["name"] - if nd["type"] == "op": + node_data = dag.node(node) + name = node_data["name"] + if node_data["type"] == "op": if name not in op_dict: op_dict[name] = 1 else: From bfd903f8274733f0dbc6096e11de2bf2228dc16f Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Wed, 13 Mar 2019 11:03:49 -0400 Subject: [PATCH 11/32] changelog --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2da5e8105be7..3e8760a10c09 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -49,6 +49,7 @@ Added - ``execute_circuits()`` and ``assemble_circuits()`` allow setting a qobj_header of type QobjHeader to add extra information to the qobj (and thus result). - Register indexing supports negative indices (#1875) +- Added a ``ResourceEstimation`` analysis pass. Changed ------- From 62aa6f0e1745a677ba4db682accde90bb8832900 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 19 Mar 2019 12:47:01 -0400 Subject: [PATCH 12/32] depth pass --- qiskit/transpiler/passes/depth.py | 17 ++++++ test/python/transpiler/test_depth_pass.py | 64 +++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 qiskit/transpiler/passes/depth.py create mode 100644 test/python/transpiler/test_depth_pass.py diff --git a/qiskit/transpiler/passes/depth.py b/qiskit/transpiler/passes/depth.py new file mode 100644 index 000000000000..f2f688f5c854 --- /dev/null +++ b/qiskit/transpiler/passes/depth.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019, 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. + +""" An analysis pass for calculated the depth of a DAG circuit. +""" +from qiskit.transpiler.basepasses import AnalysisPass + + +class Depth(AnalysisPass): + """ An analysis pass for calculated the depth of a DAG circuit. + """ + def run(self, dag): + self.property_set['depth'] = dag.depth() \ No newline at end of file diff --git a/test/python/transpiler/test_depth_pass.py b/test/python/transpiler/test_depth_pass.py new file mode 100644 index 000000000000..e4ed779f241c --- /dev/null +++ b/test/python/transpiler/test_depth_pass.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019, 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. + +"""Depth pass testing""" + +import unittest + +from qiskit import QuantumCircuit, QuantumRegister +from qiskit.converters import circuit_to_dag +from qiskit.transpiler.passes import Depth +from qiskit.test import QiskitTestCase + + +class TestDepthPass(QiskitTestCase): + """ Tests for Depth analysis methods. """ + + def test_empty_dag(self): + """ Empty DAG has 0 depth """ + circuit = QuantumCircuit() + dag = circuit_to_dag(circuit) + + pass_ = Depth() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['depth'], 0) + + def test_purely_qubits(self): + """ A dag with 8 operations and no classic bits""" + qr = QuantumRegister(2) + circuit = QuantumCircuit(qr) + circuit.h(qr[0]) + circuit.h(qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[1], qr[0]) + circuit.cx(qr[1], qr[0]) + dag = circuit_to_dag(circuit) + + pass_ = Depth() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['depth'], 7) + + def test_depth_one(self): + """ A dag with operations in parallel and depth 1""" + qr = QuantumRegister(2) + circuit = QuantumCircuit(qr) + circuit.h(qr[0]) + circuit.h(qr[1]) + dag = circuit_to_dag(circuit) + + pass_ = Depth() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['depth'], 1) + +if __name__ == '__main__': + unittest.main() From 08b076170a9cdc5dd6cc101f8971aed4bf3b9b47 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 19 Mar 2019 13:29:19 -0400 Subject: [PATCH 13/32] size pass --- qiskit/transpiler/passes/width.py | 17 ++++++ test/python/transpiler/test_width_pass.py | 74 +++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 qiskit/transpiler/passes/width.py create mode 100644 test/python/transpiler/test_width_pass.py diff --git a/qiskit/transpiler/passes/width.py b/qiskit/transpiler/passes/width.py new file mode 100644 index 000000000000..0b4b1427b3e2 --- /dev/null +++ b/qiskit/transpiler/passes/width.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019, 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. + +""" An analysis pass for calculated the width of a DAG circuit. +""" +from qiskit.transpiler.basepasses import AnalysisPass + + +class Width(AnalysisPass): + """ An analysis pass for calculated the width of a DAG circuit. + """ + def run(self, dag): + dag.property_set['width'] = dag.width() \ No newline at end of file diff --git a/test/python/transpiler/test_width_pass.py b/test/python/transpiler/test_width_pass.py new file mode 100644 index 000000000000..d6a242266cbd --- /dev/null +++ b/test/python/transpiler/test_width_pass.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019, 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. + +"""Depth pass testing""" + +import unittest + +from qiskit import QuantumCircuit, QuantumRegister +from qiskit.converters import circuit_to_dag +from qiskit.transpiler.passes import ResourceEstimation +from qiskit.test import QiskitTestCase + + +class TestDepthPass(QiskitTestCase): + """ Tests for Depth analysis methods. """ + + def test_empty_dag(self): + """ Empty DAG has 0 depth """ + circuit = QuantumCircuit() + dag = circuit_to_dag(circuit) + + pass_ = ResourceEstimation() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['size'], 0) + self.assertEqual(pass_.property_set['depth'], 0) + self.assertEqual(pass_.property_set['width'], 0) + self.assertDictEqual(pass_.property_set['count_ops'], {}) + + def test_purly_qubits(self): + """ A dag with 8 operations and no classic bits""" + qr = QuantumRegister(2) + circuit = QuantumCircuit(qr) + circuit.h(qr[0]) + circuit.h(qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[1], qr[0]) + circuit.cx(qr[1], qr[0]) + dag = circuit_to_dag(circuit) + + pass_ = ResourceEstimation() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['size'], 8) + self.assertEqual(pass_.property_set['depth'], 7) + self.assertEqual(pass_.property_set['width'], 2) + self.assertDictEqual(pass_.property_set['count_ops'], {'cx': 6, 'h': 2}) + + def test_depth_one(self): + """ A dag with operations in parallel and depth 1""" + qr = QuantumRegister(2) + circuit = QuantumCircuit(qr) + circuit.h(qr[0]) + circuit.h(qr[1]) + dag = circuit_to_dag(circuit) + + pass_ = ResourceEstimation() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['size'], 2) + self.assertEqual(pass_.property_set['depth'], 1) + self.assertEqual(pass_.property_set['width'], 2) + self.assertDictEqual(pass_.property_set['count_ops'], {'h': 2}) + + +if __name__ == '__main__': + unittest.main() From e7c1817fdd034e443dd1e2fc9a88f888d517bc6e Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 19 Mar 2019 13:43:40 -0400 Subject: [PATCH 14/32] size pass --- test/python/transpiler/test_width_pass.py | 32 ++++------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/test/python/transpiler/test_width_pass.py b/test/python/transpiler/test_width_pass.py index d6a242266cbd..1de896690385 100644 --- a/test/python/transpiler/test_width_pass.py +++ b/test/python/transpiler/test_width_pass.py @@ -5,17 +5,17 @@ # 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. -"""Depth pass testing""" +"""Width pass testing""" import unittest from qiskit import QuantumCircuit, QuantumRegister from qiskit.converters import circuit_to_dag -from qiskit.transpiler.passes import ResourceEstimation +from qiskit.transpiler.passes import Width from qiskit.test import QiskitTestCase -class TestDepthPass(QiskitTestCase): +class TestWidthPass(QiskitTestCase): """ Tests for Depth analysis methods. """ def test_empty_dag(self): @@ -23,13 +23,10 @@ def test_empty_dag(self): circuit = QuantumCircuit() dag = circuit_to_dag(circuit) - pass_ = ResourceEstimation() + pass_ = Width() _ = pass_.run(dag) - self.assertEqual(pass_.property_set['size'], 0) - self.assertEqual(pass_.property_set['depth'], 0) self.assertEqual(pass_.property_set['width'], 0) - self.assertDictEqual(pass_.property_set['count_ops'], {}) def test_purly_qubits(self): """ A dag with 8 operations and no classic bits""" @@ -45,29 +42,10 @@ def test_purly_qubits(self): circuit.cx(qr[1], qr[0]) dag = circuit_to_dag(circuit) - pass_ = ResourceEstimation() + pass_ = Width() _ = pass_.run(dag) - self.assertEqual(pass_.property_set['size'], 8) - self.assertEqual(pass_.property_set['depth'], 7) self.assertEqual(pass_.property_set['width'], 2) - self.assertDictEqual(pass_.property_set['count_ops'], {'cx': 6, 'h': 2}) - - def test_depth_one(self): - """ A dag with operations in parallel and depth 1""" - qr = QuantumRegister(2) - circuit = QuantumCircuit(qr) - circuit.h(qr[0]) - circuit.h(qr[1]) - dag = circuit_to_dag(circuit) - - pass_ = ResourceEstimation() - _ = pass_.run(dag) - - self.assertEqual(pass_.property_set['size'], 2) - self.assertEqual(pass_.property_set['depth'], 1) - self.assertEqual(pass_.property_set['width'], 2) - self.assertDictEqual(pass_.property_set['count_ops'], {'h': 2}) if __name__ == '__main__': From 6710a7327a465d508c699520be6d6599971c350b Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 19 Mar 2019 13:54:44 -0400 Subject: [PATCH 15/32] count_ops pass --- qiskit/transpiler/passes/count_ops.py | 17 ++++++ test/python/transpiler/test_count_ops_pass.py | 52 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 qiskit/transpiler/passes/count_ops.py create mode 100644 test/python/transpiler/test_count_ops_pass.py diff --git a/qiskit/transpiler/passes/count_ops.py b/qiskit/transpiler/passes/count_ops.py new file mode 100644 index 000000000000..8f54f71f9320 --- /dev/null +++ b/qiskit/transpiler/passes/count_ops.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019, 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. + +""" An analysis pass for counting operations in a DAG circuit. +""" +from qiskit.transpiler.basepasses import AnalysisPass + + +class CountOps(AnalysisPass): + """ An analysis pass for counting operations in a DAG circuit. + """ + def run(self, dag): + self.property_set['count_ops'] = dag.count_ops() \ No newline at end of file diff --git a/test/python/transpiler/test_count_ops_pass.py b/test/python/transpiler/test_count_ops_pass.py new file mode 100644 index 000000000000..5c2114d3669a --- /dev/null +++ b/test/python/transpiler/test_count_ops_pass.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019, 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. + +"""Depth pass testing""" + +import unittest + +from qiskit import QuantumCircuit, QuantumRegister +from qiskit.converters import circuit_to_dag +from qiskit.transpiler.passes import CountOps +from qiskit.test import QiskitTestCase + + +class TestCountOpsPass(QiskitTestCase): + """ Tests for CountOps analysis methods. """ + + def test_empty_dag(self): + """ Empty DAG has empty counts.""" + circuit = QuantumCircuit() + dag = circuit_to_dag(circuit) + + pass_ = CountOps() + _ = pass_.run(dag) + + self.assertDictEqual(pass_.property_set['count_ops'], {}) + + def test_purely_qubits(self): + """ A dag with 8 operations (6 CXs and 2 Hs)""" + qr = QuantumRegister(2) + circuit = QuantumCircuit(qr) + circuit.h(qr[0]) + circuit.h(qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[1], qr[0]) + circuit.cx(qr[1], qr[0]) + dag = circuit_to_dag(circuit) + + pass_ = CountOps() + _ = pass_.run(dag) + + self.assertDictEqual(pass_.property_set['count_ops'], {'cx': 6, 'h': 2}) + + +if __name__ == '__main__': + unittest.main() From 896e394d4698519fea508070db9d9233f1b36ccc Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 19 Mar 2019 13:56:10 -0400 Subject: [PATCH 16/32] size pass --- qiskit/transpiler/passes/size.py | 17 +++++++ test/python/transpiler/test_size_pass.py | 65 ++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 qiskit/transpiler/passes/size.py create mode 100644 test/python/transpiler/test_size_pass.py diff --git a/qiskit/transpiler/passes/size.py b/qiskit/transpiler/passes/size.py new file mode 100644 index 000000000000..95a514da6da6 --- /dev/null +++ b/qiskit/transpiler/passes/size.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019, 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. + +""" An analysis pass for calculated the size of a DAG circuit. +""" +from qiskit.transpiler.basepasses import AnalysisPass + + +class Size(AnalysisPass): + """ An analysis pass for calculated the size of a DAG circuit. + """ + def run(self, dag): + self.property_set['size'] = dag.size() \ No newline at end of file diff --git a/test/python/transpiler/test_size_pass.py b/test/python/transpiler/test_size_pass.py new file mode 100644 index 000000000000..8bbf4933e5e8 --- /dev/null +++ b/test/python/transpiler/test_size_pass.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019, 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. + +"""Size pass testing""" + +import unittest + +from qiskit import QuantumCircuit, QuantumRegister +from qiskit.converters import circuit_to_dag +from qiskit.transpiler.passes import Size +from qiskit.test import QiskitTestCase + + +class TestSizePass(QiskitTestCase): + """ Tests for Depth analysis methods. """ + + def test_empty_dag(self): + """ Empty DAG has 0 size""" + circuit = QuantumCircuit() + dag = circuit_to_dag(circuit) + + pass_ = Size() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['size'], 0) + + def test_purly_qubits(self): + """ A dag with 8 operations and no classic bits""" + qr = QuantumRegister(2) + circuit = QuantumCircuit(qr) + circuit.h(qr[0]) + circuit.h(qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[1], qr[0]) + circuit.cx(qr[1], qr[0]) + dag = circuit_to_dag(circuit) + + pass_ = Size() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['size'], 8) + + def test_depth_one(self): + """ A dag with operations in parallel and size 2""" + qr = QuantumRegister(2) + circuit = QuantumCircuit(qr) + circuit.h(qr[0]) + circuit.h(qr[1]) + dag = circuit_to_dag(circuit) + + pass_ = Size() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['size'], 2) + + +if __name__ == '__main__': + unittest.main() From edf90f68ddefcc53cd56a75645d699f1b532c35a Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 19 Mar 2019 14:18:02 -0400 Subject: [PATCH 17/32] NumTensorFactor pass --- qiskit/transpiler/passes/num_tensor_factor.py | 17 +++++ .../transpiler/test_tensor_factor_pass.py | 65 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 qiskit/transpiler/passes/num_tensor_factor.py create mode 100644 test/python/transpiler/test_tensor_factor_pass.py diff --git a/qiskit/transpiler/passes/num_tensor_factor.py b/qiskit/transpiler/passes/num_tensor_factor.py new file mode 100644 index 000000000000..baf88702982b --- /dev/null +++ b/qiskit/transpiler/passes/num_tensor_factor.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019, 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. + +""" An analysis pass for calculated the amount of tensor factors of a DAG circuit. +""" +from qiskit.transpiler.basepasses import AnalysisPass + + +class NumTensorFactor(AnalysisPass): + """ An analysis pass for calculated the amount of tensor factors of a DAG circuit. + """ + def run(self, dag): + self.property_set['num_tensor_factors'] = dag.num_tensor_factors() \ No newline at end of file diff --git a/test/python/transpiler/test_tensor_factor_pass.py b/test/python/transpiler/test_tensor_factor_pass.py new file mode 100644 index 000000000000..2e67ee96e0b7 --- /dev/null +++ b/test/python/transpiler/test_tensor_factor_pass.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019, 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. + +"""NumTensorFactor pass testing""" + +import unittest + +from qiskit import QuantumCircuit, QuantumRegister +from qiskit.converters import circuit_to_dag +from qiskit.transpiler.passes import NumTensorFactor +from qiskit.test import QiskitTestCase + + +class TestNumTensorsFactorPass(QiskitTestCase): + """ Tests for NumTensorFactor analysis methods. """ + + def test_empty_dag(self): + """ Empty DAG has 0 number of tensor factors. """ + circuit = QuantumCircuit() + dag = circuit_to_dag(circuit) + + pass_ = NumTensorFactor() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['num_tensor_factors'], 0) + + def test_purely_qubits(self): + """ A dag with 8 operations and 1 tensor factor.""" + qr = QuantumRegister(2) + circuit = QuantumCircuit(qr) + circuit.h(qr[0]) + circuit.h(qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[0], qr[1]) + circuit.cx(qr[1], qr[0]) + circuit.cx(qr[1], qr[0]) + dag = circuit_to_dag(circuit) + + pass_ = NumTensorFactor() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['num_tensor_factors'], 1) + + def test_depth_one(self): + """ A dag with operations in parallel (2 tensor factors)""" + qr = QuantumRegister(2) + circuit = QuantumCircuit(qr) + circuit.h(qr[0]) + circuit.h(qr[1]) + dag = circuit_to_dag(circuit) + + pass_ = NumTensorFactor() + _ = pass_.run(dag) + + self.assertEqual(pass_.property_set['num_tensor_factors'], 2) + + +if __name__ == '__main__': + unittest.main() From 8b4d74635e03f919bbef3568bd3f3394cccd8a8d Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 19 Mar 2019 14:44:40 -0400 Subject: [PATCH 18/32] resource calculation metapass --- qiskit/transpiler/passes/__init__.py | 5 ++ .../transpiler/passes/resource_estimation.py | 32 +++++------ qiskit/transpiler/passes/width.py | 2 +- test/python/transpiler/test_count_ops_pass.py | 2 +- test/python/transpiler/test_depth_pass.py | 2 +- .../test_resource_estimation_pass.py | 57 +++++++------------ test/python/transpiler/test_size_pass.py | 2 +- .../transpiler/test_tensor_factor_pass.py | 2 +- test/python/transpiler/test_width_pass.py | 2 +- 9 files changed, 44 insertions(+), 62 deletions(-) diff --git a/qiskit/transpiler/passes/__init__.py b/qiskit/transpiler/passes/__init__.py index 440e87da1d9f..bb5b90f99dcb 100644 --- a/qiskit/transpiler/passes/__init__.py +++ b/qiskit/transpiler/passes/__init__.py @@ -11,6 +11,11 @@ from .cx_cancellation import CXCancellation from .fixed_point import FixedPoint from .resource_estimation import ResourceEstimation +from .depth import Depth +from .size import Size +from .width import Width +from .count_ops import CountOps +from .num_tensor_factor import NumTensorFactor from .optimize_1q_gates import Optimize1qGates from .decompose import Decompose from .unroll_3q_or_more import Unroll3qOrMore diff --git a/qiskit/transpiler/passes/resource_estimation.py b/qiskit/transpiler/passes/resource_estimation.py index b5eb2e0b2265..262638fc7791 100644 --- a/qiskit/transpiler/passes/resource_estimation.py +++ b/qiskit/transpiler/passes/resource_estimation.py @@ -5,28 +5,22 @@ # 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. -"""Writes circuit resources to the property set -('size', 'depth', 'width', and 'count_ops') +""" An analysis pass for automatically running Depth(), Width(), Size(), CountOps(), and +Tensor_Factor() """ from qiskit.transpiler.basepasses import AnalysisPass - +from qiskit.transpiler.passes.depth import Depth +from qiskit.transpiler.passes.width import Width +from qiskit.transpiler.passes.size import Size +from qiskit.transpiler.passes.count_ops import CountOps +from qiskit.transpiler.passes.num_tensor_factor import NumTensorFactor class ResourceEstimation(AnalysisPass): - """ Updates 'size', 'depth', 'width', and 'count_ops' in the property set. + """ Requires Depth(), Width(), Size(), CountOps(), and NumTensorFactor(). """ + def __init__(self): + super().__init__() + self.requires += [Depth(), Width(), Size(), CountOps(), NumTensorFactor()] - def run(self, dag): - self.property_set['size'] = dag.size() - self.property_set['depth'] = dag.depth() - self.property_set['width'] = dag.width() - op_dict = {} - for node in dag.node_nums_in_topological_order(): - node_data = dag.node(node) - name = node_data["name"] - if node_data["type"] == "op": - if name not in op_dict: - op_dict[name] = 1 - else: - op_dict[name] += 1 - self.property_set['count_ops'] = op_dict - return dag + def run(self, _): + pass \ No newline at end of file diff --git a/qiskit/transpiler/passes/width.py b/qiskit/transpiler/passes/width.py index 0b4b1427b3e2..61618ae4c637 100644 --- a/qiskit/transpiler/passes/width.py +++ b/qiskit/transpiler/passes/width.py @@ -14,4 +14,4 @@ class Width(AnalysisPass): """ An analysis pass for calculated the width of a DAG circuit. """ def run(self, dag): - dag.property_set['width'] = dag.width() \ No newline at end of file + self.property_set['width'] = dag.width() \ No newline at end of file diff --git a/test/python/transpiler/test_count_ops_pass.py b/test/python/transpiler/test_count_ops_pass.py index 5c2114d3669a..bb247eedefa8 100644 --- a/test/python/transpiler/test_count_ops_pass.py +++ b/test/python/transpiler/test_count_ops_pass.py @@ -28,7 +28,7 @@ def test_empty_dag(self): self.assertDictEqual(pass_.property_set['count_ops'], {}) - def test_purely_qubits(self): + def test_just_qubits(self): """ A dag with 8 operations (6 CXs and 2 Hs)""" qr = QuantumRegister(2) circuit = QuantumCircuit(qr) diff --git a/test/python/transpiler/test_depth_pass.py b/test/python/transpiler/test_depth_pass.py index e4ed779f241c..56249bffcb6c 100644 --- a/test/python/transpiler/test_depth_pass.py +++ b/test/python/transpiler/test_depth_pass.py @@ -28,7 +28,7 @@ def test_empty_dag(self): self.assertEqual(pass_.property_set['depth'], 0) - def test_purely_qubits(self): + def test_just_qubits(self): """ A dag with 8 operations and no classic bits""" qr = QuantumRegister(2) circuit = QuantumCircuit(qr) diff --git a/test/python/transpiler/test_resource_estimation_pass.py b/test/python/transpiler/test_resource_estimation_pass.py index 5b470c21343f..56e15ee6a82b 100644 --- a/test/python/transpiler/test_resource_estimation_pass.py +++ b/test/python/transpiler/test_resource_estimation_pass.py @@ -9,29 +9,29 @@ import unittest -from qiskit import QuantumCircuit, QuantumRegister -from qiskit.converters import circuit_to_dag +from qiskit import QuantumRegister, QuantumCircuit +from qiskit.transpiler import PassManager, transpile from qiskit.transpiler.passes import ResourceEstimation +from qiskit.converters import circuit_to_dag from qiskit.test import QiskitTestCase - +from qiskit.test.mock import FakeRueschlikon class TestResourceEstimationPass(QiskitTestCase): """ Tests for PropertySet methods. """ def test_empty_dag(self): - """ Empty DAG has 0 amount of operations """ + """ Empty DAG.""" circuit = QuantumCircuit() - dag = circuit_to_dag(circuit) + passmanager = PassManager() + passmanager.append(ResourceEstimation()) + _ = transpile(circuit, FakeRueschlikon(), pass_manager=passmanager) - pass_ = ResourceEstimation() - _ = pass_.run(dag) + self.assertEqual(passmanager.property_set['size'], 0) + self.assertEqual(passmanager.property_set['depth'], 0) + self.assertEqual(passmanager.property_set['width'], 0) + self.assertDictEqual(passmanager.property_set['count_ops'], {}) - self.assertEqual(pass_.property_set['size'], 0) - self.assertEqual(pass_.property_set['depth'], 0) - self.assertEqual(pass_.property_set['width'], 0) - self.assertDictEqual(pass_.property_set['count_ops'], {}) - - def test_purly_qubits(self): + def test_just_qubits(self): """ A dag with 8 operations and no classic bits""" qr = QuantumRegister(2) circuit = QuantumCircuit(qr) @@ -43,32 +43,15 @@ def test_purly_qubits(self): circuit.cx(qr[0], qr[1]) circuit.cx(qr[1], qr[0]) circuit.cx(qr[1], qr[0]) - dag = circuit_to_dag(circuit) - - pass_ = ResourceEstimation() - _ = pass_.run(dag) - - self.assertEqual(pass_.property_set['size'], 8) - self.assertEqual(pass_.property_set['depth'], 7) - self.assertEqual(pass_.property_set['width'], 2) - self.assertDictEqual(pass_.property_set['count_ops'], {'cx': 6, 'h': 2}) - - def test_depth_one(self): - """ A dag with operations in parallel and depth 1""" - qr = QuantumRegister(2) - circuit = QuantumCircuit(qr) - circuit.h(qr[0]) - circuit.h(qr[1]) - dag = circuit_to_dag(circuit) - - pass_ = ResourceEstimation() - _ = pass_.run(dag) - self.assertEqual(pass_.property_set['size'], 2) - self.assertEqual(pass_.property_set['depth'], 1) - self.assertEqual(pass_.property_set['width'], 2) - self.assertDictEqual(pass_.property_set['count_ops'], {'h': 2}) + passmanager = PassManager() + passmanager.append(ResourceEstimation()) + _ = transpile(circuit, FakeRueschlikon(), pass_manager=passmanager) + self.assertEqual(passmanager.property_set['size'], 8) + self.assertEqual(passmanager.property_set['depth'], 7) + self.assertEqual(passmanager.property_set['width'], 2) + self.assertDictEqual(passmanager.property_set['count_ops'], {'cx': 6, 'h': 2}) if __name__ == '__main__': unittest.main() diff --git a/test/python/transpiler/test_size_pass.py b/test/python/transpiler/test_size_pass.py index 8bbf4933e5e8..6b12617cb3aa 100644 --- a/test/python/transpiler/test_size_pass.py +++ b/test/python/transpiler/test_size_pass.py @@ -28,7 +28,7 @@ def test_empty_dag(self): self.assertEqual(pass_.property_set['size'], 0) - def test_purly_qubits(self): + def test_just_qubits(self): """ A dag with 8 operations and no classic bits""" qr = QuantumRegister(2) circuit = QuantumCircuit(qr) diff --git a/test/python/transpiler/test_tensor_factor_pass.py b/test/python/transpiler/test_tensor_factor_pass.py index 2e67ee96e0b7..222338c83002 100644 --- a/test/python/transpiler/test_tensor_factor_pass.py +++ b/test/python/transpiler/test_tensor_factor_pass.py @@ -28,7 +28,7 @@ def test_empty_dag(self): self.assertEqual(pass_.property_set['num_tensor_factors'], 0) - def test_purely_qubits(self): + def test_just_qubits(self): """ A dag with 8 operations and 1 tensor factor.""" qr = QuantumRegister(2) circuit = QuantumCircuit(qr) diff --git a/test/python/transpiler/test_width_pass.py b/test/python/transpiler/test_width_pass.py index 1de896690385..6ac73602d103 100644 --- a/test/python/transpiler/test_width_pass.py +++ b/test/python/transpiler/test_width_pass.py @@ -28,7 +28,7 @@ def test_empty_dag(self): self.assertEqual(pass_.property_set['width'], 0) - def test_purly_qubits(self): + def test_just_qubits(self): """ A dag with 8 operations and no classic bits""" qr = QuantumRegister(2) circuit = QuantumCircuit(qr) From e2682d02882932cf765a62d622f18f026a712702 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 19 Mar 2019 14:51:52 -0400 Subject: [PATCH 19/32] lint --- qiskit/transpiler/passes/count_ops.py | 3 ++- qiskit/transpiler/passes/depth.py | 3 ++- qiskit/transpiler/passes/num_tensor_factor.py | 3 ++- qiskit/transpiler/passes/resource_estimation.py | 4 +++- qiskit/transpiler/passes/size.py | 3 ++- qiskit/transpiler/passes/width.py | 3 ++- test/python/transpiler/test_resource_estimation_pass.py | 2 ++ 7 files changed, 15 insertions(+), 6 deletions(-) diff --git a/qiskit/transpiler/passes/count_ops.py b/qiskit/transpiler/passes/count_ops.py index 8f54f71f9320..490af95ebaf7 100644 --- a/qiskit/transpiler/passes/count_ops.py +++ b/qiskit/transpiler/passes/count_ops.py @@ -13,5 +13,6 @@ class CountOps(AnalysisPass): """ An analysis pass for counting operations in a DAG circuit. """ + def run(self, dag): - self.property_set['count_ops'] = dag.count_ops() \ No newline at end of file + self.property_set['count_ops'] = dag.count_ops() diff --git a/qiskit/transpiler/passes/depth.py b/qiskit/transpiler/passes/depth.py index f2f688f5c854..c6398f21f4b4 100644 --- a/qiskit/transpiler/passes/depth.py +++ b/qiskit/transpiler/passes/depth.py @@ -13,5 +13,6 @@ class Depth(AnalysisPass): """ An analysis pass for calculated the depth of a DAG circuit. """ + def run(self, dag): - self.property_set['depth'] = dag.depth() \ No newline at end of file + self.property_set['depth'] = dag.depth() diff --git a/qiskit/transpiler/passes/num_tensor_factor.py b/qiskit/transpiler/passes/num_tensor_factor.py index baf88702982b..c0b89f125a61 100644 --- a/qiskit/transpiler/passes/num_tensor_factor.py +++ b/qiskit/transpiler/passes/num_tensor_factor.py @@ -13,5 +13,6 @@ class NumTensorFactor(AnalysisPass): """ An analysis pass for calculated the amount of tensor factors of a DAG circuit. """ + def run(self, dag): - self.property_set['num_tensor_factors'] = dag.num_tensor_factors() \ No newline at end of file + self.property_set['num_tensor_factors'] = dag.num_tensor_factors() diff --git a/qiskit/transpiler/passes/resource_estimation.py b/qiskit/transpiler/passes/resource_estimation.py index 262638fc7791..dd1ceb410dcf 100644 --- a/qiskit/transpiler/passes/resource_estimation.py +++ b/qiskit/transpiler/passes/resource_estimation.py @@ -15,12 +15,14 @@ from qiskit.transpiler.passes.count_ops import CountOps from qiskit.transpiler.passes.num_tensor_factor import NumTensorFactor + class ResourceEstimation(AnalysisPass): """ Requires Depth(), Width(), Size(), CountOps(), and NumTensorFactor(). """ + def __init__(self): super().__init__() self.requires += [Depth(), Width(), Size(), CountOps(), NumTensorFactor()] def run(self, _): - pass \ No newline at end of file + pass diff --git a/qiskit/transpiler/passes/size.py b/qiskit/transpiler/passes/size.py index 95a514da6da6..9d35118bd7ae 100644 --- a/qiskit/transpiler/passes/size.py +++ b/qiskit/transpiler/passes/size.py @@ -13,5 +13,6 @@ class Size(AnalysisPass): """ An analysis pass for calculated the size of a DAG circuit. """ + def run(self, dag): - self.property_set['size'] = dag.size() \ No newline at end of file + self.property_set['size'] = dag.size() diff --git a/qiskit/transpiler/passes/width.py b/qiskit/transpiler/passes/width.py index 61618ae4c637..aa1aced11232 100644 --- a/qiskit/transpiler/passes/width.py +++ b/qiskit/transpiler/passes/width.py @@ -13,5 +13,6 @@ class Width(AnalysisPass): """ An analysis pass for calculated the width of a DAG circuit. """ + def run(self, dag): - self.property_set['width'] = dag.width() \ No newline at end of file + self.property_set['width'] = dag.width() diff --git a/test/python/transpiler/test_resource_estimation_pass.py b/test/python/transpiler/test_resource_estimation_pass.py index 56e15ee6a82b..17a3c9617fbd 100644 --- a/test/python/transpiler/test_resource_estimation_pass.py +++ b/test/python/transpiler/test_resource_estimation_pass.py @@ -16,6 +16,7 @@ from qiskit.test import QiskitTestCase from qiskit.test.mock import FakeRueschlikon + class TestResourceEstimationPass(QiskitTestCase): """ Tests for PropertySet methods. """ @@ -53,5 +54,6 @@ def test_just_qubits(self): self.assertEqual(passmanager.property_set['width'], 2) self.assertDictEqual(passmanager.property_set['count_ops'], {'cx': 6, 'h': 2}) + if __name__ == '__main__': unittest.main() From 5604586bbe2df90a6a16e7c2564cbdff463f980e Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Tue, 19 Mar 2019 14:53:22 -0400 Subject: [PATCH 20/32] unused import --- test/python/transpiler/test_resource_estimation_pass.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/python/transpiler/test_resource_estimation_pass.py b/test/python/transpiler/test_resource_estimation_pass.py index 17a3c9617fbd..07012728700a 100644 --- a/test/python/transpiler/test_resource_estimation_pass.py +++ b/test/python/transpiler/test_resource_estimation_pass.py @@ -12,7 +12,6 @@ from qiskit import QuantumRegister, QuantumCircuit from qiskit.transpiler import PassManager, transpile from qiskit.transpiler.passes import ResourceEstimation -from qiskit.converters import circuit_to_dag from qiskit.test import QiskitTestCase from qiskit.test.mock import FakeRueschlikon From 12ced28e4283682280628d2324113583fb0d2ac5 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 22 Mar 2019 11:19:08 -0400 Subject: [PATCH 21/32] changelog --- CHANGELOG.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c09dd362e577..4fc92052ff47 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -50,7 +50,8 @@ Added - ``execute_circuits()`` and ``assemble_circuits()`` allow setting a qobj_header of type QobjHeader to add extra information to the qobj (and thus result). - Register indexing supports negative indices (#1875) -- Added a ``ResourceEstimation`` analysis pass. +- Added new resource estimation passes: ``Depth``, ``Width``, ``Size``, ``CountOps``, and + ``NumTensorFactor``, all grouped in the ``ResourceEstimation`` analysis pass. Changed ------- From 8813020ed6afbeb64c83c8e6e210daf2b98903cb Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Mon, 25 Mar 2019 14:00:27 -0400 Subject: [PATCH 22/32] lint --- test/python/transpiler/test_depth_pass.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/python/transpiler/test_depth_pass.py b/test/python/transpiler/test_depth_pass.py index 56249bffcb6c..2d039b122afb 100644 --- a/test/python/transpiler/test_depth_pass.py +++ b/test/python/transpiler/test_depth_pass.py @@ -60,5 +60,6 @@ def test_depth_one(self): self.assertEqual(pass_.property_set['depth'], 1) + if __name__ == '__main__': unittest.main() From 630a3689f242b242b5721c3e8ad257ebe91e73c8 Mon Sep 17 00:00:00 2001 From: Ali Javadi-Abhari Date: Thu, 4 Apr 2019 13:13:41 -0400 Subject: [PATCH 23/32] Update qiskit/transpiler/passes/__init__.py Co-Authored-By: 1ucian0 --- qiskit/transpiler/passes/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/transpiler/passes/__init__.py b/qiskit/transpiler/passes/__init__.py index f297c75b365a..dbd4912fa1a8 100644 --- a/qiskit/transpiler/passes/__init__.py +++ b/qiskit/transpiler/passes/__init__.py @@ -15,7 +15,7 @@ from .size import Size from .width import Width from .count_ops import CountOps -from .num_tensor_factor import NumTensorFactor +from .num_tensor_factors import NumTensorFactors from .dag_fixed_point import DAGFixedPoint from .optimize_1q_gates import Optimize1qGates from .decompose import Decompose From 5fbe0cfdbcf2f9f8dcdc60714f82e55821f19d79 Mon Sep 17 00:00:00 2001 From: Ali Javadi-Abhari Date: Thu, 4 Apr 2019 13:13:57 -0400 Subject: [PATCH 24/32] Update qiskit/transpiler/passes/width.py Co-Authored-By: 1ucian0 --- qiskit/transpiler/passes/width.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/transpiler/passes/width.py b/qiskit/transpiler/passes/width.py index aa1aced11232..8e351d099796 100644 --- a/qiskit/transpiler/passes/width.py +++ b/qiskit/transpiler/passes/width.py @@ -11,7 +11,7 @@ class Width(AnalysisPass): - """ An analysis pass for calculated the width of a DAG circuit. + """ An analysis pass for calculating the width of a DAG circuit. """ def run(self, dag): From d2c1373df1979a302168d01f4b1516fcb71c92a5 Mon Sep 17 00:00:00 2001 From: Ali Javadi-Abhari Date: Thu, 4 Apr 2019 13:14:09 -0400 Subject: [PATCH 25/32] Update qiskit/transpiler/passes/num_tensor_factor.py Co-Authored-By: 1ucian0 --- qiskit/transpiler/passes/num_tensor_factor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/transpiler/passes/num_tensor_factor.py b/qiskit/transpiler/passes/num_tensor_factor.py index c0b89f125a61..368c1dc0534a 100644 --- a/qiskit/transpiler/passes/num_tensor_factor.py +++ b/qiskit/transpiler/passes/num_tensor_factor.py @@ -5,7 +5,7 @@ # 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. -""" An analysis pass for calculated the amount of tensor factors of a DAG circuit. +""" An analysis pass for calculating the number of tensor factors of a DAG circuit. """ from qiskit.transpiler.basepasses import AnalysisPass From c0e5e284d09079ca99ac0d5377029312519037cc Mon Sep 17 00:00:00 2001 From: Ali Javadi-Abhari Date: Thu, 4 Apr 2019 13:14:22 -0400 Subject: [PATCH 26/32] Update qiskit/transpiler/passes/depth.py Co-Authored-By: 1ucian0 --- qiskit/transpiler/passes/depth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/transpiler/passes/depth.py b/qiskit/transpiler/passes/depth.py index c6398f21f4b4..20d8c190eb41 100644 --- a/qiskit/transpiler/passes/depth.py +++ b/qiskit/transpiler/passes/depth.py @@ -5,7 +5,7 @@ # 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. -""" An analysis pass for calculated the depth of a DAG circuit. +""" An analysis pass for calculating the depth of a DAG circuit. """ from qiskit.transpiler.basepasses import AnalysisPass From 8b1c58810184aa3321950d56299a9742573d57b0 Mon Sep 17 00:00:00 2001 From: Ali Javadi-Abhari Date: Thu, 4 Apr 2019 13:14:34 -0400 Subject: [PATCH 27/32] Update qiskit/transpiler/passes/depth.py Co-Authored-By: 1ucian0 --- qiskit/transpiler/passes/depth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/transpiler/passes/depth.py b/qiskit/transpiler/passes/depth.py index 20d8c190eb41..368b90114695 100644 --- a/qiskit/transpiler/passes/depth.py +++ b/qiskit/transpiler/passes/depth.py @@ -11,7 +11,7 @@ class Depth(AnalysisPass): - """ An analysis pass for calculated the depth of a DAG circuit. + """ An analysis pass for calculating the depth of a DAG circuit. """ def run(self, dag): From 876123cbcdbc9abc3143a105b020ab9d51c06585 Mon Sep 17 00:00:00 2001 From: Ali Javadi-Abhari Date: Thu, 4 Apr 2019 13:15:52 -0400 Subject: [PATCH 28/32] Update qiskit/transpiler/passes/size.py Co-Authored-By: 1ucian0 --- qiskit/transpiler/passes/size.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/transpiler/passes/size.py b/qiskit/transpiler/passes/size.py index 9d35118bd7ae..3eb49762830c 100644 --- a/qiskit/transpiler/passes/size.py +++ b/qiskit/transpiler/passes/size.py @@ -5,7 +5,7 @@ # 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. -""" An analysis pass for calculated the size of a DAG circuit. +""" An analysis pass for calculating the size of a DAG circuit. """ from qiskit.transpiler.basepasses import AnalysisPass From 222a5df1bb39d7348e5e490f4487eaeaedcec140 Mon Sep 17 00:00:00 2001 From: Ali Javadi-Abhari Date: Thu, 4 Apr 2019 13:16:06 -0400 Subject: [PATCH 29/32] Update qiskit/transpiler/passes/width.py Co-Authored-By: 1ucian0 --- qiskit/transpiler/passes/width.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/transpiler/passes/width.py b/qiskit/transpiler/passes/width.py index 8e351d099796..2ba81c19112b 100644 --- a/qiskit/transpiler/passes/width.py +++ b/qiskit/transpiler/passes/width.py @@ -5,7 +5,7 @@ # 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. -""" An analysis pass for calculated the width of a DAG circuit. +""" An analysis pass for calculating the width of a DAG circuit. """ from qiskit.transpiler.basepasses import AnalysisPass From 8b1c08be2f0deda494fd90fab80f475f2ea2ccc5 Mon Sep 17 00:00:00 2001 From: Ali Javadi-Abhari Date: Thu, 4 Apr 2019 13:16:16 -0400 Subject: [PATCH 30/32] Update qiskit/transpiler/passes/size.py Co-Authored-By: 1ucian0 --- qiskit/transpiler/passes/size.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/transpiler/passes/size.py b/qiskit/transpiler/passes/size.py index 3eb49762830c..5f8cd759b57f 100644 --- a/qiskit/transpiler/passes/size.py +++ b/qiskit/transpiler/passes/size.py @@ -11,7 +11,7 @@ class Size(AnalysisPass): - """ An analysis pass for calculated the size of a DAG circuit. + """ An analysis pass for calculating the size of a DAG circuit. """ def run(self, dag): From f462fae00599af4816fcf75314ee5d77b6093a84 Mon Sep 17 00:00:00 2001 From: Ali Javadi-Abhari Date: Thu, 4 Apr 2019 13:16:30 -0400 Subject: [PATCH 31/32] Update qiskit/transpiler/passes/num_tensor_factor.py Co-Authored-By: 1ucian0 --- qiskit/transpiler/passes/num_tensor_factor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/transpiler/passes/num_tensor_factor.py b/qiskit/transpiler/passes/num_tensor_factor.py index 368c1dc0534a..7f121e4cda53 100644 --- a/qiskit/transpiler/passes/num_tensor_factor.py +++ b/qiskit/transpiler/passes/num_tensor_factor.py @@ -11,7 +11,7 @@ class NumTensorFactor(AnalysisPass): - """ An analysis pass for calculated the amount of tensor factors of a DAG circuit. + """ An analysis pass for calculating the number of tensor factors of a DAG circuit. """ def run(self, dag): From d7fa54ec2b3375c081bcf2b3a72e2d878b4b4281 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Thu, 4 Apr 2019 13:32:37 -0400 Subject: [PATCH 32/32] renaming --- CHANGELOG.rst | 2 +- .../{num_tensor_factor.py => num_tensor_factors.py} | 2 +- qiskit/transpiler/passes/resource_estimation.py | 6 +++--- test/python/transpiler/test_tensor_factor_pass.py | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) rename qiskit/transpiler/passes/{num_tensor_factor.py => num_tensor_factors.py} (93%) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d76cd27bccd5..09485e5bcd57 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -51,7 +51,7 @@ Added QobjHeader to add extra information to the qobj (and thus result). - Register indexing supports negative indices (#1875) - Added new resource estimation passes: ``Depth``, ``Width``, ``Size``, ``CountOps``, and - ``NumTensorFactor``, all grouped in the ``ResourceEstimation`` analysis pass. + ``NumTensorFactors``, all grouped in the ``ResourceEstimation`` analysis pass. - Added ``nodes_on_wire()`` to DAGCircuit which returns an iterator over all the operations on the given wire - Added new properties to an Instruction: diff --git a/qiskit/transpiler/passes/num_tensor_factor.py b/qiskit/transpiler/passes/num_tensor_factors.py similarity index 93% rename from qiskit/transpiler/passes/num_tensor_factor.py rename to qiskit/transpiler/passes/num_tensor_factors.py index 7f121e4cda53..738edcd04d5c 100644 --- a/qiskit/transpiler/passes/num_tensor_factor.py +++ b/qiskit/transpiler/passes/num_tensor_factors.py @@ -10,7 +10,7 @@ from qiskit.transpiler.basepasses import AnalysisPass -class NumTensorFactor(AnalysisPass): +class NumTensorFactors(AnalysisPass): """ An analysis pass for calculating the number of tensor factors of a DAG circuit. """ diff --git a/qiskit/transpiler/passes/resource_estimation.py b/qiskit/transpiler/passes/resource_estimation.py index dd1ceb410dcf..8983660e43b3 100644 --- a/qiskit/transpiler/passes/resource_estimation.py +++ b/qiskit/transpiler/passes/resource_estimation.py @@ -13,16 +13,16 @@ from qiskit.transpiler.passes.width import Width from qiskit.transpiler.passes.size import Size from qiskit.transpiler.passes.count_ops import CountOps -from qiskit.transpiler.passes.num_tensor_factor import NumTensorFactor +from qiskit.transpiler.passes.num_tensor_factors import NumTensorFactors class ResourceEstimation(AnalysisPass): - """ Requires Depth(), Width(), Size(), CountOps(), and NumTensorFactor(). + """ Requires Depth(), Width(), Size(), CountOps(), and NumTensorFactors(). """ def __init__(self): super().__init__() - self.requires += [Depth(), Width(), Size(), CountOps(), NumTensorFactor()] + self.requires += [Depth(), Width(), Size(), CountOps(), NumTensorFactors()] def run(self, _): pass diff --git a/test/python/transpiler/test_tensor_factor_pass.py b/test/python/transpiler/test_tensor_factor_pass.py index 222338c83002..1d7a63a71060 100644 --- a/test/python/transpiler/test_tensor_factor_pass.py +++ b/test/python/transpiler/test_tensor_factor_pass.py @@ -5,25 +5,25 @@ # 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. -"""NumTensorFactor pass testing""" +"""NumTensorFactors pass testing""" import unittest from qiskit import QuantumCircuit, QuantumRegister from qiskit.converters import circuit_to_dag -from qiskit.transpiler.passes import NumTensorFactor +from qiskit.transpiler.passes import NumTensorFactors from qiskit.test import QiskitTestCase class TestNumTensorsFactorPass(QiskitTestCase): - """ Tests for NumTensorFactor analysis methods. """ + """ Tests for NumTensorFactors analysis methods. """ def test_empty_dag(self): """ Empty DAG has 0 number of tensor factors. """ circuit = QuantumCircuit() dag = circuit_to_dag(circuit) - pass_ = NumTensorFactor() + pass_ = NumTensorFactors() _ = pass_.run(dag) self.assertEqual(pass_.property_set['num_tensor_factors'], 0) @@ -42,7 +42,7 @@ def test_just_qubits(self): circuit.cx(qr[1], qr[0]) dag = circuit_to_dag(circuit) - pass_ = NumTensorFactor() + pass_ = NumTensorFactors() _ = pass_.run(dag) self.assertEqual(pass_.property_set['num_tensor_factors'], 1) @@ -55,7 +55,7 @@ def test_depth_one(self): circuit.h(qr[1]) dag = circuit_to_dag(circuit) - pass_ = NumTensorFactor() + pass_ = NumTensorFactors() _ = pass_.run(dag) self.assertEqual(pass_.property_set['num_tensor_factors'], 2)