Melvin: An algorithm for automatically designing new quantum experiments using SymPy

164 views
Skip to first unread message

Xuemei Gu

unread,
Oct 15, 2021, 1:42:48 PM10/15/21
to sympy
Hello all,

I worked on quantum physics and studied computer science. Using AI to discover new quantum experiments is one of my research interests.  

There is a computer-based design algorithm for seaching new quantum optics experiments -- Melvin (10.1103/PhysRevLett.116.090405), which is implemented in Mathematica. Based on this work, I have reimplemented it in SymPy:

It would great, if this project (https://github.com/XuemeiGu/MelvinPython) could be listed on the SymPy webpage. 

I am looking forward to hearing feedback from the SymPy commuity on this project.
Thank you very much!

best regards,
Xuemei Gu

David Bailey

unread,
Oct 19, 2021, 3:55:33 PM10/19/21
to sy...@googlegroups.com
Dear group,

First I would like to say how good it was to discover that the online
SymPy documentation now supports copy/paste operations without
constantly switching to SymPyLive. I think this will make the
documentation considerably more user friendly.

My question is what construct should I use to get variables with
subscripts, and maybe superscripts. I thought at first that indexed
objects were the way to go, but they seem rather obscure. E.g. think of
indexing through the Bessel functions - J0, J1,J2 etc.

Ideally I'd like to loop over the index/indices and also see the
subscripts positioned below the main symbol when using Latex output

Best wishes,

David


Oscar Benjamin

unread,
Oct 20, 2021, 7:36:44 AM10/20/21
to sympy
On Tue, 19 Oct 2021 at 20:55, David Bailey <da...@dbailey.co.uk> wrote:
>
> Dear group,
>
> First I would like to say how good it was to discover that the online
> SymPy documentation now supports copy/paste operations without
> constantly switching to SymPyLive. I think this will make the
> documentation considerably more user friendly.

I'm not sure what has changed there...

> My question is what construct should I use to get variables with
> subscripts, and maybe superscripts. I thought at first that indexed
> objects were the way to go, but they seem rather obscure. E.g. think of
> indexing through the Bessel functions - J0, J1,J2 etc.
>
> Ideally I'd like to loop over the index/indices and also see the
> subscripts positioned below the main symbol when using Latex output

I'm not completely sure what you want here but is this it:

In [19]: symbols('x:10')
Out[19]: (x₀, x₁, x₂, x₃, x₄, x₅, x₆, x₇, x₈, x₉)

IndexedBase is for the situation where you want the index to be symbolic e.g.:

In [27]: xi = IndexedBase('x')

In [28]: n, m = symbols('n, m')

In [29]: Sum(xi[n], (n, 1, m))
Out[29]:
m
___


╱ x[n]

‾‾‾
n = 1

--
Oscar

David Bailey

unread,
Oct 20, 2021, 4:24:28 PM10/20/21
to sy...@googlegroups.com
On 20/10/2021 12:36, Oscar Benjamin wrote:
On Tue, 19 Oct 2021 at 20:55, David Bailey <da...@dbailey.co.uk> wrote:
Dear group,

First I would like to say how good it was to discover that the online
SymPy documentation now supports copy/paste operations without
constantly switching to SymPyLive. I think this will make the
documentation considerably more user friendly.
I'm not sure what has changed there...

Thanks for replying Oscar. You are right! When I went to the SymPy documentation to prepare the second part of this email I found it behaved in the same old way - maybe the live shell was down last night. The problem is that if you click into a block of SymPy code with the intention of cutting and pasting its contents, it fires up the live shell when you don't want it - at least using Firefox on Windows 10. To cut and paste you have to use a trick - clicking outside the block with the green background and dragging into the block from there. Since there is a dark green tag above each section to invoke the live shell, all that is needed is to disable special trapping the left mouse click.

My question is what construct should I use to get variables with
subscripts, and maybe superscripts. I thought at first that indexed
objects were the way to go, but they seem rather obscure. E.g. think of
indexing through the Bessel functions - J0, J1,J2 etc.

Ideally I'd like to loop over the index/indices and also see the
subscripts positioned below the main symbol when using Latex output
I'm not completely sure what you want here but is this it:

In [19]: symbols('x:10')
Out[19]: (x₀, x₁, x₂, x₃, x₄, x₅, x₆, x₇, x₈, x₉)

IndexedBase is for the situation where you want the index to be symbolic e.g.:

In [27]: xi = IndexedBase('x')

In [28]: n, m = symbols('n, m')

In [29]: Sum(xi[n], (n, 1, m))

It was the second facility that I was looking for. What fooled me was that in the documentation:

https://docs.sympy.org/latest/modules/tensor/indexed.html

The index variables are created specially:

i, j = symbols('i j', cls=Idx)

However it would seem you can index with any integer variable. What does the Idx class contribute?

David



Aaron Meurer

unread,
Oct 20, 2021, 5:52:19 PM10/20/21
to sympy
Idx lets you specify a range of values. I think it is also handled
better by the code printers. If you don't need any of those features,
just using a Symbol should work fine.

Aaron Meurer

>
> David
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/d7dfab2d-9789-c46f-8b72-94d2722ca635%40dbailey.co.uk.

David Bailey

unread,
Oct 21, 2021, 4:37:52 PM10/21/21
to sy...@googlegroups.com
On 20/10/2021 22:51, Aaron Meurer wrote:
> Idx lets you specify a range of values. I think it is also handled
> better by the code printers. If you don't need any of those features,
> just using a Symbol should work fine.
>
> Aaron Meurer

Thanks Aaron,

That clarifies things a lot, but I think if you look at the
documentation, this isn't clear.

That leaves me with one question. Can this be used to index a sequence
of functions (as opposed to values) - think of the conventional notation
J_n for the n'th Bessel function, for example? This test suggests that
such a sequence can't be constructed::

X=IndexedBase('X')

x[3]=sin

Generates an error:

TypeError: 'IndexedBase' object does not support item assignment

David


Aaron Meurer

unread,
Oct 21, 2021, 4:49:39 PM10/21/21
to sympy
On Thu, Oct 21, 2021 at 2:37 PM David Bailey <da...@dbailey.co.uk> wrote:
>
> On 20/10/2021 22:51, Aaron Meurer wrote:
> > Idx lets you specify a range of values. I think it is also handled
> > better by the code printers. If you don't need any of those features,
> > just using a Symbol should work fine.
> >
> > Aaron Meurer
>
> Thanks Aaron,
>
> That clarifies things a lot, but I think if you look at the
> documentation, this isn't clear.
>
> That leaves me with one question. Can this be used to index a sequence
> of functions (as opposed to values) - think of the conventional notation
> J_n for the n'th Bessel function, for example? This test suggests that
> such a sequence can't be constructed::

You would have to represent that as the index being an argument of the
function. For example, J_n(x) is besselj(n, x).

Aaron Meurer

>
> X=IndexedBase('X')
>
> x[3]=sin
>
> Generates an error:
>
> TypeError: 'IndexedBase' object does not support item assignment
>
> David
>
>
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/b97cffac-c0be-7851-515f-e23bd19459d9%40dbailey.co.uk.

Oscar Benjamin

unread,
Oct 27, 2021, 8:01:43 PM10/27/21
to sympy
Hi Xuemei,

I'm sure we can list this on the webpage. I think you can just open a
PR to add this.

Oscar
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/6834bab3-7eb5-46d2-89cd-bab1189f30bbn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages