PyBaMM icon indicating copy to clipboard operation
PyBaMM copied to clipboard

Print parameter info by submodel

Open valentinsulzer opened this issue 4 years ago • 10 comments

When printing parameter info, add an option to separate by submodel name (with repetitions between submodels). This might require storing the parameters when the submodel is created.

valentinsulzer avatar Jun 02 '21 17:06 valentinsulzer

Be good to also add a table that lists parameters with a tick against each submodel

TomTranter avatar Aug 10 '22 09:08 TomTranter

Note you can do

import pybamm

model = pybamm.lithium_ion.SPM()
submodel = model.submodels["positive primary particle"]
submodel.print_parameter_info()

rtimms avatar Sep 23 '22 08:09 rtimms

HI @tinosulzer Can you assign this to me? I'd be more than happy to work on this.

jaskiratsingh2000 avatar Feb 20 '23 09:02 jaskiratsingh2000

Hi @rtimms I see you already implemented the print_parameter_info() above. DO i have to look for the implementation into this page - https://github.com/pybamm-team/PyBaMM/blob/develop/pybamm/models/submodels/base_submodel.py right?

jaskiratsingh2000 avatar Feb 20 '23 10:02 jaskiratsingh2000

At the moment you can do model.print_parameter_info() to print the parameters used in the whole model. And you can manually print the parameters for each submodel as in the example above. We want to add the option to do model.print_parameter_info(by_submodel=True) which would then print the name of each submodel and the parameters used by that submodel. The method is defined here.

rtimms avatar Feb 20 '23 10:02 rtimms

Just bit of clarification. With the help of above mentiioned example. I tried printing. By using submodel.print_parameter_info(), I get the following:

