Skip to content

Ensure consistent extra columns in SolutionArray#931

Merged
speth merged 3 commits into
Cantera:mainfrom
ischoegl:consistent-extra-columns
Jan 19, 2021
Merged

Ensure consistent extra columns in SolutionArray#931
speth merged 3 commits into
Cantera:mainfrom
ischoegl:consistent-extra-columns

Conversation

@ischoegl
Copy link
Copy Markdown
Member

@ischoegl ischoegl commented Sep 5, 2020

Changes proposed in this pull request

  • Fix bugs in beta release of 2.5.0b1
  • Ensure that dimensions of extra columns are consistent
  • Enable multi-dimensional extra 'columns' (e.g. 2D arrays similar to what already exists for other SolutionArray attributes)
  • Like the existing code, this PR takes advantage of NumPy for on-the-fly adjustments of data types.

If applicable, fill in the issue number this pull request is fixing

Fixes #895, fixes #930

Illustration

In [2]: gas = ct.Solution("air.yaml")
   ...: states = ct.SolutionArray(gas, 3, extra={"prop": [5, 6, 7]})
   ...: states.append(TPX=(1100, 3e5, "AR:1.0"), prop=[1, 2, 3]) # <--- Fix #895
   ...: 
---------------------------------------------------------------------------
[...]
ValueError: Encountered incompatible value '[1, 2, 3]' for extra column 'prop'.

In [3]: states.prop = ‘spam’ # <--- overwrite individual entries / Fix #930
   ...: states.prop
   ...: 
Out[3]: array([‘spam’, ‘spam’, ‘spam’], dtype=‘<U4’)

In [4]: states.prop = np.ones((3,4)) # <--- enable multi-dimensional extra 'columns'
   ...: states.prop
   ...: 
Out[4]: 
array([[1., 1., 1., 1.],
       [1., 1., 1., 1.],
       [1., 1., 1., 1.]])

In [5]: states.prop = [1, 2, 3, 4] # <--- ensure that dimensions are consistent
---------------------------------------------------------------------------
[...]
ValueError: Incompatible shapes for extra column 'prop': cannot assign value with shape (4,) to SolutionArray with shape (3,)

Checklist

  • There is a clear use-case for this code change
  • The commit message has a short title & references relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • The pull request is ready for review

@ischoegl ischoegl force-pushed the consistent-extra-columns branch from 6e6883e to cca2fef Compare September 6, 2020 02:14
@ischoegl
Copy link
Copy Markdown
Member Author

ischoegl commented Sep 6, 2020

@speth / @bryanwweber ... I cannot request a review, but I’d appreciate if those fixes could make it into 2.5.

Copy link
Copy Markdown
Member Author

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

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

[minor edits are taken care of]

@ischoegl ischoegl force-pushed the consistent-extra-columns branch from cca2fef to 318eedb Compare September 7, 2020 19:29
Copy link
Copy Markdown
Member

@speth speth left a comment

Choose a reason for hiding this comment

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

I think these are useful improvements to eliminate some confusing behavior in the SolutionArray class. Just noticed a couple of things to fix up further.

Comment thread interfaces/cython/cantera/composite.py
Comment thread interfaces/cython/cantera/composite.py Outdated
@ischoegl
Copy link
Copy Markdown
Member Author

ischoegl commented Dec 6, 2020

@speth ... thanks for the review. I believe it's all addressed.

As for the other PR's, I can rebase once #946 is merged.

@ischoegl ischoegl force-pushed the consistent-extra-columns branch from 86f327f to 47c11ec Compare December 11, 2020 03:04
@ischoegl ischoegl mentioned this pull request Dec 11, 2020
4 tasks
@ischoegl ischoegl requested a review from speth December 11, 2020 12:32
Copy link
Copy Markdown
Member

@speth speth left a comment

Choose a reason for hiding this comment

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

Looks good, thanks.

@speth speth merged commit 52630d4 into Cantera:main Jan 19, 2021
@ischoegl ischoegl deleted the consistent-extra-columns branch January 29, 2021 18:48
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.

It is possible to create inconsistent extra SolutionArray entries Sequences can be appended as extra items on a SolutionArray

2 participants