add_sensitivity_reaction accepts the same reaction twice although the docstring says it raises

Open
#2,197 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, python
Domain
api

Research direction

Start by rebuilding from source and running the reproduction script so you see the missing exception, then read Reactor::addSensitivityReaction and ReactorSurface::addSensitivityReaction (src/reactor/) and check how ReactorNet::registerSensitivityParameter stores parameters, since that is where a duplicate check belongs. Also fix the missing space in the "after theintegrator" message there. Done means the second call raises CanteraError, n_sensitivity_params stays 1, and a regression test in the Python reactor test suite covers both the duplicate and the message.

Written by the indexing model from the issue text.

Description

Problem description

The docstring of add_sensitivity_reaction says: "Specifying the same reaction more than one time raises an exception." It does not: the parameter is registered a second time. Reactor::addSensitivityReaction and ReactorSurface::addSensitivityReaction do not check for an existing parameter.

There is also a missing space in the related message in ReactorNet::registerSensitivityParameter: "Sensitivity parameters cannot be added after theintegrator has been initialized."

Steps to reproduce

import cantera as ct
gas = ct.Solution("h2o2.yaml")
gas.TPX = 1000.0, ct.one_atm, "H2:2, O2:1, AR:4"
r = ct.IdealGasConstPressureReactor(gas, clone=True)
net = ct.ReactorNet([r])
r.add_sensitivity_reaction(2)
r.add_sensitivity_reaction(2)
print(net.n_sensitivity_params)

Behavior

No exception; prints 2. Expected: CanteraError on the second call, as documented.

System information

  • Cantera version: 4.0.0a2, main at 25c1ab1 (built from source); also seen in 3.2.0
  • OS: Linux x86_64 (glibc 2.43)
  • Python 3.13.16, NumPy 2.5.4, Cython 3.3.1, SUNDIALS 7.2.0

Additional context

Found while writing tests for our own use of Cantera; the example was reduced and run by an AI coding agent (Claude Code), and checked against existing issues.

Dominant language
C++
Stars
885
Forks
438
Avg merge
3h 41m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Cantera/cantera

All issues in Cantera/cantera

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.