Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maxcut for graph with non-consecutive nodes/verticies #578

Open
Siheon-Park opened this issue Dec 8, 2023 · 1 comment
Open

Maxcut for graph with non-consecutive nodes/verticies #578

Siheon-Park opened this issue Dec 8, 2023 · 1 comment
Labels
type: feature request New feature or request

Comments

@Siheon-Park
Copy link

What should we add?

Problem

qiskit_optimization.applications.max_cut.Maxcut cannot work along with the graph non-consecutive nodes (e.g. V={0, 1, 4, 5}). This may result in minor inconvenience when we create graph and then remove nodes, such as isolated nodes. Obviously, it is not necessary to keep isolated nodes (i.e., nodes not connected to any other nodes) for max-cut problem and waste qubits.

Solution

Simply replace line 44 in file qiskit_optimization.applications.max_cut.py in current git version (2b5c37b) from

x = {i: mdl.binary_var(name=f"x_{i}") for i in range(self._graph.number_of_nodes())}

to

x = {node: mdl.binary_var(name=f"x_{node}") for node in list(self._graph.nodes)}

See my forked repo

Test

It is so simple that it does not require testing. This is also the reason why I made issue instead of pull request; only a single line changed. However, it is bugging me that I have to inherit the well-made Maxcut class every time to insert this feature.
It would be great to add this line of code to this repo to be feasible with non-consecutive nodes.

@Siheon-Park Siheon-Park added the type: feature request New feature or request label Dec 8, 2023
@woodsp-ibm
Copy link
Member

It is so simple that it does not require testing.

For such a change a new unit test would be required to ensure that not only it works with non-consecutive nodes now but continues to do so in the future as things change/evolve.

The change would also warrant a release note to make others aware that this capability now exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants