-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Add Angular Momentum builtins... #496
Conversation
61a71c6
to
e30dff9
Compare
|
||
<dl> | ||
<dt>'ClebschGordan[{$j1$, $m1$}, {$j2$, $m2$}, {$j$ $m$}]' | ||
<dd>returns the Clebsch-Gordan coefficient for the decomposition of in terms of |$j$, $m$|$j2$, $m2$>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be precise, * ... in terms of |$j_1, m_1$>|j_2 m_2$>.*
Maybe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The persistent problem we have is that we the homegrown doc system really can't handle symbols reliably. We have seen this time and time again with things like Phi.
Do we use the bra or ket symbols anywhere else? If you know that when we go to print this it will work, then we can use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let's keep ">", but then the description should say
returns the Clebsch-Gordan coefficient for the decomposition of in terms of $|j_1, m_1>|j_2, m_2>$.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for finding the mistake. I think it is fixed now in bb73c51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Speaking of >, the ket symbol and our homegrown docsystem fragility: when I was working on the guide section for the process of adding Curl as an example, I wanted to write:
in the Sphinx document. and I was pleasantly surprised that I could do this without fuss, and that there was a world of flexibility available rather that this kind of constrained system where we are working around things and getting less-good results in the end.
So there is hope if we can get over the mountain of moving this to sphinx.
sympy_jms += [p.to_sympy() for p in pair.elements] | ||
return from_sympy(CG(*sympy_jms).doit()) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some place, it would be good to implement also KroneckerProduct
(https://reference.wolfram.com/language/ref/KroneckerProduct.html)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been going by reference guide section. That seems to belong to Matrix or Tensor things even though everything is related. Feel free to add it, but I am not sure where we would add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure where we would add it.
It looks like it goes under "Vector Space Operations" which we already have. See https://reference.wolfram.com/language/guide/OperationsOnVectors.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I was doing these, it occurred to me that there was a set not intuitive process I used that makes doing this kind of thing more automatic.
- Find a Builtin that hasn't been implemented. This PR comes from the bottom this this issue. See also TODO's at the bottom of newer sections/modules for missing functions.
- Decide where in the code/doc to put it. As noted, I first noticed it as a missing Combinatorial Function. However on more recent reflection, those last three are more specifically isolated as Angular Momentum functions (and in Combinatorial Functions it is not split out or noted as such). If this is a new section, then things are harder. If not a new section, then please add class in alphabetic order.
- See if it is a SymPy function. And the rest will assume yes. But if not try to SciPy and mpmath. I suppose numpy might be tried too.
- Copy one of the newer existing Sympy functions and adapt. Newer existing Sympy functions have Wiki, SyPy, and WMA links. Probably in the WMA link, all you will have to do is change the copied WMA name into the new name.
- Use WMA link to adapt the docstring. It might be consulted to get the summary text too.
- Go into mathics and see that you can get "info" or "?" on the changed doc.
- Adapt the pattern match rule and parameters. This is probably the hardest part.
Cases
in mathics can help here. If you have put the code with related functions, often that class will be similar to some other class and that can make adapting the pattern match and body of the code easier. Also, similar classes do not follow the most recent conventions, consider updating nearby related builtins so that do follow new conventions. - Adapt the eval method parameters and body.
- Make sure the function attributes are correct.
- Adapt some doctests and test. Examples from WMA and SymPy are a good source, but try to make the examples meaningful.
- Run the tests using
python mathics/docpipeline -s <builtin name>
- Go over error conditions and error messages
- Write unit tests for all of these edge cases and uninteresting cases to try. test using
python -m pytest -s
test/builtin/.../test-.py` - Run all tests.
- Add new builtin entry to
CHANGES.rst
- Create PR.
The above even though long is still kind of sketchy. So I will go through this process on KroneckerProdect as a detailed example and put this in the developer guide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably,this is something that should go into the developer guide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started down this path. See https://github.com/Mathics3/mathics-development-guide/tree/adding-KroneckerProduct and https://mathics-development-guide.readthedocs.io/en/adding-kroneckerproduct/extending/developing-code/extending/adding-new-mathics-function.html.
I stopped however when I see that there is this is not going to make for a simple example, because of the matrix checking, and conversion to Matrix in SymPy that we probably need to do. And this is just for the matrix case, not the vector case.
I will pick a simpler example. As for the KroneckerProduct branch , I don't intend on going further there in case you are interested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, I would say that this is almost ready.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I never was my intention to add it here - these are the angular momentum functions.)
Possibly over the weekend I may add pytests.. However redoing how Part works and changes ListExpression is more important.
Something that I am not sure about this is whether these functions belong to a |
I am following https://reference.wolfram.com/language/guide/FunctionsUsedInQuantumMechanics.html We will also have to deal with the duplication somehow. But that is yet another battle with autodoc for some other time.
Again I am following the organization cited above and we'll have to figure out how to deal with duplication under sections. |
c71ec83
to
f862984
Compare
94a053e
to
e888eea
Compare
which starts a Quantum Mechanics section. TODO: * Unit tests for errors. * Ensure function attributes are correct * Ensure we error on what we are supposed to and not on what we do not
Show symmetry in doc and add some error handling
e888eea
to
881a11b
Compare
This weekday's activity will probably be finish the development guide for Curl, and I might also add KroneckerProduct since I now see what is up with sympy Matrices. |
which starts a Quantum Mechanics section.
TODO:Ensure we error on what we are supposed to and not on what we do not