Complete cosmo_array numpy support and add cosmo_quantity#219
Complete cosmo_array numpy support and add cosmo_quantity#219
cosmo_array numpy support and add cosmo_quantity#219Conversation
cosmo_quantity analogous to unyt_quantitycosmo_array numpy support and add cosmo_quantity
…tors with reduce.
|
@JBorrow @robjmcgibbon Everything that both of you have raised is now addressed. I've checked and in some cases revised the visualisation examples from the narrative docs, they now all run out of the box. There are a small number of API changes from the user perspective - a few necessary given the changes, and a few where it seemed like this would be a good time to make them. Notably the removal of There are two minor (non-blocking, imo) outstanding issues that need changed in unyt to be rectified. These have xfailing tests in place, so we'll catch them when unyt fixes them (I already contributed one fix that's merged to their main, just depends when they release again...). The two issues are that using One gotcha that I have no good way of addressing is that Aaaaanyway, dare I say, ready to merge? |
|
Ah and I tested that numpy>=2.0.0 isn't enough now, so require >=2.1.0. And unyt>=3.0.4 now (just released with a bunch of fixes that I contributed throughout all of this). |
|
Fantastic, thanks Kyle, looks good to me. I will let Josh have the final say since he had more comments than me. |
|
Are you ready to merge this? You just made a new commit 😅 |
|
I'm tinkering with the leftover non-blocking stuff and discovered a dodgy test, figured I'd sneak it in... |
|
Do you want a release to be minted or is it not ready for that? |
|
I think it's ready for a release. There might be a follow-up minor release, but that would first involve wrangling some changes in unyt and getting them to release them, so rather go ahead with this. As far as I know there's nothing serious outstanding. |
…IM#219) * Implement tests for cosmo_quantity. * Initial cosmo_quantity implementation. * First rough working implementation of a numpy func overload. * Start trudging through list of functions to wrap. * Work out an approach for concatenate-like functions. * Implement a few more funcs, rough in all the rest. * Fill in FFT functions, continue roughing in. * Implement block, around. * Implement a few more funcs. * Implement a few more numpy funcs. * Start implementing histograms. * Implement a few more numpy funcs. * Implement linalg.det. * Attempt histogramdd implementation. * Wrap up histogram testing. * Amend physical conversion test because array_equal is now cosmo_array-aware. * Implement a couple more numpy functions. * Check cosmo_factor for consistent scale_factor when preparing arguments. * Implement a few more numpy functions. * Implement a few more numpy functions. * Implement a few more numpy functions. * Implement more numpy functions. * Finish implementing numpy functions, immediate tests pass. * Overhaul initialisation to allow list of cosmo_arrays as input. * Cleanup some caught warnings that no longer happen :) * Remove some unused imports and variables. * Add reshape to cosmo_quantity to enable some functions like meshgrid. * Implement numpy take function. * Wrap np.ndarray.take properly. * Replace some internal uses of unyt_array with cosmo_array. * Replace unyt array/quantity with cosmo array/quantity in tests. * Cleanup some unused imports and unused variables. * Remove duplicate comoving=... in __repr__. * Prepare to handle np functions that 'just work' in unyt but don't for us. * Make use of cosmo_array being supported in numpy in power_spectrum functions in visualisation (partial, test failing pending completing np support). * Make checks on numpy functions more stringent and fix revealed bugs. * Simplify implementation of amin, amax, and implement meshgrid. * Split out cosmo attribute copying into separate function & fix some bugs. * Check against unyt warning when running unyt version of function. * Add a few more functions and a check that we're covering all functions mentioned by unyt. * Check many more array funcs. * Keep cosmo_array to cosmo_quantity conversion in one location. * Simplify wrapping some methods and properties. * Simplify array function checks and finish checking all unyt-supported numpy functions. * Remove some redundant wrappers. * Greatly simplify array function handling with wrapper functions. * Remove version guard since we're going to pin a higher unyt version as dependency. * Cleanup another import guard since we'll require newer numpy now. * Move array_func helper functions to _array_functions.py. * Replace awkward unyt usage with new numpy supported cosmo versions. * Point requirements to unyt github main branch (temporarily). * Handle comoving is None in str representation * Refactor to keep code for casting return types in one place. * Cleanup while checking unyt usage. * Add a test for cosmo_quantity conversion. * Cleanup while checking unyt usage. * Refactor ca_cfs to just use cf directly. * Troubleshooting after refactor. * Remove unused import. * Replace some unyt usage with cosmo versions. * Some cleanup of array constructors. * Cleanup and document _array_functions.py * Start reviewing objects.py docstrings. * Run black. * Edit a few more docstrings. * Fix warnings from neutrino cosmology. * Use squeeze safely. * Review type hints and docstrings in objects.py. * Fix some sphinx issues. * Remove a and cosmo_factor from global namespace (was temporarily added for dev). * Fill in descriptions of all cosmo_array tests. * Remove some more unused imports. * Add now-redundant checks on rotation_center argument. * Cleanup more imports. * Refactor try/except into getattr for fetching hsml. * Remove stray print statement from debugging. * Gradually coercing vis functions to share code. * Remove redundant boxsize argument, get from metadata. * Remove argument from tests, too. * Cleanup more imports. * Prepared to create helper function in vis functions. * Start refactoring visualisation functions with helpers. * Move more to helper functions and cleanup. * Continue cleanup of visualisation functions. * Consolidate handling cosmo_arrays in visualisation and big namespace cleanup. * Run black. * Run CI black version. * Move wrapper from backends to be called in frontend functions. * Move norm argument onto wrapper function. * Update tests with norm arg removed from backend functions. * Run black. * Update some vis docstrings. * Support __round__ for cosmo_quantity and dot for cosmo_array. * Make a pass over the visualisation docs. * Switch on intersphinx, why not. * Reorganize docs a little bit and flesh out the cosmo_array description. * Run black. * Add new vis backend submodules (from reorganising) to installed modules. * Unyt fixed ftt->fft typo, update to match. * cache@v2 in workflows deprecated, update so that we can run CI. * Point to unyt on pypi now that 3.0.4 is released. * Add support for multiplying a cosmo_array by a bare unit object from unyt. * Re-point unyt to pypi (tests will fail). * Point unyt dependency to fork. * Remove accidentally added png files. * Rename attr copy function for clarity. * Add a constructor to initialize a cosmo_factor without import . * Refactor accumulation of preservation and multiplication of cosmo_factors with reduce. * Close if statement with else instead of elif. * Remove unused 'inputs' argument to _power_cosmo_factor. * Restore inputs argument to _power_cosmo_factor, it's used after all. * Add a new way to construct cosmo_array with scale factor and exponent. * Make use of new tidier constructors for arrays and quantities. * Remember to run the autoformatter. * Update docs for new constructors. * Add some tests for initializing with new constructors. * Rename cosmo_array ufunc tests file descriptively. * Add tests for new constructors for cosmo_array. * Tidy up tests to flag non-critical unresolved issues in unyt. * Re-point dependency at latest unyt release. * Update visualisation example. * Revisions to visualisation examples. * Run black. * We do actually need numpy>=2.1.0, and pin unyt>=3.0.4 * Corrections to unit conversion in test.
Unyt has a
unyt_quantityfor scalars with units attached (a subclass ofunyt_array). It makes sense to have an analoguecosmo_quantitysubclass ofcosmo_array, mainly so that various numpy functions don't silently cast tounyt_quantity. While I'm at it am also reviewing testing of numpy function return types and cleaning up helper functions as needed.Closes #102
Closes #123
So far I have new tests implemented, and the new
cosmo_quantityclass implemented. As collateral to all of this I'm implementing wrapping all of the numpy functions supported by unyt. Those are now all wrapped. I'd previously wrapped all of the numpy ufuncs so most of the logic existed already, just repackaged existing helper functions and created a couple of new ones, and now cribbed off of the unyt wrappers to make sure I don't miss any edge cases (unless they missed any!).After a bit of tidying up and a couple of squashed bugs in unyt the test suite now passes (with the not-yet-released unyt version with my patches applied, they say hopefully released by the end of the year). Will need to pin dependencies to unyt >=3.0.4, and probably numpy >=2.0, too.
Left to do:
"ca_cfs"logic by usingcosmo_factor(None, None)instead. That's a big job, though.to_comovingmight be better asconvert_to_comoving(in-place).objects.pyto_array_functions.py.takestrips units with scalar index input yt-project/unyt#549 and get it merged, then implement a wrapper fornp.take._array_functions.py.objects.pycomoving == Noneprints as(Physical).cosmo_array.__new__for lists of lists ofcosmo_arrays, etc. (shouldn't recurse here because unyt doesn't, but__new__needs some cleanup if possible anyway).bypass_validation?