Skip to content

Commit

Permalink
Removed plotly and matplotlib from top-level imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Framba-Luca committed Jun 22, 2023
1 parent 5e8b9e3 commit d8585ab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
5 changes: 3 additions & 2 deletions unified_planning/plot/causal_graph_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
#

from itertools import chain, product
from unified_planning.exceptions import (
UPUsageError,
UPNoSuitableEngineAvailableException,
Expand All @@ -38,7 +37,7 @@
)
from unified_planning.engines import CompilationKind

import matplotlib.pyplot as plt # type: ignore[import]
from itertools import chain, product
import networkx as nx
from typing import (
Any,
Expand Down Expand Up @@ -114,6 +113,8 @@ def plot_causal_graph(
maintained in any way and it might be removed or modified at any moment.
"""
# param "sanitization"
import matplotlib.pyplot as plt # type: ignore[import]

if generate_edge_label is None:
edge_label_function: Callable[
[Action, Sequence[FNode]], str
Expand Down
20 changes: 16 additions & 4 deletions unified_planning/plot/plan_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#


from fractions import Fraction
from functools import partial
import unified_planning as up
from unified_planning.engines.sequential_simulator import (
UPSequentialSimulator,
Expand Down Expand Up @@ -54,8 +52,8 @@
)

import datetime
import plotly.express as px # type: ignore[import]
import matplotlib.pyplot as plt # type: ignore[import]
from fractions import Fraction
from functools import partial
import networkx as nx
from typing import (
Any,
Expand Down Expand Up @@ -167,6 +165,8 @@ def plot_sequential_plan(
method; use carefully. NOTE: This parameters is not guaranteed to be
maintained in any way and it might be removed or modified at any moment.
"""
import matplotlib.pyplot as plt # type: ignore[import]

if expression_or_expressions is None and metric_or_metrics is None:
# plot sequential_plan as graph
graph = nx.DiGraph()
Expand Down Expand Up @@ -246,6 +246,9 @@ def plot_time_triggered_plan(
:param figsize: Width and height in pixels/100; for example (10, 15) means 1000
pixels wide and 1500 pixels high.
"""

import plotly.express as px # type: ignore[import]

if figsize is None:
figsize = FIGSIZE
assert figsize is not None
Expand Down Expand Up @@ -370,6 +373,8 @@ def plot_stn_plan(
method; use carefully. NOTE: This parameters is not guaranteed to be
maintained in any way and it might be removed or modified at any moment.
"""
import matplotlib.pyplot as plt # type: ignore[import]

# param "sanitization"
if generate_edge_label is None:
edge_label_function: Callable[
Expand Down Expand Up @@ -475,6 +480,8 @@ def plot_contingent_plan(
method; use carefully. NOTE: This parameters is not guaranteed to be
maintained in any way and it might be removed or modified at any moment.
"""
import matplotlib.pyplot as plt # type: ignore[import]

# param "sanitization"
if generate_edge_label is None:
edge_label_function: Callable[
Expand Down Expand Up @@ -575,6 +582,8 @@ def plot_partial_order_plan(
method; use carefully. NOTE: This parameters is not guaranteed to be
maintained in any way and it might be removed or modified at any moment.
"""
import matplotlib.pyplot as plt # type: ignore[import]

fig, _, _ = draw_base_graph(
plan._graph,
figsize=figsize,
Expand Down Expand Up @@ -644,6 +653,9 @@ def _plot_expressions(
filename: Optional[str] = None,
figsize: Optional[Tuple[float, float]] = None,
):

import plotly.express as px # type: ignore[import]

if figsize is None:
figsize = FIGSIZE
assert figsize is not None
Expand Down
38 changes: 6 additions & 32 deletions unified_planning/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,17 @@
#


from fractions import Fraction
from functools import partial
import unified_planning as up
from unified_planning.engines.sequential_simulator import (
UPSequentialSimulator,
evaluate_quality_metric_in_initial_state,
evaluate_quality_metric,
)
from unified_planning.model import (
FNode,
Problem,
State,
PlanQualityMetric,
Expression,
Action,
)
from unified_planning.model.walkers import StateEvaluator
from unified_planning.plans.plan import ActionInstance, Plan
from unified_planning.plans.sequential_plan import SequentialPlan
from unified_planning.plans.stn_plan import STNPlan, STNPlanNode
from unified_planning.plans.time_triggered_plan import TimeTriggeredPlan
from unified_planning.plans.contingent_plan import (
ContingentPlan,
ContingentPlanNode,
visit_tree,
)
from unified_planning.plans.partial_order_plan import PartialOrderPlan
import datetime
import plotly.express as px # type: ignore[import]
import matplotlib.pyplot as plt # type: ignore[import]
from unified_planning.model import FNode
from unified_planning.plans.plan import ActionInstance
from unified_planning.plans.stn_plan import STNPlanNode
from unified_planning.plans.contingent_plan import ContingentPlanNode
import networkx as nx
from typing import (
Any,
Dict,
Iterable,
List,
Optional,
Sequence,
Set,
Tuple,
Union,
Callable,
Expand Down Expand Up @@ -92,6 +64,8 @@ def draw_base_graph(
font_color: str = FONT_COLOR,
draw_networkx_kwargs: Optional[Dict[str, Any]] = None,
):
import matplotlib.pyplot as plt # type: ignore[import]

# input "sanitization"
if generate_node_label is None:
node_label: Callable[[Any], str] = str
Expand Down

0 comments on commit d8585ab

Please sign in to comment.