impedance.py icon indicating copy to clipboard operation
impedance.py copied to clipboard

[BUG] Circuit element not found when spaces are used in string

Open edmundsj opened this issue 3 years ago • 0 comments

Describe the bug When spaces are placed inside parentheses of circuit string definitions, circuit elements cannot be found.

To Reproduce Steps to reproduce the behavior:

  1. Code which generates the error '...'
from impedance.models.circuits import CustomCircuit

circuit = circuit = 'R0-p(R1, C1)'
circuit = CustomCircuit(circuit, initial_guess=initial_guess)
  1. Full error info
*** ValueError:  C not in allowed elements (dict_keys(['G', 'W', 's', 'Ws', 'La', 'K', 'Gs', 'L', 'TLMQ', 'C', 'R', 'T', 'CPE', 'p', 'Wo', '__builtins__']))

Expected behavior Spaces should not affect the definition of a circuit, as they have no topological meaning, and are often inserted habitually when separating arguments of a function. This is common practice and will lead to many unnecessary errors. Suggest applying a simple .replace( ' ', '') to the string before it is parsed into a circuit to avoid this error.

Additional context Add any other context about the problem here.

edmundsj avatar Jun 02 '22 18:06 edmundsj