I'm attempting to work through the exercise at the end of https://learn.qiskit.org/course/ch-gates/phase-kickback#phase-8-0 where I am to build and implement Deutsch's algorithm. I understand that deutsch_problem(seed=None)
will randomly determine which function is in the black box, but I am not sure how to implement it using Python coding in the def deutsch(function)
.
My attempt is below and though I have not yet run this on qasm_simulator
to see what result I get, I feel that since qc.draw()
only gives me the circuit leading up to the black-box, something must be incorrect.
My attempt
# My code within def deutsch(function):
deutsch_problem(seed=None) #I THINK this randomly decides which of the 4 functions are in the black box
#The next three lines are my attempt to turn the random function into a unitary for the circuit
usim = Aer.get_backend('unitary_simulator')
qobj = assemble(problem)
unitary = usim.run(qobj).result().get_unitary()
#The next section builds Deutsch's algorithm to measure the outcome
qc=QuantumCircuit(2,1)
qc.x(1)
qc.h([0,1])
qc.compose(unitary)
qc.h(0)
qc.measure(0,0)