Skip to content

Netlist .include problem when pasing filepath #150

@dzenki-byte

Description

@dzenki-byte

Hi, recently I have encountered a problem when defining a circuit using an subcircuit defined in an external file. Below is my code where I define a circuit using a link to a transistor model i have defined in a separate file.

   t_file = os.path.join(transistor_save_dir, t_sch)
    
    circuit_text = f'''
                    .include {t_file} as x1
                    .include {t_file} as x2
            
                    P1 1 0_1
            
                    R_1 1 x1._G
                    W 1 x1._D
                    W x1._S x2._S
            
                    W x2._G 0
                    W 0_1 0
                    W 0 0_2
            
                    R_2 x1._G 2
                    W x2._D 2
            
                    P2 2 0_2
                    '''
                    
    circuit = lp.Circuit(circuit_text)

File path is contained in t_file variable of the form folder_a/folder with spaces/transistor_model.sch. Problem arises when there are spaces in the file path, namely _include(self, string) method in NetfileMixin uses parts = string.split(' ') to split the .include {t_file} as x1 into 4 parts but this also splits the file path leading to error. I have fixed this by using regular expressions:

    pattern = r'(\.include)\s+(.+?)\s+(as)\s+(\w+)'
    matches = re.match(pattern, string)
    if matches:
        parts = list(matches.groups())
    else:
        raise ValueError('Expecting include filename in %s' % string)

(\.include) matches .include.
\s+ matches one or more whitespace characters.
(.+?) lazily matches the file path (anything between .include and as).
(as) matches the keyword as.
(\w+) matches the name following as (e.g., x1).

Is there a better way of including subcircuits into the schematic?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions