From daecf3e336c494d1417fa6833998690a7053b80d Mon Sep 17 00:00:00 2001 From: Bernard Knueven Date: Tue, 7 May 2024 15:44:02 -0600 Subject: [PATCH 1/2] only import matplotlib when plotting --- mpisppy/convergers/primal_dual_converger.py | 6 ++++-- mpisppy/extensions/phtracker.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mpisppy/convergers/primal_dual_converger.py b/mpisppy/convergers/primal_dual_converger.py index c87b9143e..571e7a6f8 100644 --- a/mpisppy/convergers/primal_dual_converger.py +++ b/mpisppy/convergers/primal_dual_converger.py @@ -1,7 +1,6 @@ import numpy as np import os import pandas as pd -import matplotlib.pyplot as plt import mpisppy.convergers.converger from mpisppy import MPI from mpisppy.extensions.phtracker import TrackedData @@ -141,6 +140,9 @@ def plot_results(self): Plot the results of the convergence checks by reading in csv file and plotting """ + # don't create a hard dependency on matplotlib + import matplotlib.pyplot as plt + plot_fname = self.tracker.plot_fname conv_data = pd.read_csv(self.tracker.fname) @@ -159,4 +161,4 @@ def post_everything(self): Reading the convergence data and plotting the results ''' if self.tracking and self._rank == 0: - self.plot_results() \ No newline at end of file + self.plot_results() diff --git a/mpisppy/extensions/phtracker.py b/mpisppy/extensions/phtracker.py index de9b52887..ae4fa77c4 100644 --- a/mpisppy/extensions/phtracker.py +++ b/mpisppy/extensions/phtracker.py @@ -3,7 +3,6 @@ Must use the PH object for this to work ''' import ast -import matplotlib.pyplot as plt import numpy as np import os import pandas as pd @@ -408,6 +407,9 @@ def add_xbars(self, final=False): def plot_gaps(self, var): ''' plot the gaps; Assumes gaps are saved in a csv file ''' + # only import this if needed so we + # don't create a hard dependency + import matplotlib.pyplot as plt df = pd.read_csv(self.track_dict[var].fname, sep=',') From 2e905a73aa72f4ea903886423827b7953edb802a Mon Sep 17 00:00:00 2001 From: Bernard Knueven Date: Tue, 7 May 2024 15:44:16 -0600 Subject: [PATCH 2/2] create pandas dependency --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index a53d05d0b..e1dd825ec 100644 --- a/setup.py +++ b/setup.py @@ -33,6 +33,7 @@ 'numpy', 'scipy', 'pyomo>=6.4', + 'pandas', # should probably remove ], extras_require={ 'doc': [