def test_with_pass_manager(self): """ Test Bernstein Vazirani using PassManager """ quantum_instance = QuantumInstance( BasicAer.get_backend('qasm_simulator'), pass_manager=level_0_pass_manager( PassManagerConfig(basis_gates=['cx', 'u1', 'u2', 'u3']))) alg = BernsteinVazirani(oracle=TruthTableOracle(bitmaps="01100110"), quantum_instance=quantum_instance) result = alg.run() self.assertEqual(result['result'], '011')
def test_bernsteinvazirani(self, bv_input, mct_mode, optimization='off'): nbits = int(math.log(len(bv_input), 2)) # compute the ground-truth classically parameter = "" for i in reversed(range(nbits)): bit = bv_input[2 ** i] parameter += bit backend = get_aer_backend('qasm_simulator') oracle = TruthTableOracle(bv_input, optimization=optimization, mct_mode=mct_mode) algorithm = BernsteinVazirani(oracle) result = algorithm.run(backend) # print(result['circuit'].draw(line_length=10000)) self.assertEqual(result['result'], parameter)
def test_bernstein_vazirani(self, bv_input, mct_mode, optimization, simulator): """ Bernstein Vazirani test """ nbits = int(math.log(len(bv_input), 2)) # compute the ground-truth classically parameter = "" for i in reversed(range(nbits)): bit = bv_input[2**i] parameter += bit backend = BasicAer.get_backend(simulator) oracle = TruthTableOracle(bv_input, optimization=optimization, mct_mode=mct_mode) algorithm = BernsteinVazirani(oracle) quantum_instance = QuantumInstance(backend) result = algorithm.run(quantum_instance=quantum_instance) # print(result['circuit'].draw(line_length=10000)) self.assertEqual(result['result'], parameter)
def test_aqua_algorithm() -> None: backends: List[Backend] = [AerBackend(), AerStateBackend()] if use_qulacs: backends.append(QulacsBackend()) for b in backends: for comp in (None, b.default_compilation_pass()): if use_qulacs and type(b) == QulacsBackend and comp is None: continue tb = TketBackend(b, comp) ora = TruthTableOracle(bitmaps="01100110") alg = BernsteinVazirani(oracle=ora, quantum_instance=tb) result = alg.run() assert result["result"] == "011" alg = DeutschJozsa(oracle=ora, quantum_instance=tb) result = alg.run() assert result["result"] == "balanced" ora = TruthTableOracle(bitmaps="11111111") alg = DeutschJozsa(oracle=ora, quantum_instance=tb) result = alg.run() assert result["result"] == "constant"
def test_bernsteinvazirani(self, bv_input): backend = get_aer_backend('qasm_simulator') oracle = BernsteinVaziraniOracle(bv_input) algorithm = BernsteinVazirani(oracle) result = algorithm.run(backend) self.assertTrue(result['oracle_evaluation'])