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

Bracket aliases do not load properly #3

Closed
dan87134 opened this issue Sep 17, 2021 · 8 comments
Closed

Bracket aliases do not load properly #3

dan87134 opened this issue Sep 17, 2021 · 8 comments

Comments

@dan87134
Copy link

Thank's for putting together this package, it will be very useful.

But the Braket package doesn't seem to add aliases properly in version 12.3.1.0 on macOS with a machine using Apple silicon (i.e. Apple's ARM processor)

To Reproduce
Quit the current kernel and then Run the notebook below with the correct path for the notebook. This notebook uses Get to load the example program. The ket alias doesn't work.

The notebook uses Options[SelectedNotebook[], InputAliases] so see the aliases that have been loaded. It looks like there is a Join that fails for some reason that I don't understand.

Expected behavior
[esc]ket[esc] should work
Screenshots

Git doesn't support uploading .nb files so here is the plain text for it

Get["/Users/danielsullivan/Dropbox/My Mac
(Daniels-MacBook-Pro.local)/Downloads/BernDirac-main/BernDirac.wl"]

Options[SelectedNotebook[], InputAliases]

And this is the error that appears

Join::incpt: Incompatible elements in Join[<|intt->RowBox[{[Integral],RowBox[{[SelectionPlaceholder],RowBox[{[DifferentialD],[Placeholder]}]}]}],dintt->RowBox[{SubsuperscriptBox[[Integral],[SelectionPlaceholder],[Placeholder]],RowBox[{[Placeholder],RowBox[{[DifferentialD],[Placeholder]}]}]}],rintt->RowBox[{UnderscriptBox[[Integral],RowBox[{[SelectionPlaceholder],[Element],[Placeholder]}]],[Placeholder]}],<<42>>,cS->TemplateBox[{},CombinatorS],cW->TemplateBox[{},CombinatorW],cY->TemplateBox[{},CombinatorY]|>,{<<1>>},{<<1>>}] cannot be joined.

@bernwo
Copy link
Owner

bernwo commented Sep 17, 2021

That is weird that the [esc]ket[esc] input alias did not work for you, because the input alias for Ket[] and Bra[] are built-in in Mathematica. BernDirac.wl does not have anything to do with defining the input alias of Ket[] and Bra[].

Perhaps try doing ClearAll["Global`*"] then see if the input alias works?

I am on Mathematica version 12.3 on Windows, and never had any issues with the input alias for either Bra[] or Ket[]. In fact, even without loading BernDirac.wl, you should be able to access these input aliases since they are built-in.

@dan87134
Copy link
Author

It looks like it is a Mathematica problem. I quit the kernel and did a ClearAll just in case and (without loading your example) and [esc]ket[esc] does not work and Options[SelectedNotebook[], InputAliases] shows the Join error. I send a bug to Mathematica and I'll let you know what they say.

@dan87134
Copy link
Author

I received response from Mathematica support. They could not reproduce the error I was having with bra/ket on macOS on Apple silicon.

They suggested that I wipe the config files for Mathematica and Wolfram... there are four of them in Library. I did that and the problem went away, the templates for bra and ket worked.

I don't know what put the config files in a bad state, it may have been loading BernDirac.wl. That's the only code I have used that uses bra and ket.

I should retry it to confirm that BernDirac was the source of the error but I won't do that for a while. If it is the problem I'd have to clear the Mathematica config again, which means I'd need to reactivate Mathematica, which leads to a license already in use error, which requires a call to Wolfram support to clear things up. But when I get a break I'll will do that.

@dan87134
Copy link
Author

I had time to try loading BernDirac.wl into a clean configuration. Now the templates for bra and ket work just fine, so I don't know what corrupted my config.

However did run into another problem. The DirectForm function generates some errors in the BernDirac_examples.nb notebook. Specifically in some cases it generates and argument count error in the KroneckerProduct function.

I can't attach an .nb file but you can download my example from here https://danal-temp.s3.amazonaws.com/braketfail2.nb

Running your example files will produce the error on my machine too.

The errors that are produced look like this:

KroneckerProduct::argmu: KroneckerProduct called with 1 argument; 2 or more arguments are expected.

Thread::tdlen: Objects of unequal length in {{|0[RightAngleBracket],0},{0,|0[RightAngleBracket]}}+{[Alpha] |1[RightAngleBracket]} cannot be combined.

Note that I am running on Apple silicon, not Intel, Mathematica version 12.3.1.0.

In any case for what I am going to be doing I just need to basic bra ket templates to work. Thanks again for making this code available.

Dan

@bernwo
Copy link
Owner

bernwo commented Sep 22, 2021

Yes, I am aware of that bug. It happens when DiracForm[] is used on vectors/matrices that only have Hilbert space of a single qubit. It works if you use it on larger vectors/matrices. I am working on a fix.

@dan87134
Copy link
Author

dan87134 commented Sep 22, 2021 via email

@bernwo
Copy link
Owner

bernwo commented Sep 22, 2021

Hi, the bugfix has been pushed to the main branch.

Additionally, I would like to point to a feature of Diracform which I haven't the time to write docstrings for.
Namely, you can change from the default computational basis to the X basis representation like so: DiracForm[Ket[0, 1], "Basis" -> {"X", "Z"}]. This outputs dirac notation where the first (left) qubit is shown in the X basis while the second (right) is shown in the Z basis.

@dan87134
Copy link
Author

dan87134 commented Sep 22, 2021 via email

@bernwo bernwo closed this as completed Sep 22, 2021
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

No branches or pull requests

2 participants