Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

For the Enhancement of converters of QuadraticProgram #1061

Merged
merged 43 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2c1e762
refactored converter's constructor
a-matsuo Jun 19, 2020
eaa1cf1
Merge branch 'master' into converter_constructor
woodsp-ibm Jun 23, 2020
7dd3692
Merge branch 'master' into converter_constructor
manoelmarques Jun 24, 2020
73af26f
added baseconverter class
a-matsuo Jul 6, 2020
281ebe9
Merge branch 'master' into converter_constructor
manoelmarques Jul 6, 2020
fabdc3a
added is_compatible_with_integer_slack
a-matsuo Jul 7, 2020
8c9e474
added InequalityToEquality converter to QuadraticProgramToQubo
a-matsuo Jul 7, 2020
b657d41
Merge branch 'converter_constructor' of github.com:a-matsuo/qiskit-aq…
a-matsuo Jul 7, 2020
5669d81
refactor InequalityToEquality converter
a-matsuo Jul 7, 2020
6efbdcf
refactored encode and decode name
a-matsuo Jul 7, 2020
be17abe
Merge branch 'master' into converter_constructor
manoelmarques Jul 7, 2020
5cb01a0
renamed encode/decode to convert/interpret
a-matsuo Jul 8, 2020
64111f2
renamed encode/decode to convert/interpret
a-matsuo Jul 8, 2020
07c8e4e
fixed lint and changed to deep copy results
a-matsuo Jul 8, 2020
abb351d
added getter/setter for linear
a-matsuo Jul 8, 2020
bd0fec0
Merge branch 'master' into converter_constructor
Cryoris Jul 9, 2020
dbf881b
reflect EqualityToPenalty converter changes
a-matsuo Jul 10, 2020
8fb0c25
fixed
a-matsuo Jul 10, 2020
fb66959
fixed lint and mypy errors
a-matsuo Jul 10, 2020
cc2beb2
fixed a style error
a-matsuo Jul 10, 2020
5b4077c
moved `name` to convert method
a-matsuo Jul 15, 2020
f73fbd8
fixed IsingToQuadraticProgram
a-matsuo Jul 15, 2020
2ff04ea
added reno file
a-matsuo Jul 15, 2020
26da9c9
fixed
a-matsuo Jul 15, 2020
d512032
removed `name` arguments from converters
a-matsuo Jul 15, 2020
ae5da14
fixed issues
a-matsuo Jul 16, 2020
d034110
fixed name
a-matsuo Jul 16, 2020
7673009
Merge branch 'master' into converter_constructor
woodsp-ibm Jul 16, 2020
e8ed1f0
Merge branch 'master' into converter_constructor
woodsp-ibm Jul 17, 2020
c3ce427
Merge branch 'master' into converter_constructor
woodsp-ibm Jul 17, 2020
bb22c9f
added to_ising and from_ising
a-matsuo Jul 22, 2020
d45a18d
Merge branch 'converter_constructor' of github.com:a-matsuo/qiskit-aq…
a-matsuo Jul 22, 2020
5b56f0c
updated release notes
a-matsuo Jul 22, 2020
0f14ee1
Merge branch 'master' into converter_constructor
manoelmarques Jul 23, 2020
44149e4
fixed the release note
a-matsuo Jul 29, 2020
0827f25
Merge remote-tracking branch 'upstream/master' into converter_constru…
a-matsuo Jul 30, 2020
6c9ada1
Merge remote-tracking branch 'upstream/master' into converter_constru…
a-matsuo Aug 3, 2020
89f4695
added deprecated messages and fixed
a-matsuo Aug 3, 2020
c543a7d
fixed lint
a-matsuo Aug 3, 2020
41f7315
fixed lint
a-matsuo Aug 3, 2020
06fcdfb
moved converters to constructors of algorithms
a-matsuo Aug 3, 2020
1317ae3
Merge remote-tracking branch 'upstream/master' into converter_constru…
a-matsuo Aug 3, 2020
b3cf5db
fixed deprecated msg and added conv to results
a-matsuo Aug 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions qiskit/optimization/algorithms/grover_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, num_value_qubits: int, num_iterations: int = 3,
self._num_value_qubits = num_value_qubits
self._n_iterations = num_iterations
self._quantum_instance = None
self._qubo_converter = QuadraticProgramToQubo()

if quantum_instance is not None:
self.quantum_instance = quantum_instance
Expand Down Expand Up @@ -108,8 +109,7 @@ def solve(self, problem: QuadraticProgram) -> OptimizationResult:
self._verify_compatibility(problem)

# convert problem to QUBO
qubo_converter = QuadraticProgramToQubo()
problem_ = qubo_converter.convert(problem)
problem_ = self._qubo_converter.convert(problem)

# convert to minimization problem
sense = problem_.objective.sense
Expand Down Expand Up @@ -228,10 +228,10 @@ def solve(self, problem: QuadraticProgram) -> OptimizationResult:
fval = -fval
result = OptimizationResult(x=opt_x, variables=problem.variables, fval=fval,
results={"grover_results": grover_results,
"qubo_converter": qubo_converter})
"qubo_converter": self._qubo_converter})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert a copy of the converter?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(for all optimizers)


# cast binaries back to integers
result = qubo_converter.interpret(result)
result = self._qubo_converter.interpret(result)

return result

Expand Down
8 changes: 4 additions & 4 deletions qiskit/optimization/algorithms/minimum_eigen_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def __init__(self, min_eigen_solver: MinimumEigensolver, penalty: Optional[float
"""
self._min_eigen_solver = min_eigen_solver
self._penalty = penalty
self._qubo_converter = QuadraticProgramToQubo()

def get_compatibility_msg(self, problem: QuadraticProgram) -> str:
"""Checks whether a given problem can be solved with this optimizer.
Expand Down Expand Up @@ -141,8 +142,7 @@ def solve(self, problem: QuadraticProgram) -> MinimumEigenOptimizerResult:
self._verify_compatibility(problem)

# convert problem to QUBO
qubo_converter = QuadraticProgramToQubo()
problem_ = qubo_converter.convert(problem)
problem_ = self._qubo_converter.convert(problem)

# construct operator and offset
operator, offset = problem_.to_ising()
Expand Down Expand Up @@ -172,9 +172,9 @@ def solve(self, problem: QuadraticProgram) -> MinimumEigenOptimizerResult:
samples = [(x_str, offset, 1.0)]

# translate result back to integers
opt_res = MinimumEigenOptimizerResult(x, fval, samples, qubo_converter,
opt_res = MinimumEigenOptimizerResult(x, fval, samples, self._qubo_converter,
variables=problem.variables)
opt_res = cast(MinimumEigenOptimizerResult, qubo_converter.interpret(opt_res))
opt_res = cast(MinimumEigenOptimizerResult, self._qubo_converter.interpret(opt_res))

# translate results back to original problem
return opt_res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(self, min_eigen_optimizer: MinimumEigenOptimizer, min_num_vars: int
else:
self._min_num_vars_optimizer = MinimumEigenOptimizer(NumPyMinimumEigensolver())
self._penalty = penalty
self._qubo_converter = QuadraticProgramToQubo()

def get_compatibility_msg(self, problem: QuadraticProgram) -> str:
"""Checks whether a given problem can be solved with this optimizer.
Expand Down Expand Up @@ -124,8 +125,7 @@ def solve(self, problem: QuadraticProgram) -> OptimizationResult:
self._verify_compatibility(problem)

# convert problem to QUBO, this implicitly checks if the problem is compatible
qubo_converter = QuadraticProgramToQubo()
problem_ = qubo_converter.convert(problem)
problem_ = self._qubo_converter.convert(problem)
problem_ref = deepcopy(problem_)

# run recursive optimization until the resulting problem is small enough
Expand Down Expand Up @@ -209,9 +209,9 @@ def find_value(x, replacements, var_values):
# construct result
x_v = [var_values[x_aux.name] for x_aux in problem_ref.variables]
fval = result.fval
results = OptimizationResult(x_v, fval, (replacements, qubo_converter),
results = OptimizationResult(x_v, fval, (replacements, self._qubo_converter),
variables=problem.variables)
results = qubo_converter.interpret(results)
results = self._qubo_converter.interpret(results)
return results

def _find_strongest_correlation(self, correlations):
Expand Down
7 changes: 3 additions & 4 deletions qiskit/optimization/converters/quadratic_program_to_qubo.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def __init__(self, penalty: Optional[float] = None) -> None:

self._int_to_bin = IntegerToBinary()
self._ineq_to_eq = InequalityToEquality(mode='integer')
self._penalize_lin_eq_constraints = LinearEqualityToPenalty()
self._penalty = penalty
self._penalize_lin_eq_constraints = LinearEqualityToPenalty(penalty=penalty)

def convert(self, problem: QuadraticProgram) -> QuadraticProgram:
"""Convert a problem with linear equality constraints into new one with a QUBO form.
Expand Down Expand Up @@ -202,7 +201,7 @@ def penalty(self) -> Optional[float]:
Returns:
The penalty factor used in conversion.
"""
return self._penalty
return self._penalize_lin_eq_constraints.penalty

@penalty.setter
def penalty(self, penalty: Optional[float]) -> None:
Expand All @@ -212,4 +211,4 @@ def penalty(self, penalty: Optional[float]) -> None:
penalty: The new penalty factor.
If None is passed, penalty factor will be automatically calculated.
"""
self._penalty = penalty
self._penalize_lin_eq_constraints.penalty = penalty