I am having trouble setting the state_preparation parameter of AmplificationProblem() from qiskit.algorithms. I’d like to apply a generalized version of Grover on only one of the multiple registers in my circuit.

The total number of registers in the circuit is 3. After several computation steps (including quantum counting algo) the target register gets in a superposition of non-uniform basis states - also, it is entangled with the other two registers.

According to the documentation, state_preparation parameter takes just a QuantumCircuit (sometimes also referred to as Operator). Since my circuit includes the Initialize() method from qiskit.extensions.initialize (for the other two registers), i.e. a non-unitary operation, there exists no inverse.

My questions are two-fold:

  • What should I pass as the state_preparation parameter? I just need one specific QuantumRegister to be passed, but I do not have a circuit or operator for only that register (have only the full QuantumCircuit of the entire algorithm).
  • Per the documentation/tutorials, the state_preparation operator $\mathcal{A}$ should be invertible - but the Initialize() method introduces a qubit reset, which is non-unitary. How can I circumvent this?

So as a summary I'm wondering what would be the best approach to avoid passing the entire circuit to the state_preparation?


2 Answers 2


You have to pass a circuit, but you can just remove the resets from your circuit with the initialize instruction as

>>> from qiskit.circuit import QuantumCircuit
>>> from qiskit.transpiler.passes import RemoveResetInZeroState
>>> init = QuantumCircuit(3)
>>> init.initialize([1, 0, 0, 0, 0, 0, 0, 0], init.qubits)
>>> init.draw()
q_0: ┤0                             ├
     │                              │
q_1: ┤1 Initialize(1,0,0,0,0,0,0,0) ├
     │                              │
q_2: ┤2                             ├
>>> stateprep = RemoveResetInZeroState()(init.decompose())
>>> stateprep.draw()
q_0: ┤0                 ├
     │                  │
q_1: ┤1 disentangler_dg ├
     │                  │
q_2: ┤2                 ├

Now you can pass stateprep as the state_preparation argument in the AmplitudeProblem.

  • $\begingroup$ Thanks! This indeed removes the resets from the initialized circuit. However, passing the entire circuit (which includes stateprep initialize) to state_preperation throws an error. I'll probably split the original question in two, to be able to describe the problem better. $\endgroup$
    – 26118in
    Nov 27, 2021 at 5:01

The points that I learned about passing the correct parameter state_preparation to AmplificationProblem() are as below:

  1. The operator $\mathcal{A}$ should be invertible. Therefore the circuit that we pass should not include any non-unitary operations e.g. reset (for example, if you have .initialize() somewhere in your circuit).
  2. The circuit should not include ClassicalRegister.
  3. The oracle passed to the amplification method should be in the size of the circuit's width ($\mathcal{A}$). Although the target QuantumRegister, that we aim to apply amplification on, has smaller width!

For (1.), the approach that @Cryoris suggested, is working properly. Hence accepted his answer.
There is still an issue with the result of AmplificationProblem(). For that, I've opened a separate question.
In addition, I think passing the entire circuit creates an overhead of an unnecessary number of qubits to the amplification method.


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.