• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

qiskit-community / qiskit-optimization / 15315042704

27 May 2025 03:22PM CUT coverage: 92.103%. Remained the same
15315042704

push

github

web-flow
Update intersphinx mapping and other URLs pointing to IQP Classic (#662)

* Update intersphinx mapping and other URLs pointing to IQP Classic

* fix copyright date

5680 of 6167 relevant lines covered (92.1%)

0.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.95
/qiskit_optimization/applications/graph_optimization_application.py
1
# This code is part of a Qiskit project.
2
#
3
# (C) Copyright IBM 2018, 2023.
4
#
5
# This code is licensed under the Apache License, Version 2.0. You may
6
# obtain a copy of this license in the LICENSE.txt file in the root directory
7
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8
#
9
# Any modifications or derivative works of this code must retain this
10
# copyright notice, and modified files need to carry a notice indicating
11
# that they have been altered from the originals.
12

13
"""An abstract class for graph optimization application classes."""
14

15
from abc import abstractmethod
1✔
16
from typing import Dict, List, Optional, Union
1✔
17

18
import networkx as nx
1✔
19
import numpy as np
1✔
20

21
import qiskit_optimization.optionals as _optionals
1✔
22

23
from ..algorithms import OptimizationResult
1✔
24
from .optimization_application import OptimizationApplication
1✔
25

26

27
class GraphOptimizationApplication(OptimizationApplication):
1✔
28
    """
29
    An abstract class for graph optimization applications.
30
    """
31

32
    def __init__(self, graph: Union[nx.Graph, np.ndarray, List]) -> None:
1✔
33
        """
34
        Args:
35
            graph: A graph representing a problem. It can be specified directly as a
36
                `NetworkX <https://networkx.org/>`_ graph,
37
                or as an array or list format suitable to build out a NetworkX graph.
38
        """
39
        # The view of the graph is stored which means the graph can not be changed.
40
        self._graph = nx.Graph(graph).copy(as_view=True)
1✔
41

42
    @_optionals.HAS_MATPLOTLIB.require_in_call
1✔
43
    def draw(
1✔
44
        self,
45
        result: Optional[Union[OptimizationResult, np.ndarray]] = None,
46
        pos: Optional[Dict[int, np.ndarray]] = None,
47
    ) -> None:
48
        """Draw a graph with the result. When the result is None, draw an original graph without
49
        colors.
50

51
        Args:
52
            result: The calculated result for the problem
53
            pos: The positions of nodes
54
        """
55
        if result is None:
×
56
            nx.draw(self._graph, pos=pos, with_labels=True)
×
57
        else:
58
            self._draw_result(result, pos)
×
59

60
    @abstractmethod
1✔
61
    def _draw_result(
1✔
62
        self,
63
        result: Union[OptimizationResult, np.ndarray],
64
        pos: Optional[Dict[int, np.ndarray]] = None,
65
    ) -> None:
66
        """Draw the result with colors
67

68
        Args:
69
            result : The calculated result for the problem
70
            pos: The positions of nodes
71
        """
72
        pass
×
73

74
    @property
1✔
75
    def graph(self) -> nx.Graph:
1✔
76
        """Getter of the graph
77

78
        Returns:
79
            A graph for a problem
80
        """
81
        return self._graph
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc