Trying to implement Grover under Qiskit I found an example with
good_state = ['110','101']
For a given $n$ it possible to define good_state as "any string of $n$ bits whose last bit is 1"?
And if so, how?
1 Answer
Yes, there's two options:
- Define the good state as "1" and use only the last bit as objective qubit:
from qiskit.algorithms import EstimationProblem
stateprep = # your state preparation, or "A" operator
n = # index of your target qubit
problem = EstimationProblem(stateprep, objective_qubits=[n])
# the good state default is 1, so you don't need to specify it, but if you want to:
# problem = EstimationProblem(stateprep, objective_qubits=[n], is_good_state="1")
- Define the
is_good_state
via a function
from qiskit.algorithms import EstimationProblem
stateprep = # your state preparation, or "A" operator
n = # index of your target qubit
def is_good_state(bitstring):
return bitstring[n] == "1" # note: maybe the bitstring needs to be reverted
problem = EstimationProblem(stateprep, objective_qubits=list(range(n)), is_good_state=is_good_state)
I would strongly suggest option 1, that'll generate the more efficient circuits.
-
$\begingroup$ Thank you very much for your prompt and very helpful response! $\endgroup$ May 23 at 15:34