Skip to content

Commit

Permalink
update other optimizers
Browse files Browse the repository at this point in the history
  • Loading branch information
t-imamichi committed Nov 11, 2022
1 parent 8a042d9 commit 7795bbc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 40 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ from docplex.mp.model import Model
from qiskit_optimization.algorithms import MinimumEigenOptimizer
from qiskit_optimization.translators import from_docplex_mp

from qiskit.utils import algorithm_globals, QuantumInstance
from qiskit import BasicAer
from qiskit.algorithms import QAOA
from qiskit.utils import algorithm_globals
from qiskit.primitives import Sampler
from qiskit.algorithms.minimum_eigensolvers import QAOA
from qiskit.algorithms.optimizers import SPSA

# Generate a graph of 4 nodes
Expand All @@ -97,9 +97,8 @@ seed = 1234
algorithm_globals.random_seed = seed

spsa = SPSA(maxiter=250)
backend = BasicAer.get_backend('qasm_simulator')
q_i = QuantumInstance(backend=backend, seed_simulator=seed, seed_transpiler=seed)
qaoa = QAOA(optimizer=spsa, reps=5, quantum_instance=q_i)
sampler = Sampler()
qaoa = QAOA(sampler=sampler, optimizer=spsa, reps=5)
algorithm = MinimumEigenOptimizer(qaoa)
result = algorithm.solve(problem)
print(result.prettyprint()) # prints solution, x=[1, 0, 1, 0], the cost, fval=4
Expand Down
16 changes: 8 additions & 8 deletions qiskit_optimization/algorithms/admm_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
from typing import List, Optional, Tuple, cast

import numpy as np
from qiskit.algorithms import NumPyMinimumEigensolver
from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver

from ..converters import MaximizeToMinimize
from ..problems.constraint import Constraint
from ..problems.linear_constraint import LinearConstraint
from ..problems.linear_expression import LinearExpression
from ..problems.quadratic_program import QuadraticProgram
from ..problems.variable import Variable, VarType
from .minimum_eigen_optimizer import MinimumEigenOptimizer
from .optimization_algorithm import (
OptimizationResultStatus,
OptimizationAlgorithm,
OptimizationResult,
OptimizationResultStatus,
)
from .slsqp_optimizer import SlsqpOptimizer
from ..problems.constraint import Constraint
from ..problems.linear_constraint import LinearConstraint
from ..problems.linear_expression import LinearExpression
from ..problems.quadratic_program import QuadraticProgram
from ..problems.variable import VarType, Variable
from ..converters import MaximizeToMinimize

UPDATE_RHO_BY_TEN_PERCENT = 0
UPDATE_RHO_BY_RESIDUALS = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,22 @@

from copy import deepcopy
from enum import Enum
from typing import Optional, Union, List, Tuple, Dict, cast
from typing import Dict, List, Optional, Tuple, Union, cast

import numpy as np
from qiskit.algorithms import NumPyMinimumEigensolver
from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver
from qiskit.utils.validation import validate_min

from .minimum_eigen_optimizer import (
MinimumEigenOptimizer,
MinimumEigenOptimizationResult,
)
from ..converters.quadratic_program_to_qubo import QuadraticProgramConverter, QuadraticProgramToQubo
from ..exceptions import QiskitOptimizationError
from ..problems import Variable
from ..problems.quadratic_program import QuadraticProgram
from .minimum_eigen_optimizer import MinimumEigenOptimizationResult, MinimumEigenOptimizer
from .optimization_algorithm import (
OptimizationResultStatus,
OptimizationAlgorithm,
OptimizationResult,
OptimizationResultStatus,
)
from ..converters.quadratic_program_to_qubo import (
QuadraticProgramToQubo,
QuadraticProgramConverter,
)
from ..exceptions import QiskitOptimizationError
from ..problems import Variable
from ..problems.quadratic_program import QuadraticProgram


class IntermediateResult(Enum):
Expand Down
17 changes: 5 additions & 12 deletions qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
# (C) Copyright IBM 2021, 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -14,26 +14,19 @@

import copy
from abc import ABC, abstractmethod
from typing import Optional, List, Union, Dict, Tuple, cast
from typing import Dict, List, Optional, Tuple, Union, cast

import numpy as np
from qiskit import QuantumCircuit
from qiskit.algorithms import QAOA
from qiskit.algorithms.minimum_eigensolvers import QAOA
from qiskit.circuit import Parameter

from .minimum_eigen_optimizer import (
MinimumEigenOptimizer,
MinimumEigenOptimizationResult,
)
from .optimization_algorithm import (
OptimizationAlgorithm,
OptimizationResultStatus,
SolutionSample,
)
from ..converters.quadratic_program_converter import QuadraticProgramConverter
from ..exceptions import QiskitOptimizationError
from ..problems.quadratic_program import QuadraticProgram
from ..problems.variable import VarType
from .minimum_eigen_optimizer import MinimumEigenOptimizationResult, MinimumEigenOptimizer
from .optimization_algorithm import OptimizationAlgorithm, OptimizationResultStatus, SolutionSample


class BaseAggregator(ABC):
Expand Down

0 comments on commit 7795bbc

Please sign in to comment.