Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit construction macro now defines docs for units #476

Merged
merged 45 commits into from
Nov 29, 2021
Merged

Unit construction macro now defines docs for units #476

merged 45 commits into from
Nov 29, 2021

Conversation

lukebemish
Copy link
Contributor

@lukebemish lukebemish commented Aug 13, 2021

This is a fairly minor change that simply causes Docs.getdocs to be defined for the appropriate type when a unit is defined, allowing for basic documentation of the dimensions and conversion factor of every unit defined by the "unit" macro.

Close #436

@sostock
Copy link
Collaborator

sostock commented Aug 19, 2021

Thanks! I think the docstrings could be improved:

help?> Unitful.m
"Equal to 10^0 Meter, or 1 m, with dimensions 𝐋"

help?> Unitful.mm
"Equal to 10^-3 Meter, or 1//1000 m, with dimensions 𝐋"
  • The docstrings should probably mention that the object is a unit (not a quantity), because to me, “equal to 1 m” sounds like it describes a quantity.
  • In the Unitful.m docstring, I don’t think it’s helpful to mention that m is equal to 1m.
  • The quotes should not be included in the docstrings. Adding getdoc methods is not the right way to implement this, it’s better to add the docstrings in the expression returned by the macro. EDIT: or use Docs.doc!

Also, should this be optional? Maybe users want to write their own docstrings for units instead. We could add a new optional argument to the @unit macro that determines whether the automatic docstring is added.

I also think we should enable documenting the @unit macro by just adding Base.@__doc__ in the right place:

julia> "docstring for MySecond"
       @unit mys "mys" MySecond 1u"s" true
ERROR: cannot document the following expression:

#= REPL[20]:2 =# @unit mys "mys" MySecond 1 * u"s" true

'@unit' not documentable. See 'Base.@__doc__' docs for details.

However, this would document only mys, not mmys (milli-MySecond). Maybe the docstrings for the prefixed units should be added automatically even if one supplies their own docstring?

@lukebemish
Copy link
Contributor Author

lukebemish commented Aug 22, 2021

Alright; I agree with what you've said, though I'll have to do some research, as I haven't played with julia documentation too much. What do you think the docstring for the base unit should be (i.e., meters)? The reason I had implemented this using getdoc is that I couldn't find any easy way to come up with the appropriate doc string when the macro is run, but I'll look into better alternatives, as I agree that using getdoc is by far not the best option.

Allowing docstrings for base units should be fairly easy; I may go down that method instead. I could also probably implement a fairly simple addition for power-of-ten units; something like "A unit equal to 10^-3 meters" or the like.

@lukebemish
Copy link
Contributor Author

lukebemish commented Aug 22, 2021

I just added a couple of commits that should provide documentation in a completely different way, relying on user-defined documentation instead and only automatically generating the SI power-of-ten derived units documentation. All in all, I think this is a much nicer way to go, as users can add as much custom documentation as they would like to to any units they define. I also started adding documentation for some of the units defined in pkgdefaults, though I figured I should hold off on defining documentation for all of them until we've got a common documentation format. The system I'm using should also let documentation be defined for dimensions, if I did everything correctly. What do you think?

This lets all unit and dimension definition macros repect doc strings
set in unit definition. Additionally, it automatically defines
documentation for derived units using power-of-ten prefixes.
Documentation has been added for all base units and many other SI units, as
well as adding a special case to the documentation so that kg and
documented as being the SI base unit.
@codecov-commenter
Copy link

codecov-commenter commented Aug 22, 2021

Codecov Report

Merging #476 (4787813) into master (5f68b2b) will increase coverage by 0.85%.
The diff coverage is 96.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #476      +/-   ##
==========================================
+ Coverage   83.77%   84.63%   +0.85%     
==========================================
  Files          16       16              
  Lines        1344     1419      +75     
==========================================
+ Hits         1126     1201      +75     
  Misses        218      218              
