Exemplo n.º 1
0
 def test_bit_not(self):
     """Int1wise not does not work on bit (aka bool)
       ~True   # -2
       ~False  # -1
     """
     with self.assertRaises(ClassicalFunctionCompilerTypeError) as context:
         compile_classical_function(bad_examples.bit_not)
     self.assertExceptionMessage(context, 'does not operate with Int1 type')
Exemplo n.º 2
0
 def test_bool_or(self):
     """Tests examples.bool_or type checking"""
     network = compile_classical_function(examples.bool_or)
     self.assertEqual(network.args, ["a", "b"])
     self.assertEqual(
         network.types, [{"Int1": "type", "a": "Int1", "b": "Int1", "return": "Int1"}]
     )
Exemplo n.º 3
0
 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'
     }])
Exemplo n.º 4
0
 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"
     }])
Exemplo n.º 5
0
    def test_grover_oracle(self):
        """Synthesis of grover_oracle example"""
        oracle = compile_classical_function(examples.grover_oracle)
        quantum_circuit = oracle.synth()

        expected = QuantumCircuit(5)
        expected.append(XGate().control(4, ctrl_state="1010"), [0, 1, 2, 3, 4])

        self.assertEqual(quantum_circuit.name, "grover_oracle")
        self.assertEqual(quantum_circuit, expected)
Exemplo n.º 6
0
    def test_grover_oracle(self):
        """grover_oracle.decomposition"""
        oracle = compile_classical_function(examples.grover_oracle)
        quantum_circuit = QuantumCircuit(5)
        quantum_circuit.append(oracle, [2, 1, 0, 3, 4])

        expected = QuantumCircuit(5)
        expected.append(XGate().control(4, ctrl_state="1010"), [2, 1, 0, 3, 4])

        self.assertEqual(quantum_circuit.decompose(), expected)
Exemplo n.º 7
0
 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'
     }])
    def test_grover_oracle_arg_regs(self):
        """Synthesis of grover_oracle example with arg_regs"""
        oracle = compile_classical_function(examples.grover_oracle)
        quantum_circuit = oracle.synth(registerless=False)

        qr_a = QuantumRegister(1, 'a')
        qr_b = QuantumRegister(1, 'b')
        qr_c = QuantumRegister(1, 'c')
        qr_d = QuantumRegister(1, 'd')
        qr_return = QuantumRegister(1, 'return')
        expected = QuantumCircuit(qr_d, qr_c, qr_b, qr_a, qr_return)
        expected.append(XGate().control(4, ctrl_state='0101'),
                        [qr_d[0], qr_c[0], qr_b[0], qr_a[0], qr_return[0]])

        self.assertEqual(quantum_circuit.name, 'grover_oracle')
        self.assertEqual(quantum_circuit, expected)
Exemplo n.º 9
0
 def test_(self, a_callable):
     """Tests LogicSimulate.simulate() on all the examples"""
     network = compile_classical_function(a_callable)
     truth_table = network.simulate()
     self.assertEqual(truth_table, get_truthtable_from_function(a_callable))
Exemplo n.º 10
0
 def test_out_of_scope(self):
     """Trying to parse examples.out_of_scope raises ClassicalFunctionParseError"""
     with self.assertRaises(ClassicalFunctionParseError) as context:
         compile_classical_function(examples.out_of_scope)
     self.assertExceptionMessage(context, 'out of scope: c')
Exemplo n.º 11
0
 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')
Exemplo n.º 12
0
 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")