Skip to content

Commit

Permalink
Don't add Hadamards to a user-defined initial state in QAOA (qiskit-c…
Browse files Browse the repository at this point in the history
…ommunity/qiskit-aqua#1362)

* Fixing QAOA initial_state problem

* fixing code style warnings

* Creating QAOA-initial_state-dont-mix-with-Hadamards bugfix test and a release note for the bugfix.

* Removing code that appeared in pull request due to error

* Fixing import math error

* Fixing code style issues.

Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
  • Loading branch information
Milos9304 and woodsp-ibm authored Oct 23, 2020
1 parent 1fd25f1 commit bb156ac
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions qiskit/aqua/algorithms/minimum_eigen_solvers/qaoa/var_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import numpy as np

from qiskit.aqua.operators import (OperatorBase, X, I, H, Zero, CircuitStateFn,
from qiskit.aqua.operators import (OperatorBase, X, I, H, CircuitStateFn,
EvolutionFactory, LegacyBaseOperator)
from qiskit.aqua.components.variational_forms import VariationalForm
from qiskit.aqua.components.initial_states import InitialState
Expand Down Expand Up @@ -80,13 +80,12 @@ def construct_circuit(self, parameters, q=None):
self.num_parameters, len(parameters)
))

circuit = (H ^ self._num_qubits)
# initialize circuit, possibly based on given register/initial state
if self._initial_state is not None:
init_state = CircuitStateFn(self._initial_state.construct_circuit('circuit'))
stateVector = CircuitStateFn(self._initial_state.construct_circuit('circuit'))
circuit = stateVector.to_circuit_op()
else:
init_state = Zero
circuit = circuit.compose(init_state)
circuit = (H ^ self._num_qubits)

for idx in range(self._p):
circuit = (self._cost_operator * parameters[idx]).exp_i().compose(circuit)
Expand Down

0 comments on commit bb156ac

Please sign in to comment.