Impacted Files Coverage Δ
src/pkgdefaults.jl 18.60% <ø> (ø)
src/types.jl 89.79% <ø> (ø)
src/user.jl 95.05% <96.29%> (+0.78%) ⬆️
src/dates.jl 95.83% <0.00%> (+0.05%) ⬆️
src/logarithm.jl 69.67% <0.00%> (+0.12%) ⬆️
src/conversion.jl 88.40% <0.00%> (+0.17%) ⬆️
src/display.jl 95.45% <0.00%> (+0.21%) ⬆️
src/dimensions.jl 95.23% <0.00%> (+0.23%) ⬆️
src/units.jl 86.00% <0.00%> (+0.48%) ⬆️
src/quantities.jl 94.64% <0.00%> (+0.49%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f68b2b...4787813. Read the comment docs.

@lukebemish
Copy link
Contributor Author

This has stagnated slightly, mostly because I am not sure if I have enough expertise to write a doc string for all the built-in units, and I am not yet sure what a standard doc string format for these units should be. I've given it a try for some simpler units, but I would love to see what somebody else thinks of this.

@sostock
Copy link
Collaborator

sostock commented Oct 5, 2021

I like that the new iteration of this PR now enables the user to write their own docstrings, even if it means that we have to document every unit in pkgdefaults.jl by hand. I haven’t looked at the code in detail, hopefully I have time for it soon.

Regarding the format of the docstrings, I think something like the following would be nice. In particular I think it would be good to spell out the names of the units (meter, joule etc.):

    Unitful.m

The meter, base SI unit of length.

Dimension: [`Unitful.𝐋`](@ref).
    Unitful.J

The joule, an SI unit of energy, equal to 1 kg*m^2*s^-2.

Dimension: `𝐌*𝐋^2*𝐓^-2`.
    Unitful.u

The unified atomic mass unit (also called dalton), a unit of mass, equal to 1.66053906660(50)*10^-27 kg.

Dimension: [`Unitful.𝐌`](@ref)

The automatically generated docstrings for prefixed units could look like this:

    Unitful.cm

A prefixed unit, equal to 10^-2 m.

Dimension: [`Unitful.𝐋`](@ref).

See also: [Unitful.m](@ref).

For gram and its prefixed versions, one could add a disclaimer:

    Unitful.g

The gram, an SI unit of mass, equal to 10^-3 kg. Note that `kg`, not `g`, is the base unit.

Dimension: [`Unitful.𝐌`](@ref).

See also: [`Unitful.kg`](@ref).

@lukebemish
Copy link
Contributor Author

Getting the dimension to show up in the generated docs for prefixed units is quite hard; I haven't yet found a method that works. In fact, I now realize that the way I was making a reference to the base unit was also flawed, but I'm fixing that now. If anyone has ideas for getting nice representations of dimension in prefixed units, that would be good to look at. Otherwise, I'll go with what I have now, which is to give the prefixed unit a reference to the base unit, and the base unit information on the dimension.

Additionally, changed how the prefixed unit documentation is written; this
now means that prefixed units made by other modules should be properly
documented (tested with UnitfulAstro).
Documentation is still required for log scales
@lukebemish
Copy link
Contributor Author

I've added documentation in this format for all units defined in pkgdefaults. It could definitely use some review; additionally, I'd like to figure out a standard format for log scales and log scale units, and I haven't really used those much at all in Unitful.

Copy link
Collaborator

@sostock sostock left a comment

Choose a reason for hiding this comment

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

I suggest using the “official” SI names for the dimensions. I will look at the other docstrings later.

src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
Copy link
Collaborator

@sostock sostock left a comment

Choose a reason for hiding this comment

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

This batch of suggestions changes “base SI unit” to “SI base unit” and uses the official names for the base dimensions. It also changes “mol” to “mole” (“mol” is the symbol, “mole” the full name of the unit).

src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
Copy link
Collaborator

@sostock sostock left a comment

Choose a reason for hiding this comment

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

Some corrections to the docstrings.

src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
lukebemish and others added 5 commits October 7, 2021 09:40
Co-authored-by: Sebastian Stock <[email protected]>
Co-authored-by: Sebastian Stock <[email protected]>
Co-authored-by: Sebastian Stock <[email protected]>
Co-authored-by: Sebastian Stock <[email protected]>
Copy link
Contributor Author

@lukebemish lukebemish left a comment

Choose a reason for hiding this comment

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

All of these changes make sense; I believe I have committed all of them.

Copy link
Collaborator

@sostock sostock left a comment

Choose a reason for hiding this comment

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

The suggestions below add dimension information to dimensionless units and explain the choice of symbols for q and minute.

Some more points about the format of the docstrings:

  • The symbols that are documented should appear in the docstrings, i.e.,
    "A dimension representing length."
    
    should become
    "    Unitful.𝐋
    \nA dimension representing length."
    
  • The \n\n at the beginning of some lines is unnecessary. Since there is already a linebreak preceding these lines, a single \n is enough to get a double linebreak.
  • The format used for numbers and quantities in docstrings is inconsistent. Sometimes there is a space between number and unit (100 kPa), sometimes there isn’t (24hr). Sometimes, digits are grouped (299,792,458 m/s), sometimes they aren’t (6.62607015 e-34 J*s). In my opinion, if we want to keep the 6.62607015 e-34 J*s format, the space before e-34 should be removed (at least I have never seen it written with a space before). We should come to a conclusion what format we want (something that can be parsed or something that looks nice?).
  • Some docstrings don’t give the actual values of the quantities:
     "A quantity representing the rest mass of an electron, given to 11 significant figures.
    
    This should include the actual value, not just a note that the value is given to 11 significant figures, because this information is rather useless without knowing which value is actually used. Better:
     "A quantity representing the rest mass of an electron, equal to 9.109,383,7015 × 10^-31 kg (the CODATA 2018 recommended value).
    

src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
Added descriptions of why certain alternate symbols are used (q for electron charge, minute for minutes)

Co-authored-by: Sebastian Stock <[email protected]>
@lukebemish
Copy link
Contributor Author

Several things to follow up on this:

  • It might be worth using Dimension: [Unitful.NoDims](@ref) instead of Dimension: dimensionless for dimensionless units, as NoDims is what the dimension function would return from this value. What do you think of this?
  • I like the following format for numbers in docstrings: 9.109,383,7015 × 10^-31. I think that this looks nice, and my argument against needing something parsable is that these are the docstrings for an object; if the parsable version is needed, that object can just be referenced. However, I would like to see other people's take on this.
  • Additionally, I think that all values with more than a minimal number of digits should be written in scientific notation, though once again this could use other people's input.
  • I am going to go with the "space between numbers and units" format going forward, as I think it looks more readable.

I'll put together a couple of commits for all of this shortly; the format questions I can change again if necessary if we decide on a different format.

Copy link
Collaborator

@sostock sostock left a comment

Choose a reason for hiding this comment

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

These are just some cosmetic changes. Once we add tests, this should be good to merge.

src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/user.jl Outdated Show resolved Hide resolved
src/user.jl Outdated Show resolved Hide resolved
src/user.jl Outdated Show resolved Hide resolved
src/user.jl Outdated Show resolved Hide resolved
src/user.jl Outdated Show resolved Hide resolved
src/user.jl Outdated Show resolved Hide resolved
src/user.jl Outdated Show resolved Hide resolved
src/user.jl Outdated Show resolved Hide resolved
Co-authored-by: Sebastian Stock <[email protected]>
@lukebemish
Copy link
Contributor Author

lukebemish commented Oct 16, 2021

What should we go with in the way of tests? I can't figure out any easy way to test if something is documented, which is the direction we'd probably like to go in.

@lukebemish
Copy link
Contributor Author

Oh wait, docs can be cast to strings. I'll give this a try.

@sostock
Copy link
Collaborator

sostock commented Oct 16, 2021

Oh wait, docs can be cast to strings. I'll give this a try.

Yeah, I would define a unit using the @unit macro and then check that string(@doc myunit) returns the correct string. And the same for the other documentable macros and autogenerated docstrings.

@lukebemish
Copy link
Contributor Author

lukebemish commented Oct 16, 2021

The tests are failing because multiline-string indentation is weird in julia 1.0:

help?> Unitful.kJ
                       Unitful.kJ

  A prefixed unit, equal to 10^3 J.

  Dimension: 𝐋^2 𝐌 𝐓^-2

  See also: Unitful.J.

I'm not really sure how to fix this, other than making sure no multiline text blobs are indented at all. This is a bit of a pain, but may be necessary for julia-1.0 compatibility. After some playing around with it, it looks like I might just have to remove the line break before code blocks.

@lukebemish
Copy link
Contributor Author

lukebemish commented Oct 16, 2021

I managed to fix this piece of the issue, but now I'm running into something else weird:

julia> string(@doc Unitful.Length)
"```\nUnitful.Length{T, U}\n```\n\nA supertype for quantities and levels of dimension [`Unitful.𝐋`](@ref) with a value                of type `T` and units `U`.\n\nSee also: [`Unitful.𝐋`](@ref), [`Unitful.Quantity`](@ref), [`Unitful.Level`](@ref).\n"

There's a random giant space in the middle. I think I know why; it's because that's where the indent is in the string. It disappears in the markdown, but unlike in Julia 1.6 doesn't disappear when I use string(@doc Unitful.Length). I think the only nice solution here is to just get rid of indents in multiline docstrings entirely, so that everything will be consistent between Julia versions.

@sostock
Copy link
Collaborator

sostock commented Oct 16, 2021

What did you try to fix it? I think it should be enough to just replace every \n in triple-quoted strings by actual linebreaks:

    name_doc = """
                   $__module__.$name{T, U}

               A supertype for quantities and levels of dimension [`$__module__.$s`](@ref) with a value
               of type `T` and units `U`.

               See also: [`$__module__.$s`](@ref), $name_links.
               """
julia> string(@doc Unitful.Length)
"```\nUnitful.Length{T, U}\n```\n\nA supertype for quantities and levels of dimension [`Unitful.𝐋`](@ref) with a value of type `T` and units `U`.\n\nSee also: [`Unitful.𝐋`](@ref), [`Unitful.Quantity`](@ref), [`Unitful.Level`](@ref).\n"

@lukebemish
Copy link
Contributor Author

I'll give that a try. That may be the issue.

src/pkgdefaults.jl Outdated Show resolved Hide resolved
src/user.jl Outdated Show resolved Hide resolved
src/pkgdefaults.jl Show resolved Hide resolved
src/pkgdefaults.jl Show resolved Hide resolved
src/pkgdefaults.jl Show resolved Hide resolved
src/user.jl Show resolved Hide resolved
src/user.jl Outdated Show resolved Hide resolved
src/user.jl Show resolved Hide resolved
src/user.jl Outdated Show resolved Hide resolved
src/user.jl Outdated Show resolved Hide resolved
lukebemish and others added 2 commits October 18, 2021 14:35
Also removed documentation ability for logunit and logscale (as these should be another pull request)
src/user.jl Outdated Show resolved Hide resolved
src/user.jl Outdated Show resolved Hide resolved
Copy link
Collaborator

@sostock sostock 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 this is finally ready to merge. Thank you for your work and for sticking with it so long!

@sostock
Copy link
Collaborator

sostock commented Oct 20, 2021

I want to merge #489 first because it fixes the tests on master. Then we can re-run the tests on this PR and see whether they pass.

@sostock
Copy link
Collaborator

sostock commented Oct 20, 2021

Apparently, re-running the jobs isn’t enough to get the tests to run on the merge commit into current master (they still use the older master without the fix). Maybe closing and re-opening the PR will do?

@sostock sostock closed this Oct 20, 2021
@sostock sostock reopened this Oct 20, 2021
@giordano giordano merged commit 2a3308e into PainterQubits:master Nov 29, 2021
@lukebemish lukebemish deleted the unit-docs branch February 24, 2022 04:15
hustf added a commit to hustf/Unitfu.jl that referenced this pull request Sep 1, 2022
* Use the `:fancy_exponent` IO context property to override the behavior of fancy exponents (PainterQubits#446)

* Showing how to manually cancel units (PainterQubits#451)

* Showing how to manually cancel units

* Update conversion.md

added the statement that `m/m` is automatically canceled

* Remove contrived examples, fixed typo

* More clear example

This commit changes the expression from which units are shortened to 1km/2.5m, to make clear that the denomenator is part of the expression.

It also fixed a typo (`NoUnit -> NoUnits`)

* Shorten example

It seems like some of the examples did not sit well with some of the contributers. I see their point completely, and in this PR I have made the example minimal and clearer. #LessIsMore

* Added @ref, and more interesting example

I added a reference to the NoUnits type (hopefully - I don't know how to chech that the reference actually works as expected).

I also changed the example to the more complicated one, to make it less trivial and hopefully better showcase the usefullness.

* Update docs/src/conversion.md

Co-authored-by: Sebastian Stock <[email protected]>

* As per the latest review, which got outdated

Co-authored-by: Sebastian Stock <[email protected]>

* fix example `isa(1m, Length)` (PainterQubits#454)

`isa(1m, Length)` did not work after `using Unitful` but the corrected version works.

* Elaborate on UnitfulRecipes in readme (PainterQubits#456)

If I had known this would support plot axes with units, I would not have started down the road to PainterQubits#455.
Maybe this elaboration will help someone else.

[skip ci]

* Add link to UnitfulBuckinghamPi in README (PainterQubits#442)

I just registered the [UnitfulBuckinghamPi.jl](https://github.com/rmsrosa/UnitfulBuckinghamPi.jl) package. It solves for the adimensional groups in a list of Unitful parameters (quantities, units, dimensions, or combinations thereof).

This PR adds a link to the package in the README.

[skip ci]

* Fix doctests (PainterQubits#464)

* deg2rad and rad2deg with "units" (PainterQubits#459)

* deg2rad and rad2deg

* v1.9

* Update src/pkgdefaults.jl

Co-authored-by: Mosè Giordano <[email protected]>

Co-authored-by: Mosè Giordano <[email protected]>

* Update README.md

Mentioned NaturallyUnitful.jl

* Update .gitignore (PainterQubits#482)

* Update .gitignore

* Update .gitignore

Removed binary stuff

[skip ci]

* Use aggressive constprop for `^(::AbstractQuantity, ::Rational)` (PainterQubits#487)

* Calculate correct `eltype` when multiplying `StepRangeLen` by `Units`. (PainterQubits#485)

* Prevent promotion of StepRangeLen eltype when multiplying by unit

* Release 1.9.1

* Fix multiplication of range and quantity (PainterQubits#489)

* Remove unnecessary Bool-AbstractQuantity multiplication methods (PainterQubits#491)

* made Bool-Quantity multiplication symmetric

* added tests for Bool-Quantity multiplication

* Remove unnecessary multiplication methods for Bool, AbstractQuantity

Co-authored-by: Sebastian Stock <[email protected]>

* Remove comment from previous Bool, AbstractQuantity methods

Co-authored-by: Sebastian Stock <[email protected]>

* Add NaN, -Inf tests for multiplication by false

Co-authored-by: Sebastian Stock <[email protected]>

Co-authored-by: Sebastian Stock <[email protected]>

* Resolve method ambiguity (PainterQubits#495)

* Fix fastmath trig functions (PainterQubits#497)

* make `norm` use `norm` rather than `abs` (PainterQubits#500)

* make `norm` use `norm` rather than `abs`

* support broadcasting on ranges (PainterQubits#501)

* Attempt to allow preferunits to work with non-pure units (PainterQubits#478)

* Attempt to allow preferunits to work with non-pure units

Should fix PainterQubits#457. Prior to this change, attempts to use something that
looked like "preferunits(C/ms)" would result in strange behavior, without
throwing any sort of errors. Now, that should work nicely.

* Warn user when preferunits causes redundant units

Issue a warning when preferunits creates redundant units, which could stop
it from sucessfully simplifying certain quantities.

* Fix new upreferred behavior for non-dimensional quantities

* Add tests for preferunits changes

* Update test/runtests.jl

Co-authored-by: Sebastian Stock <[email protected]>

* Fix preferunits tests

* Apply suggestions from code review

Co-authored-by: Mosè Giordano <[email protected]>

* Fix issues added by removing excess arrays

* No longer use string for key while checking for units of different scales

* Update test/runtests.jl

Co-authored-by: Sebastian Stock <[email protected]>

* Apply suggestions from code review

Co-authored-by: Sebastian Stock <[email protected]>

* Update runtests.jl

Co-authored-by: Sebastian Stock <[email protected]>
Co-authored-by: Mosè Giordano <[email protected]>

* Unit construction macro now defines docs for units (PainterQubits#476)

* Unit construction macro now defines docs for units

See PainterQubits#436

* Add documentation capabilities to most defined macros

This lets all unit and dimension definition macros repect doc strings
set in unit definition. Additionally, it automatically defines
documentation for derived units using power-of-ten prefixes.

* Add documentation for some units in pkgdefaults

Documentation has been added for all base units and many other SI units, as
well as adding a special case to the documentation so that kg and
documented as being the SI base unit.

* Allow documentation for log scales and units

* Rewrite documentation format for all units through "Liter"

Additionally, changed how the prefixed unit documentation is written; this
now means that prefixed units made by other modules should be properly
documented (tested with UnitfulAstro).

* Added documentation for all remaining units

Documentation is still required for log scales

* Update src/pkgdefaults.jl

Co-authored-by: Sebastian Stock <[email protected]>

* Update src/pkgdefaults.jl

Co-authored-by: Sebastian Stock <[email protected]>

* Update src/pkgdefaults.jl

Co-authored-by: Sebastian Stock <[email protected]>

* Update src/pkgdefaults.jl

Co-authored-by: Sebastian Stock <[email protected]>

* Apply suggestions from code review

Co-authored-by: Sebastian Stock <[email protected]>

* Apply suggestions from code review

Added descriptions of why certain alternate symbols are used (q for electron charge, minute for minutes)

Co-authored-by: Sebastian Stock <[email protected]>

* Remove excess newlines; add names to docstrings

* Add NoDims documentation

* Standardized number and equation format among quantity and unit docs

* Standardize format of dimensions in unit docs

* Apply suggestions from code review

Various minor fixes and changes, mostly typos and format changes.

Co-authored-by: Sebastian Stock <[email protected]>

* Switch from inline to block code blocks in new docstrings.

Also standardize docstrings to `2π` for 2 pi.

* Add automatic documentation for everything defined by the dimension macro

Also removed documentation from the pieces of log units that currently
don't have any sort of automatic documentation generation system in place.

* Fix documentation issues with two different symbols for vacuum permittivity constant.

* Minor formatting fixes

* Use block quotes for prefixed units' doc strings

* Update src/types.jl

Co-authored-by: Sebastian Stock <[email protected]>

* Make automatic documentation optional

Also (optionally) generate automatic documentation for derived dimensions.

* Add dimension info in automatic prefixed unit docs.

* Change method for adding dimensions to prefixed unit documentation

Now no longer tries to `eval` stuff while running the macro.

* Fixes to documentation and code structure for autodocs for various macros

* Apply suggestions from code review

Co-authored-by: Sebastian Stock <[email protected]>

* Various format fixes and liters documentation changes.

* Fix missing optional argument causing test failure

* Remove no-longer-necessary NullLogger for liter and kilogram docs

* Remove unnecessary autodocs arguments for non-SI-prefixed units

* Apply suggestions from code review

Co-authored-by: Sebastian Stock <[email protected]>

* Fix invalid links being created in non-Unitful documentation

* Add spaced out column for autogen parameter where possible

* Apply suggestions from code review

Co-authored-by: Sebastian Stock <[email protected]>

* Update src/user.jl

Co-authored-by: Sebastian Stock <[email protected]>

* Add tests for autodocs

* Add test for prefixed reference units

* Hopefully fix docstrings and docstring tests on Julia-1.0

* Apply suggestions from code review

Co-authored-by: Sebastian Stock <[email protected]>

* More documentation changes from code review

Also removed documentation ability for logunit and logscale (as these should be another pull request)

* Apply suggestions from code review

Co-authored-by: Sebastian Stock <[email protected]>

Co-authored-by: Sebastian Stock <[email protected]>

* fix range eltype (PainterQubits#503)

* Fix some major invalidations to improve compile times (PainterQubits#509)

* Fix some major invalidations to improve compile times

Unitful.jl was flagged as a major invalidator of compilation downstream. Test:

```julia
# From: https://timholy.github.io/SnoopCompile.jl/stable/snoopr/
using SnoopCompile
invalidations = @Snoopr begin
    using DifferentialEquations

    function lorenz(du,u,p,t)
     du[1] = 10.0(u[2]-u[1])
     du[2] = u[1]*(28.0-u[3]) - u[2]
     du[3] = u[1]*u[2] - (8/3)*u[3]
    end
    u0 = [1.0;0.0;0.0]
    tspan = (0.0,100.0)
    prob = ODEProblem(lorenz,u0,tspan)
    alg = Rodas5()
    tinf = solve(prob,alg)
end;

trees = SnoopCompile.invalidation_trees(invalidations);

@show length(SnoopCompile.uinvalidated(invalidations)) # show total invalidations

show(trees[end]) # show the most invalidated method
```

This method won the prize for the absolute most invalidations 🎉. But I think the bigger issue is that it simply doesn't follow Julia semantics. It fixes the types for issue PainterQubits#127 in a way that gives a stricter type than Julia would do in the normal cases (which is why the invalidation occurs).

After this PR, heterogeneous arrays of numbers with Quantity in there act normally, and compile times are back to normal. Here's a showcase of it being normal:

```julia

using Unitful, Test
m = u"m"
cm = u"cm"

b = Union{Complex,Float64}[0 + 0im, 0.0]
@test b + b == b
@test b .+ b == b
@test eltype(b+b) === Number

b = Number[0 + 0im, 0.0]
@test b + b == b
@test b .+ b == b
@test eltype(b+b) === Number

b = [0.0, 0.0m]
@test b + b == b
@test b .+ b == b
@test eltype(b+b) === Number
```

* Update promotion.jl

* Release v1.10.0

* Fix PainterQubits#465 for isapprox with complex arrays (PainterQubits#468)

* deg2rad and rad2deg

* v1.9

* Update src/pkgdefaults.jl

Co-authored-by: Mosè Giordano <[email protected]>

* fix PainterQubits#465

* test, v1.9.1

* Update src/quantities.jl

Co-authored-by: Sebastian Stock <[email protected]>

* positive test

* Update test/runtests.jl

Co-authored-by: Sebastian Stock <[email protected]>

Co-authored-by: Mosè Giordano <[email protected]>
Co-authored-by: Sebastian Stock <[email protected]>

* Fix `range` implementation on Julia master and resolve method ambiguities (PainterQubits#514)

* _range(start, ::Nothing, ::Nothing, len)

* _range(::Nothing, ::Nothing, stop, len)

* Add tests for ranges with complex elements

* Use modern  syntax

* Remove unnecessary `<:Real`

* Fix range(start::Quantity{BigFloat}; step::Quantity{BigFloat}; length)

* Fix for missing _rangestyle on 1.8

* Remove `real`

* Use `step` everywhere (instead of `st`)

* Fix range(;step, stop, len) on Julia master

* Fix range(;stop, step, length) for mixed number/quantity

* Add some newlines and comments

* Rename _range_step_stop_length → _unitful_step_stop_length

To avoid confusion with Base.range_step_stop_length

* Refactor _range(start, ::Nothing, stop, length)

* Rename 3-arg `Base._range` → `_unitful_start_stop_length` (`Base._range` always has 4 arguments)
* Move promotion to `_unitful_start_stop_length`

* Refactor _range(start, step, ::Nothing, length)

* Resolve method ambiguity on Julia ≥ 1.7

* Simplify implementation

* Use modern `where` syntax for `colon`

* Add two-argument colon for dimensionless quantities

* Remove unnecessary code related to encoding of μ (PainterQubits#511)

* Add tests for encoding of μ

* Remove unnecessary code

* Use U+03BC everywhere

* Same changes for U+025B/U+03B5

* Fix printing of `StepRangeLen` with complex elements (PainterQubits#513)

* Enable `zero` for arrays with non-concrete eltype (PainterQubits#516)

* Release 1.11.0 (PainterQubits#519)

* Delete export of `convertr`, `convertrp` (PainterQubits#530)

* Delete export of `convertr`

There is no `convertr`, so don't export it.

* Don't export convertrp

It's not defined

* Add `cispi` and `sincospi` (PainterQubits#533)

* Add `modf` (PainterQubits#539)

* Add `modf` for dimensionless quantities

* Add tests for `modf`

Co-authored-by: Sebastian Stock <[email protected]>

Co-authored-by: Sebastian Stock <[email protected]>

* Add link to UnitfulChainRules.jl to README (PainterQubits#542)

* modified:   Project.toml v1.10.1 reflect Unitful, add ConstructionBase
modified:   src/pkgdefaults.jl   Use new macros, deg rad change
modified:   test/runtests.jl     Add ConstructionBase

* modified:   Project.toml   v1.11.0

Co-authored-by: Dilum Aluthge <[email protected]>
Co-authored-by: KronosTheLate <[email protected]>
Co-authored-by: Sebastian Stock <[email protected]>
Co-authored-by: Jeff Fessler <[email protected]>
Co-authored-by: Ricardo Rosa <[email protected]>
Co-authored-by: Mosè Giordano <[email protected]>
Co-authored-by: Mo8it <[email protected]>
Co-authored-by: Samuel Buercklin <[email protected]>
Co-authored-by: Oscar Smith <[email protected]>
Co-authored-by: Alexander <[email protected]>
Co-authored-by: Luke Bemish <[email protected]>
Co-authored-by: Christopher Rackauckas <[email protected]>
Co-authored-by: adkabo <[email protected]>
Co-authored-by: Rashid Rafeek <[email protected]>
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.

Add doc strings to units?
4 participants