TheAlgorithms/Python · error · ValueError
Acceptor concentration should be positive
Error message
Acceptor concentration should be positive
What it means
Raised by builtin_voltage() when acceptor_conc <= 0 while donor_conc is positive. Na appears in the numerator of ln(Nd*Na/ni^2), so a non-positive acceptor doping makes the logarithm undefined. It is the second check in the ordered chain, so donor_conc must already be > 0 for this specific message to appear.
Source
Thrown at electronics/builtin_voltage.py:44
ValueError: Acceptor concentration should be positive
>>> builtin_voltage(donor_conc=1000, acceptor_conc=1000, intrinsic_conc=0)
Traceback (most recent call last):
...
ValueError: Intrinsic concentration should be positive
>>> builtin_voltage(donor_conc=1000, acceptor_conc=3000, intrinsic_conc=2000)
Traceback (most recent call last):
...
ValueError: Donor concentration should be greater than intrinsic concentration
>>> builtin_voltage(donor_conc=3000, acceptor_conc=1000, intrinsic_conc=2000)
Traceback (most recent call last):
...
ValueError: Acceptor concentration should be greater than intrinsic concentration
"""
if donor_conc <= 0:
raise ValueError("Donor concentration should be positive")
elif acceptor_conc <= 0:
raise ValueError("Acceptor concentration should be positive")
elif intrinsic_conc <= 0:
raise ValueError("Intrinsic concentration should be positive")
elif donor_conc <= intrinsic_conc:
raise ValueError(
"Donor concentration should be greater than intrinsic concentration"
)
elif acceptor_conc <= intrinsic_conc:
raise ValueError(
"Acceptor concentration should be greater than intrinsic concentration"
)
else:
return (
Boltzmann
* T
* log((donor_conc * acceptor_conc) / intrinsic_conc**2)
/ physical_constants["electron volt"][0]
)
View on GitHub (pinned to f5988cc097)
Solutions
- Supply a positive acceptor concentration (Na > 0, typically 1e14-1e19 cm^-3).
- Audit both doping parameters together before the call: if nd <= 0 or na <= 0: raise with context.
- Validate imported data rows and drop/flag rows with non-positive concentrations.
Example fix
# before builtin_voltage(donor_conc=1e16, acceptor_conc=0.0, intrinsic_conc=1e10) # ValueError # after builtin_voltage(donor_conc=1e16, acceptor_conc=1e15, intrinsic_conc=1e10)
Defensive patterns
Strategy: validation
Validate before calling
def positive(x: float) -> bool:
return x > 0
def valid_doping(nd: float, na: float, ni: float) -> bool:
return nd > 0 and na > 0 and ni > 0 Prevention
- Populate both Nd and Na together from the same data row.
- Reject 0/None concentrations during data import.
- Keep symmetric parameter handling for donor and acceptor.
When it happens
Trigger: Calling builtin_voltage(donor_conc=1e16, acceptor_conc=-5, ...) or acceptor_conc=0. If donor_conc is also <= 0, error 254 fires first and this message never appears.
Common situations: Symmetric doping variables where only one was populated; copy-paste parameter lists leaving acceptor_conc at a 0 default; sign errors in data ingestion from measurement files.
Related errors
- Donor concentration should be positive
- Intrinsic concentration should be positive
- Capacitor at index {index} has a negative value!
- Capacitor at index {index} has a negative or zero value!
- Expected a_coeffs to have {self.order + 1} elements for {sel
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/cff63c7df5683191.
Report an issue: GitHub.