Maximum concentration in negative electrode [mol.m-3] (Parameter)
Reference temperature [K] (Parameter)
Electrode height [m] (Parameter)
Typical current [A] (Parameter)
Separator thickness [m] (Parameter)
Positive electrode thickness [m] (Parameter)
Negative electrode thickness [m] (Parameter)
Number of electrodes connected in parallel to make a cell (Parameter)
Electrode width [m] (Parameter)
Maximum concentration in positive electrode [mol.m-3] (Parameter)
Current function [A] (FunctionParameter with input(s) 'Time [s]')
Positive electrode diffusivity [m2.s-1] (FunctionParameter with input(s) 'Positive particle stoichiometry', 'Temperature [K]')
Positive particle radius [m] (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Positive electrode active material volume fraction (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Initial concentration in positive electrode [mol.m-3] (FunctionParameter with input(s) 'Radial distance (r) [m]', 'Through-cell distance (x) [m]')

On using model.print_parameter_info(), I get the following

Maximum concentration in negative electrode [mol.m-3] (Parameter)
Upper voltage cut-off [V] (Parameter)
Typical electrolyte concentration [mol.m-3] (Parameter)
Initial temperature [K] (Parameter)
Negative electrode electrons in reaction (Parameter)
Number of cells connected in series to make a battery (Parameter)
Positive electrode electrons in reaction (Parameter)
Negative electrode Bruggeman coefficient (electrolyte) (Parameter)
Separator Bruggeman coefficient (electrolyte) (Parameter)
Positive electrode Bruggeman coefficient (electrolyte) (Parameter)
Reference temperature [K] (Parameter)
Electrode height [m] (Parameter)
Typical current [A] (Parameter)
Nominal cell capacity [A.h] (Parameter)
Separator thickness [m] (Parameter)
Positive electrode thickness [m] (Parameter)
Negative electrode Bruggeman coefficient (electrode) (Parameter)
Lower voltage cut-off [V] (Parameter)
Negative electrode thickness [m] (Parameter)
Number of electrodes connected in parallel to make a cell (Parameter)
Electrode width [m] (Parameter)
Maximum concentration in positive electrode [mol.m-3] (Parameter)
Positive electrode Bruggeman coefficient (electrode) (Parameter)
Positive electrode porosity (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Initial concentration in negative electrode [mol.m-3] (FunctionParameter with input(s) 'Radial distance (r) [m]', 'Through-cell distance (x) [m]')
Negative electrode active material volume fraction (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Positive particle radius [m] (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Positive electrode OCP [V] (FunctionParameter with input(s) 'Positive particle stoichiometry')
Positive electrode OCP entropic change [V.K-1] (FunctionParameter with input(s) 'Positive particle stoichiometry', 'Maximum positive particle surface concentration [mol.m-3]')
Negative electrode diffusivity [m2.s-1] (FunctionParameter with input(s) 'Negative particle stoichiometry', 'Temperature [K]')
Current function [A] (FunctionParameter with input(s) 'Time [s]')
Negative electrode OCP [V] (FunctionParameter with input(s) 'Negative particle stoichiometry')
Negative electrode porosity (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Positive electrode active material volume fraction (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Negative electrode OCP entropic change [V.K-1] (FunctionParameter with input(s) 'Negative particle stoichiometry', 'Maximum negative particle surface concentration [mol.m-3]')
Positive electrode diffusivity [m2.s-1] (FunctionParameter with input(s) 'Positive particle stoichiometry', 'Temperature [K]')
Negative electrode exchange-current density [A.m-2] (FunctionParameter with input(s) 'Electrolyte concentration [mol.m-3]', 'Negative particle surface concentration [mol.m-3]', 'Maximum negative particle surface concentration [mol.m-3]', 'Temperature [K]')
Separator porosity (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Positive electrode exchange-current density [A.m-2] (FunctionParameter with input(s) 'Electrolyte concentration [mol.m-3]', 'Positive particle surface concentration [mol.m-3]', 'Maximum positive particle surface concentration [mol.m-3]', 'Temperature [K]')
Ambient temperature [K] (FunctionParameter with input(s) 'Time [s]')
Negative particle radius [m] (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Initial concentration in positive electrode [mol.m-3] (FunctionParameter with input(s) 'Radial distance (r) [m]', 'Through-cell distance (x) [m]')

So, I want to knoiw that when we write the model.print_parameter_info(by_submodel=True) so it should also print the submodel info as stated above? Correct me if I'm saying wrong. Looking forward to hearing frop you. @rtimms @tinosulzer @TomTranter

jaskiratsingh2000 avatar Feb 21 '23 08:02 jaskiratsingh2000

Hi @rtimms Any update on this yet?

jaskiratsingh2000 avatar Feb 22 '23 17:02 jaskiratsingh2000

The output of model.print_parameter_info(by_submodel=True) should be equivalent to

for name, submodel in model.submodels.items():
    print(name, "submodel parameters:")
    submodel.print_parameter_info()

rtimms avatar Feb 23 '23 23:02 rtimms

Hello! I have tried solving this issue by implementing @rtimms method of printing the parameters submodel-wise in my code.

The output of model.print_parameter_info(by_submodel=True) should be equivalent to

for name, submodel in model.submodels.items():
    print(name, "submodel parameters:")
    submodel.print_parameter_info()
    def print_parameter_info(self, by_submodel=False):
        """Prints all the extracted parameter information of the model(s)"""
        try:
            if by_submodel:
                if not hasattr(self, 'submodels'):
                    print("ERROR: Model has no submodels.")
                    return

                for submodel_name, submodel in self.submodels.items():
                    print(f"'{submodel_name}' submodel parameters:")
                    submodel.print_parameter_info()
            else:
                self._parameter_info = ""
                parameter_types = [
                    ("Parameter", pybamm.Parameter),
                    ("inputParameter", pybamm.InputParameter),
                    ("FunctionParameter", pybamm.FunctionParameter),
                ]

                for param_type, param_class in parameter_types:
                    parameter_info = self.parameter_info(param_class, param_type)
                    if parameter_info is not None:
                        self._parameter_info += parameter_info
                    else:
                        print(f"WARNING: parameter_info is NONE for {param_type}")

                print(self._parameter_info)
        except Exception as e:
            print(f"ERROR in print_parameter_info: {e}")

The feature works as intended, and has passed the pre-commit checks. NOTE: To know more about the code, please refer to my PR. EDIT: Added ```python to make the code more readable

cringeyburger avatar Dec 03 '23 18:12 cringeyburger

NOTE: When I tried printing the parameters for the model using my code, I get the following output. CODE->

import pybamm

model = pybamm.lithium_ion.SPM()
submodel = model.submodels["positive primary particle"]
model.print_parameter_info()

OUTPUT:

Negative electrode Bruggeman coefficient (electrode) (Parameter)
Number of electrodes connected in parallel to make a cell (Parameter)
Separator thickness [m] (Parameter)
Positive electrode thickness [m] (Parameter)
Lower voltage cut-off [V] (Parameter)
Negative electrode Bruggeman coefficient (electrolyte) (Parameter)
Ideal gas constant [J.K-1.mol-1] (Parameter)
Maximum concentration in negative electrode [mol.m-3] (Parameter)
Maximum concentration in positive electrode [mol.m-3] (Parameter)
Reference temperature [K] (Parameter)
Electrode height [m] (Parameter)
Electrode width [m] (Parameter)
Positive electrode Bruggeman coefficient (electrolyte) (Parameter)
Upper voltage cut-off [V] (Parameter)
Number of cells connected in series to make a battery (Parameter)
Nominal cell capacity [A.h] (Parameter)
Negative electrode thickness [m] (Parameter)
Faraday constant [C.mol-1] (Parameter)
Positive electrode Bruggeman coefficient (electrode) (Parameter)
Separator Bruggeman coefficient (electrolyte) (Parameter)
Initial concentration in electrolyte [mol.m-3] (Parameter)
Negative electrode OCP [V] (FunctionParameter with input(s) 'Negative particle stoichiometry')
Ambient temperature [K] (FunctionParameter with input(s) 'Distance across electrode width [m]', 'Distance across electrode height [m]', 'Time [s]')
Negative particle radius [m] (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Initial concentration in negative electrode [mol.m-3] (FunctionParameter with input(s) 'Radial distance (r) [m]', 'Through-cell distance (x) [m]')
Positive particle radius [m] (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Initial concentration in positive electrode [mol.m-3] (FunctionParameter with input(s) 'Radial distance (r) [m]', 'Through-cell distance (x) [m]')
Negative electrode active material volume fraction (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Positive electrode OCP entropic change [V.K-1] (FunctionParameter with input(s) 'Positive particle stoichiometry', 'Maximum positive particle surface concentration [mol.m-3]')
Negative electrode OCP entropic change [V.K-1] (FunctionParameter with input(s) 'Negative particle stoichiometry', 'Maximum negative particle surface concentration [mol.m-3]')
Positive electrode OCP [V] (FunctionParameter with input(s) 'Positive particle stoichiometry')
Negative electrode exchange-current density [A.m-2] (FunctionParameter with input(s) 'Electrolyte concentration [mol.m-3]', 'Negative particle surface concentration [mol.m-3]', 'Maximum negative particle surface concentration [mol.m-3]', 'Temperature [K]')
Positive electrode porosity (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Positive electrode exchange-current density [A.m-2] (FunctionParameter with input(s) 'Electrolyte concentration [mol.m-3]', 'Positive particle surface concentration [mol.m-3]', 'Maximum positive particle surface concentration [mol.m-3]', 'Temperature [K]')
Current function [A] (FunctionParameter with input(s) 'Time[s]')
Separator porosity (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Negative electrode porosity (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Negative electrode diffusivity [m2.s-1] (FunctionParameter with input(s) 'Negative particle stoichiometry', 'Temperature [K]')
Positive electrode diffusivity [m2.s-1] (FunctionParameter with input(s) 'Positive particle stoichiometry', 'Temperature [K]')
Positive electrode active material volume fraction (FunctionParameter with input(s) 'Through-cell distance (x) [m]')

Whereas, when I set by_submodel=True, I get the following results. CODE:

import pybamm

model = pybamm.lithium_ion.SPM()
submodel = model.submodels["positive primary particle"]
model.print_parameter_info(by_submodel=True)

OUTPUT:

'external circuit' submodel parameters:
Current function [A] (FunctionParameter with input(s) 'Time[s]')

'porosity' submodel parameters:

'Negative interface utilisation' submodel parameters:

'Positive interface utilisation' submodel parameters:

'negative particle mechanics' submodel parameters:

'positive particle mechanics' submodel parameters:

'negative primary active material' submodel parameters:

'positive primary active material' submodel parameters:

'electrolyte transport efficiency' submodel parameters:

'electrode transport efficiency' submodel parameters:

'transverse convection' submodel parameters:

'through-cell convection' submodel parameters:

'negative primary open-circuit potential' submodel parameters:

'positive primary open-circuit potential' submodel parameters:

'negative interface' submodel parameters:

'negative interface current' submodel parameters:

'positive interface' submodel parameters:

'positive interface current' submodel parameters:

'negative primary particle' submodel parameters:
Electrode height [m] (Parameter)
Electrode width [m] (Parameter)
Number of electrodes connected in parallel to make a cell (Parameter)
Faraday constant [C.mol-1] (Parameter)
Negative electrode thickness [m] (Parameter)
Maximum concentration in negative electrode [mol.m-3] (Parameter)
Current function [A] (FunctionParameter with input(s) 'Time[s]')
Initial concentration in negative electrode [mol.m-3] (FunctionParameter with input(s) 'Radial distance (r) [m]', 'Through-cell distance (x) [m]')
Negative particle radius [m] (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Negative electrode diffusivity [m2.s-1] (FunctionParameter with input(s) 'Negative particle stoichiometry', 'Temperature [K]')
Negative electrode active material volume fraction (FunctionParameter with input(s) 'Through-cell distance (x) [m]')

'negative primary total particle concentration' submodel parameters:

'positive primary particle' submodel parameters:
Positive electrode thickness [m] (Parameter)
Electrode width [m] (Parameter)
Faraday constant [C.mol-1] (Parameter)
Maximum concentration in positive electrode [mol.m-3] (Parameter)
Number of electrodes connected in parallel to make a cell (Parameter)
Electrode height [m] (Parameter)
Positive electrode diffusivity [m2.s-1] (FunctionParameter with input(s) 'Positive particle stoichiometry', 'Temperature [K]')
Current function [A] (FunctionParameter with input(s) 'Time[s]')
Initial concentration in positive electrode [mol.m-3] (FunctionParameter with input(s) 'Radial distance (r) [m]', 'Through-cell distance (x) [m]')
Positive electrode active material volume fraction (FunctionParameter with input(s) 'Through-cell distance (x) [m]')
Positive particle radius [m] (FunctionParameter with input(s) 'Through-cell distance (x) [m]')

'positive primary total particle concentration' submodel parameters:

'negative electrode potential' submodel parameters:

'positive electrode potential' submodel parameters:

'electrolyte diffusion' submodel parameters:

'leading-order electrolyte conductivity' submodel parameters:

'negative surface potential difference' submodel parameters:

'positive surface potential difference' submodel parameters:

'thermal' submodel parameters:

'current collector' submodel parameters:

'negative primary sei' submodel parameters:

'positive primary sei' submodel parameters:

'negative primary sei on cracks' submodel parameters:

'positive primary sei on cracks' submodel parameters:

'negative lithium plating' submodel parameters:

'positive lithium plating' submodel parameters:

'total interface' submodel parameters:

Here are the inferences I gathered from the output:

  1. There are more parameters printed for the model than submodel-wise
  2. Most of the submodels have "empty" parameters. I have tried finding the problem a) There might be unhandled parameter types other than pybamm.Parameter, pybamm.InputParameter or pybamm.FunctionParameter --> couldn't figure this out b) The submodels themselves do not have any parameters --> I tried going through the documentations for some of the "empty" submodels, but couldn't figure out. c) The _find_symbols method is not returning any parameters for those specific submodels --> I am learning how the method works so I can't say much about this.

I am new to the codebase and am still learning about all the functionalities. I would be happy if someone can walk me through the required information for this issue.

Thank you!

cringeyburger avatar Dec 03 '23 18:12 cringeyburger