Skip to content

Conversation

@JungNam-Kim
Copy link

Problem

Cloning a DeviceModel instance was causing a TypeError due to incorrect handling of self._parameters. The DeviceModel.clone method passed self._parameters as a single positional argument instead of unpacking it as keyword arguments.

Solution

  • Updated the DeviceModel.clone method to unpack self._parameters using **self._parameters.
  • Verified compatibility with DeviceModel.__init__, which expects **parameters as input.
  • Ensured that Netlist.copy_to correctly uses the updated clone method to avoid errors during circuit cloning.

Related Error

TypeError: DeviceModel.__init__() takes 3 positional arguments but 4 were given
Traceback (most recent call last):
  File "c:\Users\김정남\Documents\GitHub\PySpiceBasedModeling\Spice_AC_TEST.py", line 200, in <module>
    test.AC_TEST(SimType.IDVG)
  File "c:\Users\김정남\Documents\GitHub\PySpiceBasedModeling\Spice_AC_TEST.py", line 145, in AC_TEST
    test_circuit = self.circuit.clone()
                   ^^^^^^^^^^^^^^^^^^^^
  File "C:\Miniconda3\envs\pySpice\Lib\site-packages\PySpice\Spice\Netlist.py", line 1172, in clone
    self.copy_to(circuit)
  File "C:\Miniconda3\envs\pySpice\Lib\site-packages\PySpice\Spice\Netlist.py", line 842, in copy_to
    netlist._models[name] = model.clone()
                            ^^^^^^^^^^^^^
  File "C:\Miniconda3\envs\pySpice\Lib\site-packages\PySpice\Spice\Netlist.py", line 165, in clone
    return self.__class__(self._name, self._model_type, self._parameters)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: DeviceModel.__init__() takes 3 positional arguments but 4 were given

Steps to Test

Provide a quick guide for reviewers to test the fix:

### Steps to Test
1. Create a `Circuit` instance and add a `DeviceModel` using `circuit.model()`.
2. Clone the circuit using `circuit.clone()`.
3. Verify that the cloned circuit is correctly created without raising any errors.
4. Confirm that all models, elements, and parameters are accurately copied to the cloned circuit.

- Description
*Updated the DeviceModel.clone method to correctly unpack self._parameters using **self._parameters when creating a new instance.
*Ensured compatibility with DeviceModel.__init__, which expects **parameters instead of a single dictionary.
*Verified that Netlist.copy_to uses the updated clone method to avoid errors during circuit cloning.
*Resolved TypeError: DeviceModel.__init__() takes 3 positional arguments but 4 were given.

- Impact
* Fixes issues with circuit cloning in Circuit.clone when DeviceModel instances are involved.
* Prevents runtime errors related to parameter passing during cloning.
* Improves robustness and correctness of cloning functionality in PySpice-based models.
Copy link

@tapegoji tapegoji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I think this is resolved in 1.6 branch. Have you tested 1.6?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants