def test_deutschjozsa(self, dj_input): backend = get_aer_backend('qasm_simulator') oracle = DeutschJozsaOracle(dj_input) algorithm = DeutschJozsa(oracle) result = algorithm.run(backend) if sum([int(v) for v in dj_input.values()]) == len(dj_input) / 2: self.assertTrue(result['result'] == 'balanced') else: self.assertTrue(result['result'] == 'constant')
def test_deutschjozsa(self, dj_input, mct_mode, optimization='off'): backend = BasicAer.get_backend('qasm_simulator') oracle = TruthTableOracle(dj_input, optimization=optimization, mct_mode=mct_mode) algorithm = DeutschJozsa(oracle) result = algorithm.run(backend) # print(result['circuit'].draw(line_length=10000)) if sum([int(i) for i in dj_input]) == len(dj_input) / 2: self.assertTrue(result['result'] == 'balanced') else: self.assertTrue(result['result'] == 'constant')
def test_using_dj_with_balanced_func(self): """ using dj with balanced func test """ q_v = QuantumRegister(2, name='v') q_o = QuantumRegister(1, name='o') circuit = QuantumCircuit(q_v, q_o) circuit.cx(q_v[0], q_o[0]) oracle = CustomCircuitOracle(variable_register=q_v, output_register=q_o, circuit=circuit) algorithm = DeutschJozsa(oracle) result = algorithm.run( quantum_instance=QuantumInstance(BasicAer.get_backend('qasm_simulator'))) self.assertEqual(result['result'], 'balanced')
def test_deutsch_jozsa(self, dj_input, mct_mode, optimization, simulator): """ Deutsch Jozsa test """ backend = BasicAer.get_backend(simulator) oracle = TruthTableOracle(dj_input, optimization=optimization, mct_mode=mct_mode) algorithm = DeutschJozsa(oracle) quantum_instance = QuantumInstance(backend) result = algorithm.run(quantum_instance=quantum_instance) # print(result['circuit'].draw(line_length=10000)) if sum([int(i) for i in dj_input]) == len(dj_input) / 2: self.assertTrue(result['result'] == 'balanced') else: self.assertTrue(result['result'] == 'constant')
def test_using_dj_with_constant_func(self): qv = QuantumRegister(2, name='v') qo = QuantumRegister(1, name='o') circuit = QuantumCircuit(qv, qo) circuit.x(qo[0]) oracle = CustomCircuitOracle(variable_register=qv, output_register=qo, circuit=circuit) algorithm = DeutschJozsa(oracle) result = algorithm.run(quantum_instance=QuantumInstance( BasicAer.get_backend('qasm_simulator'))) self.assertTrue(result['result'] == 'constant')
from qiskit import IBMQ IBMQ.load_account() from qiskit import BasicAer from qiskit.aqua import QuantumInstance from qiskit.aqua import run_algorithm from qiskit.aqua.algorithms import DeutschJozsa from qiskit.aqua.components.oracles import TruthTableOracle bitstr = '11110000' oracle = TruthTableOracle(bitstr) oracle.circuit.draw(output='mpl') dj = DeutschJozsa(oracle) backend = BasicAer.get_backend('qasm_simulator') result = dj.run(QuantumInstance(backend, shots=1024)) print('The truth table {} represents a {} function.'.format( bitstr, result['result'])) bitstr = '11110000' params = { 'problem': { 'name': 'functionevaluation', }, 'algorithm': { 'name': 'DeutschJozsa' }, 'oracle': { 'name': 'TruthTableOracle', 'bitmaps': [bitstr] },
def test_deutschjozsa(self, dj_input): backend = get_aer_backend('qasm_simulator') oracle = DeutschJozsaOracle(dj_input) algorithm = DeutschJozsa(oracle) result = algorithm.run(backend) self.assertTrue(result['oracle_evaluation'])