Skip to content

Commit

Permalink
Replace the InitialState components by circuits (qiskit-community/qis…
Browse files Browse the repository at this point in the history
…kit-aqua#1374)

* make chemistry initial states circuits

* put VSCF circuit in new file

* update several tests

* fix type change to tuple

* merge hf initial state and circuit

* merge initstate+circuit

* update EOH

* update hhl and qaia

* update chc and uvcc

* deprecate InitialState components

* update varformbased test

* fix running tests & mypy

* add reno

* fix iqpe test

* fix variable renaming from merge

* move to circuit.lib and use tuple

- move the initial state circuit to chemistry.circuit.library
- globally replace num_particles by a tuple instead of list of integers

* make _build_bitstr public functions
  • Loading branch information
Cryoris authored Oct 30, 2020
1 parent f511301 commit b5188f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion qiskit/aqua/algorithms/minimum_eigen_solvers/qaoa/qaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import numpy as np

from qiskit.circuit import QuantumCircuit
from qiskit.providers import BaseBackend
from qiskit.providers import Backend
from qiskit.aqua import QuantumInstance
Expand Down Expand Up @@ -67,7 +68,7 @@ def __init__(self,
operator: Union[OperatorBase, LegacyBaseOperator] = None,
optimizer: Optimizer = None,
p: int = 1,
initial_state: Optional[InitialState] = None,
initial_state: Optional[Union[QuantumCircuit, InitialState]] = None,
mixer: Union[OperatorBase, LegacyBaseOperator] = None,
initial_point: Optional[np.ndarray] = None,
gradient: Optional[Union[GradientBase, Callable[[Union[np.ndarray, List]],
Expand Down
12 changes: 7 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 @@ -12,10 +12,11 @@

"""Global X phases and parameterized problem hamiltonian."""

from typing import Optional
from typing import Optional, Union

import numpy as np

from qiskit import QuantumCircuit
from qiskit.aqua.operators import (OperatorBase, X, I, H, CircuitStateFn,
EvolutionFactory, LegacyBaseOperator)
from qiskit.aqua.components.variational_forms import VariationalForm
Expand All @@ -31,7 +32,7 @@ class QAOAVarForm(VariationalForm):
def __init__(self,
cost_operator: OperatorBase,
p: int,
initial_state: Optional[InitialState] = None,
initial_state: Optional[Union[QuantumCircuit, InitialState]] = None,
mixer_operator: Optional[OperatorBase] = None):
"""
Constructor, following the QAOA paper https://arxiv.org/abs/1411.4028
Expand Down Expand Up @@ -81,9 +82,10 @@ def construct_circuit(self, parameters, q=None):
))

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

Expand Down
2 changes: 1 addition & 1 deletion qiskit/aqua/operators/legacy/weighted_pauli_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ def two_qubit_reduction(operator, num_particles):
"Return the empty operator back.")
return operator

if isinstance(num_particles, list):
if isinstance(num_particles, (tuple, list)):
num_alpha = num_particles[0]
num_beta = num_particles[1]
else:
Expand Down

0 comments on commit b5188f6

Please sign in to comment.