def test_simon(self, simon_input, mct_mode, optimization, simulator): # 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 = 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)
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'])