コード例 #1
0
    def test_simon(self, simon_input, mct_mode, optimization, simulator):
        """ Simon test """
        # find the two keys that have matching values
        nbits = int(math.log(len(simon_input[0]), 2))
        vals = list(zip(*simon_input))[::-1]

        def find_pair():
            for i, val in enumerate(vals):
                for j in range(i + 1, len(vals)):
                    if val == vals[j]:
                        return i, j
            return 0, 0

        k_1, k_2 = find_pair()
        hidden = np.binary_repr(k_1 ^ k_2, nbits)

        backend = BasicAer.get_backend(simulator)
        oracle = TruthTableOracle(simon_input,
                                  optimization=optimization,
                                  mct_mode=mct_mode)
        algorithm = Simon(oracle)
        quantum_instance = QuantumInstance(backend)
        result = algorithm.run(quantum_instance=quantum_instance)
        # print(result['circuit'].draw(line_length=10000))
        self.assertEqual(result['result'], hidden)
コード例 #2
0
    def test_simon(self, simon_input, mct_mode, optimization='off'):
        # find the two keys that have matching values
        nbits = int(math.log(len(simon_input[0]), 2))
        vals = list(zip(*simon_input))[::-1]

        def find_pair():
            for i in range(len(vals)):
                for j in range(i + 1, len(vals)):
                    if vals[i] == vals[j]:
                        return i, j
            return 0, 0

        k1, k2 = find_pair()
        hidden = np.binary_repr(k1 ^ k2, nbits)

        backend = get_aer_backend('qasm_simulator')
        oracle = TruthTableOracle(simon_input, optimization=optimization, mct_mode=mct_mode)
        algorithm = Simon(oracle)
        result = algorithm.run(backend)
        # print(result['circuit'].draw(line_length=10000))
        self.assertEqual(result['result'], hidden)
コード例 #3
0
 def test_simon(self, simon_input):
     backend = get_aer_backend('qasm_simulator')
     oracle = SimonOracle(simon_input)
     algorithm = Simon(oracle)
     result = algorithm.run(backend)
     self.assertTrue(result['oracle_evaluation'])