''NoneType' object has no attribute 'plot_what'

I want to run the plot_it function, but the result will always report the error 'NoneType' object has no attribute 'plot_what', I will paste the error content and part of the code below, if the code is not enough, I will continue to add, sorry, because I am a beginner , Some problems may not have been noticed, thank you for the amazing people.

What I am learning is the angler operation package, which can be installed and used through pip. According to my experience, the pardiso solver can be guaranteed to work properly in the linux environment.

AttributeError                            Traceback (most recent call last)

Input In [32], in <cell line: 1>()
----> 1 optimization.plot_it(iteration=100)

File ~/anaconda3/lib/python3.9/site-packages/angler/optimization.py:326, in Optimization.plot_it(self, iteration)
    325 def plot_it(self, iteration):
--> 326     Nplots = len(self.temp_plt.plot_what)
    327     plt.close('all')
    329     Ez_lin = self.simulation.fields['Ez']

AttributeError: 'NoneType' object has no attribute 'plot_what'
def plot_it(self, iteration):
        Nplots = len(self.temp_plt.plot_what)
        plt.close('all')
    
        Ez_lin = self.simulation.fields['Ez']
    
        # This is what was used for the T-port in the paper    
        vmin = 4 * np.sqrt(self.simulation.W_in)
        vmax = np.abs(Ez_lin).max()/1.5
    
        # # This is more general but less flexible
        # if self.temp_plt.vlims[0] == None:
        #     vmin = np.abs(Ez_lin).min()
        # else:
        #     vmin = self.temp_plt.vlims[0]
        # if self.temp_plt.vlims[1] == None:
        #     vmax = np.abs(Ez_lin).max()
        # else:
        #     vmax = self.temp_plt.vlims[1]
    
        if Nplots == 4:
            f, faxs = plt.subplots(2, 2, figsize=self.temp_plt.figsize)
            axs = faxs.ravel()
        else:
            f, axs = plt.subplots(1, Nplots, figsize=self.temp_plt.figsize)
    
        for n, plots in enumerate(self.temp_plt.plot_what):
            if plots == 'eps':
                ax = axs[n]
                self.simulation.plt_eps(outline=False, cbar=False, ax=ax)
                ax.set_title('Permittivity')
                ax.annotate('Iteration:%4d' % np.int(iteration), (0.2, 0.92),
                    xycoords='axes fraction',
                    size='medium',
                    color='k',
                    horizontalalignment='center',
                    verticalalignment='center')
            if plots == 'of':
                ax = axs[n]
                self.plt_objs(ax=ax)
                ax.set_title('Objective')
            if plots == 'elin':
                ax = axs[n]
                self.simulation.plt_abs(outline=True, cbar=False, ax=ax, logscale=True, vmin=vmin, vmax=vmax)
                ax.set_title('Linear field')
            if plots == 'enl':
                ax = axs[n]
                self.simulation.plt_abs(outline=True, cbar=False, ax=ax, nl=True, logscale=True, vmin=vmin, vmax=vmax)
                ax.set_title('Nonlinear field')
        
        fname = self.temp_plt.folder + ('it%06d.png' % np.int(iteration))
        plt.savefig(fname, dpi=self.temp_plt.dpi)

 

If you have time, you can try to find clues in the optimization module or plot module in the angler package, please forgive me for being a little amateur, thank you!

Add Code 1st


class Temp_plt():

    def __init__(self, it_plot=1, plot_what=('eps'), folder='figs/data/temp_im/',
                    dpi=100, figsize=(4, 4), vlims=(None,None)):
        self.it_plot = it_plot
        self.plot_what = plot_what 
        self.folder = folder
        self.figsize = figsize
        self.dpi = dpi
        self.vlims = vlims

Add Code 2nd

def run(self, method='LBFGS', Nsteps=100, step_size=0.1,
            beta1=0.9, beta2=0.999, verbose=True, temp_plt=None):
        """ Runs an optimization."""

        self.Nsteps = Nsteps
        self.verbose = verbose
        self.temp_plt = temp_plt

        self._check_temp_plt()

        # get the material density from the simulation if only the first time being run
        if self.simulation.rho is None:
            eps = copy.deepcopy(self.simulation.eps_r)
            self.simulation.rho = eps2rho(eps)
        
        self.fields_current = False
        
        allowed = ['LBFGS', 'GD', 'ADAM']

        if method.lower() in ['lbfgs']:
            self._run_LBFGS()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source