Skip to content

SpiceParser.build_circuit() does not build subcircuits #291

@jimzenn

Description

@jimzenn

Environment (OS, Python version, PySpice version, simulator)

OS: Linux zealoft 5.11.0-1006-gcp #6-Ubuntu SMP Wed Apr 14 21:09:18 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Python version: 3.9.4
PySpice version: 1.4.3
Simulator: ngSpice

Related Code

class ParallelResistor2(SubCircuit):
    __nodes__ = ('n1', 'n2')
    def __init__(self, name, R1=1@u_Ω, R2=2@u_Ω):
        SubCircuit.__init__(self, name, *self.__nodes__)
        self.R(1, 'n1', 'n2', R1)
        self.R(2, 'n1', 'n2', R2)

circuit = Circuit('Test')
circuit.subcircuit(ParallelResistor2('pr1', R2=2@u_Ω))
circuit.X('1', 'pr1', 1, circuit.gnd)
circuit.subcircuit(ParallelResistor2('pr2', R2=3@u_Ω))
circuit.X('2', 'pr2', 1, circuit.gnd)

source = str(circuit)

parser = SpiceParser(source=source)
bootstrap_circuit = parser.build_circuit()
bootstrap_source = str(bootstrap_circuit)

print(bootstrap_source)

assert bootstrap_source == source

Expected Behaviour

.title Test
.subckt pr1 n1 n2
R1 n1 n2 1Ohm
R2 n1 n2 2Ohm
.ends pr1

.subckt pr2 n1 n2
R1 n1 n2 1Ohm
R2 n1 n2 3Ohm
.ends pr2
X1 1 0 pr1
X2 1 0 pr2

Actual Behaviour

.title Test
X1 1 0 pr1
X2 1 0 pr2

It seems this feature is not implemented?

https://github.com/FabriceSalvaire/PySpice/blob/e459acbad6adac20d73a82dce324fb94efefa1ce/PySpice/Spice/Parser_jmgc.py#L1440

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions