2
$\begingroup$

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?

$\endgroup$

1 Answer 1

3
$\begingroup$

Yes, there's two options:

  1. 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") 
  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.

$\endgroup$
1
  • $\begingroup$ Thank you very much for your prompt and very helpful response! $\endgroup$ Commented May 23, 2023 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.