Values from the .params '.param L1=1e-6' present in the netlist, corresponding to the variables L1, W1, L3, W3, are not extracted from the netlist, in the code, the result gives only the variables instead of its corresponding values as 'length': 'L1', 'width': 'W1'

{'NMOS_transistors': [{'device_name': 'M1', 'nets': ['N001', 'Vin1', 'N003', '0'], 'length': 'L1', 'width': 'W1'}], 'PMOS_transistors': [{'device_name': 'M3', 'nets': ['VDD', 'N001', 'N001', 'VDD'], 'length': 'L3', 'width': 'W3'}]}


my netlist:
* D:\OPAMP CIRCUITS\RLGNN_LTSpice\Netlist_Run_OTA.asc
M1 N001 Vin1 N003 0 NMOS l={L1} w={W1} ad={AD1} as={AS1} pd={PD1} ps={PS1}
M3 VDD N001 N001 VDD PMOS l={L3} w={W3} ad={AD3} as={AS3} pd={PD3} ps={PS3}

.model NMOS NMOS (  LEVEL   = 49
+VERSION = 3.1            TNOM    = 27             TOX     = 4.1E-9
+XJ      = 1E-7           NCH     = 2.3549E17      VTH0    = 0.3662473)
.param L1=1e-6
.param L3=1e-6
.param W1=2.29e-5
.param W3=6.08e-5
.op
.ac dec 100 10 100Meg
.backanno
.end

with in the netlist i have values for the constants L1, W1, L3, W3,
.param L1=1e-6
.param L3=1e-6
.param W1=2.29e-5
.param W3=6.08e-5

import re

def parse_value_with_unit(value_str, variables):
    “”“Convert value with units to a float number considering the variables.”“”
    multipliers = {
        ‘m’: 1e-3, ‘M’: 1e-3, ‘u’: 1e-6, ‘U’: 1e-6, ‘n’: 1e-9, ‘N’: 1e-9, ‘p’: 1e-12, ‘P’: 1e-12, ‘f’: 1e-15, ‘F’: 1e-15,
        ‘k’: 1e3, ‘K’: 1e3, ‘Meg’: 1e6, ‘meg’: 1e6, ‘MEG’: 1e6, ‘G’: 1e9, ‘g’: 1e9
    }
    
    if value_str.startswith(‘{’) and value_str.endswith(‘}’):
        value_str = value_str[1:-1]
        if value_str in variables:
            value_str = variables[value_str]
    
    unit = value_str[-1]
    if unit in multipliers:
        return float(value_str[:-1]) * multipliers[unit]
    else:
        try:
            return float(value_str)
        except ValueError:
            return value_str

def parse_parameter_value(value_str):
    “”“Parse the value in .param statement and handle scientific notation and units.”“”
    multipliers = {
        ‘m’: 1e-3, ‘M’: 1e-3, ‘u’: 1e-6, ‘U’: 1e-6, ‘n’: 1e-9, ‘N’: 1e-9, ‘p’: 1e-12, ‘P’: 1e-12, ‘f’: 1e-15, ‘F’: 1e-15,
        ‘k’: 1e3, ‘K’: 1e3, ‘Meg’: 1e6, ‘meg’: 1e6, ‘MEG’: 1e6, ‘G’: 1e9, ‘g’: 1e9
    }
    
    unit = value_str[-1]
    if unit in multipliers:
        try:
            return float(value_str[:-1]) * multipliers[unit]
        except ValueError:
            return value_str
    else:
        try:
            return float(value_str)
        except ValueError:
            return value_str

def parse_netlist(netlist_path):
    components = {
        ‘NMOS_transistors’: [], ‘PMOS_transistors’: []
    }
    
    variables = {}
    
    # Read the netlist file
    with open(netlist_path, ‘r’, encoding=‘utf-16 LE’) as file:
        netlist = file.readlines()
    
    # Define regular expressions
    nmos_pattern = re.compile(r’(M\d+) (\w+) (\w+) (\w+) (\w+) NMOS l={(\w+)} w={(\w+)}‘)
    pmos_pattern = re.compile(r’(M\d+) (\w+) (\w+) (\w+) (\w+) PMOS l={(\w+)} w={(\w+)}‘)
    
    def parse_and_add_component(match, component_type):
        groups = match.groups()
        component_name, nets = groups[0], groups[1:5]
        nets = list(nets)
        length_key, width_key = groups[5], groups[6]
        
        length = variables.get(length_key, length_key)
        width = variables.get(width_key, width_key)
        
        length = parse_value_with_unit(length, variables)
        width = parse_value_with_unit(width, variables)

        components[component_type].append({
            ‘device_name’: component_name, ‘nets’: nets, ‘length’: length, ‘width’: width
        })
    
    for line in netlist:
        line = line.strip()
        
        # Check for .param declarations
        if line.startswith(’.param’):
            params = line.split()[1:]  # Exclude .param keyword
            for param in params:
                if ‘=’ in param:
                    name, value = param.split(‘=’)
                    variables[name.strip()] = parse_parameter_value(value.strip())
            continue
        
        # Matching NMOS transistors
        match = nmos_pattern.match(line)
        if match:
            parse_and_add_component(match, ‘NMOS_transistors’)
            continue
        
        # Matching PMOS transistors
        match = pmos_pattern.match(line)
        if match:
            parse_and_add_component(match, ‘PMOS_transistors’)
            continue
    
    return components

# Example usage:
temp_netlist_path = r’D:\OPAMP CIRCUITS\RLGNN_LTSpice\Netlist_Run_OTAtemp_netlist.cir’
components = parse_netlist(temp_netlist_path)
print(components)