Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
9d7ab72
count operations pass
1ucian0 Mar 4, 2019
9b98f9b
empty dag test
1ucian0 Mar 4, 2019
7173726
Merge branch 'master' into depth_pass
1ucian0 Mar 8, 2019
54c88f9
Merge branch 'master' of github.com:Qiskit/qiskit-terra into depth_pass
1ucian0 Mar 11, 2019
8f52ec0
Merge branch 'depth_pass' of https://github.com/1ucian0/qiskit-terra …
1ucian0 Mar 11, 2019
f9b9cff
rename
1ucian0 Mar 11, 2019
c04fc5a
test
1ucian0 Mar 11, 2019
58f82cc
Merge branch 'master' into depth_pass
1ucian0 Mar 11, 2019
9ad1e22
test rename
1ucian0 Mar 11, 2019
3039eee
Merge branch 'master' into depth_pass
1ucian0 Mar 11, 2019
3307b28
test name
1ucian0 Mar 11, 2019
376edb9
Merge branch 'depth_pass' of https://github.com/1ucian0/qiskit-terra …
1ucian0 Mar 11, 2019
e64b177
Merge branch 'master' into depth_pass
1ucian0 Mar 13, 2019
0cd5bd0
Update qiskit/transpiler/passes/resource_estimation.py
ajavadia Mar 13, 2019
3d01256
count_ops
1ucian0 Mar 13, 2019
d2edeb7
Merge branch 'depth_pass' of https://github.com/1ucian0/qiskit-terra …
1ucian0 Mar 13, 2019
4dc0828
count_ops
1ucian0 Mar 13, 2019
af57631
lint
1ucian0 Mar 13, 2019
bfd903f
changelog
1ucian0 Mar 13, 2019
3208543
Merge branch 'master' into depth_pass
1ucian0 Mar 13, 2019
2db4f68
Merge branch 'master' into depth_pass
1ucian0 Mar 18, 2019
4af2260
Merge branch 'master' into depth_pass
1ucian0 Mar 19, 2019
62aa6f0
depth pass
1ucian0 Mar 19, 2019
08b0761
size pass
1ucian0 Mar 19, 2019
e7c1817
size pass
1ucian0 Mar 19, 2019
6710a73
count_ops pass
1ucian0 Mar 19, 2019
896e394
size pass
1ucian0 Mar 19, 2019
edf90f6
NumTensorFactor pass
1ucian0 Mar 19, 2019
8b4d746
resource calculation metapass
1ucian0 Mar 19, 2019
e2682d0
lint
1ucian0 Mar 19, 2019
5604586
unused import
1ucian0 Mar 19, 2019
08e2438
Merge branch 'master' into depth_pass
1ucian0 Mar 19, 2019
04191af
Merge branch 'master' of github.com:Qiskit/qiskit-terra into depth_pass
1ucian0 Mar 21, 2019
a25741e
Merge branch 'master' into depth_pass
1ucian0 Mar 22, 2019
e4f8c83
Merge branch 'depth_pass' of https://github.com/1ucian0/qiskit-terra …
1ucian0 Mar 22, 2019
12ced28
changelog
1ucian0 Mar 22, 2019
0ecb0d2
merge
1ucian0 Mar 25, 2019
8813020
lint
1ucian0 Mar 25, 2019
657e466
Merge branch 'master' into depth_pass
1ucian0 Mar 25, 2019
50e9bee
Merge branch 'master' into depth_pass
1ucian0 Mar 26, 2019
1678b9a
Merge branch 'master' into depth_pass
1ucian0 Mar 26, 2019
5966935
Merge branch 'master' into depth_pass
1ucian0 Mar 26, 2019
e889c6f
Merge branch 'master' into depth_pass
kdk Mar 27, 2019
4add108
Merge branch 'master' into depth_pass
1ucian0 Mar 27, 2019
1524b64
Merge branch 'master' into depth_pass
1ucian0 Mar 28, 2019
0fd8e36
Merge branch 'master' into depth_pass
1ucian0 Apr 3, 2019
630a368
Update qiskit/transpiler/passes/__init__.py
ajavadia Apr 4, 2019
5fbe0cf
Update qiskit/transpiler/passes/width.py
ajavadia Apr 4, 2019
d2c1373
Update qiskit/transpiler/passes/num_tensor_factor.py
ajavadia Apr 4, 2019
c0e5e28
Update qiskit/transpiler/passes/depth.py
ajavadia Apr 4, 2019
8b1c588
Update qiskit/transpiler/passes/depth.py
ajavadia Apr 4, 2019
876123c
Update qiskit/transpiler/passes/size.py
ajavadia Apr 4, 2019
222a5df
Update qiskit/transpiler/passes/width.py
ajavadia Apr 4, 2019
8b1c08b
Update qiskit/transpiler/passes/size.py
ajavadia Apr 4, 2019
f462fae
Update qiskit/transpiler/passes/num_tensor_factor.py
ajavadia Apr 4, 2019
0f1b6d6
Merge branch 'master' into depth_pass
1ucian0 Apr 4, 2019
d7fa54e
renaming
1ucian0 Apr 4, 2019
c5138af
Merge branch 'master' into depth_pass
1ucian0 Apr 4, 2019
fe3c5f7
Merge branch 'master' into depth_pass
1ucian0 Apr 4, 2019
4ede9b4
Merge branch 'master' into depth_pass
ajavadia Apr 4, 2019
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
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +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 new resource estimation passes: ``Depth``, ``Width``, ``Size``, ``CountOps``, and
``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:
Expand All @@ -61,7 +63,6 @@ Added
- Added an ``Instruction.mirror()`` method that mirrors a composite instruction
(reverses its sub-instructions) (#1816).


Changed
-------

Expand Down
3 changes: 2 additions & 1 deletion qiskit/dagcircuit/dagcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,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."""
Expand Down
6 changes: 6 additions & 0 deletions qiskit/transpiler/passes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
from .unroller import Unroller
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_factors import NumTensorFactors
from .dag_fixed_point import DAGFixedPoint
from .optimize_1q_gates import Optimize1qGates
from .decompose import Decompose
Expand Down
18 changes: 18 additions & 0 deletions qiskit/transpiler/passes/count_ops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- 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()
18 changes: 18 additions & 0 deletions qiskit/transpiler/passes/depth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- 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 calculating the depth of a DAG circuit.
"""
from qiskit.transpiler.basepasses import AnalysisPass


class Depth(AnalysisPass):
""" An analysis pass for calculating the depth of a DAG circuit.
"""

def run(self, dag):
self.property_set['depth'] = dag.depth()
18 changes: 18 additions & 0 deletions qiskit/transpiler/passes/num_tensor_factors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- 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 calculating the number of tensor factors of a DAG circuit.
"""
from qiskit.transpiler.basepasses import AnalysisPass


class NumTensorFactors(AnalysisPass):
""" An analysis pass for calculating the number of tensor factors of a DAG circuit.
"""

def run(self, dag):
self.property_set['num_tensor_factors'] = dag.num_tensor_factors()
28 changes: 28 additions & 0 deletions qiskit/transpiler/passes/resource_estimation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- 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 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_factors import NumTensorFactors


class ResourceEstimation(AnalysisPass):
""" Requires Depth(), Width(), Size(), CountOps(), and NumTensorFactors().
"""

def __init__(self):
super().__init__()
self.requires += [Depth(), Width(), Size(), CountOps(), NumTensorFactors()]

def run(self, _):
pass
18 changes: 18 additions & 0 deletions qiskit/transpiler/passes/size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- 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 calculating the size of a DAG circuit.
"""
from qiskit.transpiler.basepasses import AnalysisPass


class Size(AnalysisPass):
""" An analysis pass for calculating the size of a DAG circuit.
"""

def run(self, dag):
self.property_set['size'] = dag.size()
18 changes: 18 additions & 0 deletions qiskit/transpiler/passes/width.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- 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 calculating the width of a DAG circuit.
"""
from qiskit.transpiler.basepasses import AnalysisPass


class Width(AnalysisPass):
""" An analysis pass for calculating the width of a DAG circuit.
"""

def run(self, dag):
self.property_set['width'] = dag.width()
52 changes: 52 additions & 0 deletions test/python/transpiler/test_count_ops_pass.py
Original file line number Diff line number Diff line change
@@ -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_just_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()
65 changes: 65 additions & 0 deletions test/python/transpiler/test_depth_pass.py
Original file line number Diff line number Diff line change
@@ -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.

"""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_just_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()
58 changes: 58 additions & 0 deletions test/python/transpiler/test_resource_estimation_pass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- 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.

"""ResourceEstimation pass testing"""

import unittest

from qiskit import QuantumRegister, QuantumCircuit
from qiskit.transpiler import PassManager, transpile
from qiskit.transpiler.passes import ResourceEstimation
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."""
circuit = QuantumCircuit()
passmanager = PassManager()
passmanager.append(ResourceEstimation())
_ = transpile(circuit, FakeRueschlikon(), pass_manager=passmanager)

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'], {})

def test_just_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])

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()
Loading