Skip to content

Commit

Permalink
Skip classical function compiler tests if tweedledum unavailable. (#5266
Browse files Browse the repository at this point in the history
)

* Skip classical function compiler tests if tweedledum unavailable.

* remove skip

Co-authored-by: Luciano Bello <luciano.bello@ibm.com>
  • Loading branch information
kdk and Luciano Bello authored Oct 29, 2020
1 parent c8de447 commit c7c19a0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
# that they have been altered from the originals.

"""Tests ClassicalFunction as a gate."""
import unittest

from qiskit.test import QiskitTestCase

from qiskit.circuit.classicalfunction import classical_function as compile_classical_function
from qiskit.circuit.classicalfunction.classicalfunction import HAS_TWEEDLEDUM

from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import XGate
Expand All @@ -25,6 +27,7 @@
class TestOracleDecomposition(QiskitTestCase):
"""Tests ClassicalFunction.decomposition."""

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_grover_oracle(self):
""" grover_oracle.decomposition"""
oracle = compile_classical_function(examples.grover_oracle)
Expand Down
7 changes: 7 additions & 0 deletions test/python/classical_function_compiler/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
# that they have been altered from the originals.

"""Tests the classicalfunction parser."""
import unittest

from qiskit.circuit.classicalfunction import ClassicalFunctionParseError
from qiskit.circuit.classicalfunction import classical_function as compile_classical_function
from qiskit.circuit.classicalfunction.classicalfunction import HAS_TWEEDLEDUM

from qiskit.test import QiskitTestCase
from . import bad_examples as examples

Expand All @@ -25,24 +28,28 @@ def assertExceptionMessage(self, context, message):
"""Asserts the message of an exception context"""
self.assertTrue(message in context.exception.args[0])

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_id_bad_return(self):
"""Trying to parse examples.id_bad_return raises ClassicalFunctionParseError"""
with self.assertRaises(ClassicalFunctionParseError) as context:
compile_classical_function(examples.id_bad_return)
self.assertExceptionMessage(context, 'return type error')

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_id_no_type_arg(self):
"""Trying to parse examples.id_no_type_arg raises ClassicalFunctionParseError"""
with self.assertRaises(ClassicalFunctionParseError) as context:
compile_classical_function(examples.id_no_type_arg)
self.assertExceptionMessage(context, 'argument type is needed')

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_id_no_type_return(self):
"""Trying to parse examples.id_no_type_return raises ClassicalFunctionParseError"""
with self.assertRaises(ClassicalFunctionParseError) as context:
compile_classical_function(examples.id_no_type_return)
self.assertExceptionMessage(context, 'return type is needed')

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_out_of_scope(self):
"""Trying to parse examples.out_of_scope raises ClassicalFunctionParseError"""
with self.assertRaises(ClassicalFunctionParseError) as context:
Expand Down
3 changes: 3 additions & 0 deletions test/python/classical_function_compiler/test_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
# that they have been altered from the originals.

"""Tests LogicNetwork.simulate method."""
import unittest

from ddt import ddt, data
from qiskit.circuit.classicalfunction import classical_function as compile_classical_function
from qiskit.circuit.classicalfunction.classicalfunction import HAS_TWEEDLEDUM
from qiskit.test import QiskitTestCase
from .utils import get_truthtable_from_function, example_list

Expand All @@ -22,6 +24,7 @@
class TestSimulate(QiskitTestCase):
"""Tests LogicNetwork.simulate method"""
@data(*example_list())
@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_(self, a_callable):
"""Tests LogicSimulate.simulate() on all the examples"""
network = compile_classical_function(a_callable)
Expand Down
4 changes: 4 additions & 0 deletions test/python/classical_function_compiler/test_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
# that they have been altered from the originals.

"""Tests classicalfunction compiler synthesis."""
import unittest

from qiskit.test import QiskitTestCase

from qiskit.circuit.classicalfunction import classical_function as compile_classical_function
from qiskit.circuit.classicalfunction.classicalfunction import HAS_TWEEDLEDUM

from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library.standard_gates import XGate
Expand All @@ -25,6 +27,7 @@
class TestSynthesis(QiskitTestCase):
"""Tests ClassicalFunction.synth method."""

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_grover_oracle(self):
"""Synthesis of grover_oracle example"""
oracle = compile_classical_function(examples.grover_oracle)
Expand All @@ -36,6 +39,7 @@ def test_grover_oracle(self):
self.assertEqual(quantum_circuit.name, 'grover_oracle')
self.assertEqual(quantum_circuit, expected)

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_grover_oracle_arg_regs(self):
"""Synthesis of grover_oracle example with arg_regs"""
oracle = compile_classical_function(examples.grover_oracle)
Expand Down
10 changes: 10 additions & 0 deletions test/python/classical_function_compiler/test_typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,58 @@
# that they have been altered from the originals.

"""Tests classicalfunction compiler type checker."""
import unittest

from qiskit.test import QiskitTestCase
from qiskit.circuit.classicalfunction import ClassicalFunctionCompilerTypeError
from qiskit.circuit.classicalfunction import classical_function as compile_classical_function
from qiskit.circuit.classicalfunction.classicalfunction import HAS_TWEEDLEDUM

from . import examples, bad_examples


class TestTypeCheck(QiskitTestCase):
"""Tests classicalfunction compiler type checker (good examples)."""

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_id(self):
"""Tests examples.identity type checking"""
network = compile_classical_function(examples.identity)
self.assertEqual(network.args, ['a'])
self.assertEqual(network.types, [{'Int1': 'type', 'a': 'Int1', 'return': 'Int1'}])

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_bool_not(self):
"""Tests examples.bool_not type checking"""
network = compile_classical_function(examples.bool_not)
self.assertEqual(network.args, ['a'])
self.assertEqual(network.types, [{'Int1': 'type', 'a': 'Int1', 'return': 'Int1'}])

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_id_assign(self):
"""Tests examples.id_assing type checking"""
network = compile_classical_function(examples.id_assing)
self.assertEqual(network.args, ['a'])
self.assertEqual(network.types, [{'Int1': 'type', 'a': 'Int1',
'b': 'Int1', 'return': 'Int1'}])

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_bit_and(self):
"""Tests examples.bit_and type checking"""
network = compile_classical_function(examples.bit_and)
self.assertEqual(network.args, ['a', 'b'])
self.assertEqual(network.types, [{'Int1': 'type', 'a': 'Int1',
'b': 'Int1', 'return': 'Int1'}])

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_bit_or(self):
"""Tests examples.bit_or type checking"""
network = compile_classical_function(examples.bit_or)
self.assertEqual(network.args, ['a', 'b'])
self.assertEqual(network.types, [{'Int1': 'type', 'a': 'Int1',
'b': 'Int1', 'return': 'Int1'}])

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_bool_or(self):
"""Tests examples.bool_or type checking"""
network = compile_classical_function(examples.bool_or)
Expand All @@ -69,6 +78,7 @@ def assertExceptionMessage(self, context, message):
"""Asserts the message of an exception context"""
self.assertTrue(message in context.exception.args[0])

@unittest.skipUnless(HAS_TWEEDLEDUM, 'tweedledum not available')
def test_bit_not(self):
"""Int1wise not does not work on bit (aka bool)
~True # -2
Expand Down

0 comments on commit c7c19a0

Please sign in to comment.