rhoforsympy

..where we discuss density operators wrt SymPy

My GSoC Experience

Recently, I gave a talk at UIC Friendly Friday session!  

The slides give an overview about Google Summer of Code, some relevant links and what is in it for students.

Take a peek.

slide/pdf

Emacs script to add function headers in python mode

I have an usual python-mode setup with python-mode.el and all packages that help set up a good IDE environment for Python in Emacs. But, I did not find any scripts/functions that would help me generate a doc string for methods. The script I have shared below should do the trick. This is the initial script and I hope to add to this script as I use it. The script tries to follows the markup syntax that is supported by reStructuredText

Please feel free comment on the git repo if you find any issues or have any improvements


;; add the following lines to .emacs file.
;; When a function header needs to be generated, place the cursor
;; on the same line as function definition and call the function
;; generate-header. Alternatively, a key-binding can be added
;; using (global-set-key) or adding this function to the python-mode-hook

(defun get-function-definition(sentence)
(if (string-match "def.*(.*):" sentence)
(match-string 0 sentence))
)

(defun get-parameters(sentence)
(setq y (get-function-definition sentence))
(if y
(if (string-match "(.*)" y)
(match-string 0 y)))
)

(require 'thingatpt)
(defun generate-header()
(interactive)
(setq p (get-parameters (thing-at-point 'sentence)))
(forward-line 1)
(insert "\t\"\"\"\n\n\n")
(setq params (split-string p "[?\,?\(?\)?\ ]"))
(while params
(if (/= (length (chomp (car params))) 0)
(progn
(insert "\t:param ")
(insert (chomp (car params)))
(insert ": \n")))
(setq params (cdr params)))
(insert "\n\t\"\"\"\n\n")
)

Git

Ubuntu to Mac – My experience with the new setup

Recently I had an opportunity to get my hands dirty on a Mac based development environment. I have done most of my development on Ubuntu and getting to work on Mac was a mixed experience. As anyone would have guessed the overall UI experience has been great.

Here are some of the tools I was introduced to during my first week:

1. SQLPro : This is a nice GUI based MySQL client. I was never impressed with the command line MySql client. I hated it all the more once I started using Postgress and the accompanying client. If you have used Golden for Oracle it is on par with that tool.

2. iTerm2: This is the tmux equivalent and tuned towards the Mac UI experience. The key bindings are easy to learn and worth spending time getting used to the keyboard shortcuts.

3. Homebrew: This is the Ubuntu equivalent of apt-get. Other options include MacPorts and Fink. I am yet to familiarize myself with the differences between the options.

4. Alfred: This is a quick launch app which helps you launch applications using Cmd-Space shortcut. This is equivalent to Alt-F2 on Ubuntu.

5. PyCharm : This is not Mac specific, but this tool has been handy in helping me step through code and understand the implementation as I debug.

6. Emacs on Mac : The biggest challenge I had was trying to set up Emacs to reflect my set up on Ubuntu. ‘Monaco’ is the usual font used in most of Mac applications. But, the GUI version of Emacs just does not render Monaco-11 or Monaco-12 in anti-aliased mode.Turning on/off anti-aliasing did not help either. Doing anything in a font bigger than that was very painful. Finally, I settled into to using the non gui-version of Emacs-24. I just had to create an alias called emacs24 and make it point to the Emacs app with the non-Gui option. Here is the instruction you will need to follow, if you had the same experience.
a. Install the Emacs-24.x version.
b. Add this line to your bash_profile.

alias emacs=”/Applications/Emacs.app/Contents/MacOS/Emacs -nw”

c. And, happily run Emacs with the beautiful fonts rendered by iTerm2.

This option also helps you open Emacs within one of the sessions in iTerm2. That way you can remain working on the terminals without the need to switch windows.

There are some new Python tools I have started working in lately, and that will be the topic of my next post.

Happy Coding!

Week 12 : Starting work on Shor’s algorithm

This has been a great 12 week run filled with learning and valuable experience! I believe I have accomplished most of what I had set out to do.  The only other thing pending as far as proposed tasks goes is to relocate the Tr module. This would be based on decisions that needs to be taken by more experienced folks here! Once, the decision is made, I don’t think this would take too much of my time. (I am estimating this based on the current approaches that have been proposed).  Therefore, I am committed to getting this done even if this goes beyond GSoC pencils down deadline which is this week!

So, that was all about the wrap up! So, what I am doing now?

~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

Looking forward, I have taken up another interesting task I am excited to work on.  Past week I started working on implementing/completing Shor’s algorithm. The 2 major activities that consumed my time this week were

a) Understand Shor’s algorithm in more detail to help me understand what is available in the current implementation.

b) Review the current implementation and plan on next steps.

After reviewing the current implementation, I have decided to approach this task with the following smaller tasks:

a) Review and complete the implementation of QFT gate ( include tests, documentation), so that it can work independent of Shor’s algorithm.

b) Review and complete the implementation of CMOD gate. Right now, the implementation is not complete, and needs more tests too. This is the set of gates that would do the  |a mod N> * |state> over 2^j times for j = { 0, 1, ….2^(n-1)}

c) Put this all together and re-factor the current implementation (especially break down current period_find() ) to help more detail testing.

d) Also, I plan to provide a argument to shor() method, to work as a flag to turn on detail logging as the circuit progresses.

All the code I am currenly reviewing and planning to work on are available on the master branch even though it is not complete.

Happy coding!

Week 11: Fidelity of quantum states

As discussed in my previous weeks report, this week I started addressing some of the issues in the pending PR’s and all the pending PRs were merged!

In addition to getting the pending PRs accepted, I have stated working on 2 other tasks. One of them, that was completed is the feature to compute Fidelity (PR 1459) of quantum states.  Some screen-shots follow (taken from notebook examples available with code base). Information regarding fidelity can be found at these 2 wikis: 1, 2

For the next week, my plan is to finish up work on the implementation of Shor’s algorithm available here.

Here are some examples of using the fidelity function:

Week 10: Finishing up density matrices!

This week I largely wrapped up most of the items I had listed in the proposal. The current pending PR addresses and completes most of the major features I had proposed to implement. Some minor issues that are still pending should be addressed during the next week.

1. Adjust qapply() to complete some density based operations more gracefully.

2. Relocate the trace.py modules from core to another suggested folder. There have been some discussions on this on the mailing thread, which I plan to re-initiate and get a closure on this week.

Apart from these 2 items, based on some IRC discussions I had with Brian during past week, I have started looking at following 2 items. My plan is to work on the following 2 items during this month.

1. Finish up implementation of Shor’s algorithm currently available here: git

2.  Implement the fidelity and trace distances for density matrices: Ref

Happy Coding!

Some examples for latest pull request

In the latest PR  2 features have been implemented and relevant examples were added to notebook.   Some examples for the first feature, can be found at this post.  Some updates and test cases were added after I had discussed it there.

The second is a minor change to qapply() as seen in  the following 2 examples:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Happy Coding!

Week 8: Trace implementation contd. and more Density ops

This week was primarily spent on 2 tasks.  Getting some of the issues addressed in the currently pending PR 1396. Apart from work on this I have spent some testing some changes I had to make to implement the operations needed when Unitary operations are applied to Density operators.

Some use cases I am currently working on for this are as follows:

1. Using basic kets/bras and generic UnitaryOperator

2. Apply Gates of Density operators with states as Qubits.

Currently, qapply() works on  UnitaryOpearator*Ket correctly. But, as seen in the second print statement Bra*Dagger(UnitaryOperator) does not expand out fully. I am currently working on fixing this so that the second part of the expression expands out smoothly.

Therefore, my goal this week is to complete the implementation of UnitaryOperators applied to Density operators, plus address tasks for current PR and another PR ( related to partial trace on qubits)  I plan to submit this week.

Happy Coding!

Week 7: Tr operations on Qubits

This week has been lot less coding and more of understanding some pieces of codes for next set of changes. As far as the implementation goes, the Tr operations ( including partial trace/reduce density operations) for qubits was implemented.

Some examples of the Tr operations on qubits can be seen here.

An example of an reduced density operation on a mixed-state is shown below

The changes shown above are currently available in my git branch over here. I plan to submit a PR of this branch as soon as the my current PR 1396 is merged.

Another task I have been working on this week is figuring changes needed to qapply() to perform the L and R operations of density matrix. I plan to work on this tasks during next week.

In summary, plan for next week:

1. Address comments on current PR 1396.

2. Submit PR for trace_qubit branch and address any reviews on that.

3. Work on the L and R operations.

With these activities, the next major task that would remain is to set up trace operations for Time Dependent states.  I will start researching on the current implementation of this code to understand where my changes would have to go.

On a side note, we are breaking record temperatures in Chicago this week, and it was tough to keep myself cool without an air-conditioner!  Hope other Chicagoan Sympy members are doing just fine by the beach!

Week 6 : Tr implementation contd…

This week I continued to work on the Tr operator and the related code needed for partial trace operations.  Following up with the list of tasks I had listed out for this week, I got the following items accomplished this week.

1. PR 1333 merged

2. Submitted PR 1396  for review :

This PR has the following changes:

1. Printing ( default, latex and pretty).  The current output does not display the indices.  I would like some input on this from the reviewers on how to incorporate the information on indices into the output.

2. Handles indices in the constructor of Density class and related methods.

3. Handle partial trace operations especially wrt to Density operators.

4. Notebook example, some of which are listed below:

The activities I have in mind for next week are as follows.

1.  Address review comments on latest PR.

2.  Complete the test cases for existing partial trace implementation for Qubits. My plan is to get this changes merged with the current PR. This should happen by Tuesday.

With these 2 activities, I believe most of what is needed for Tr and density matrices could be considered complete. Again, I expect  @ellisonbg and @flacjacket to provide some input on this.   Assuming, this is true, then I plan to start looking at

3. qapply() method to incorporate density op L and R operations.

Aside:

BTW, for Emacs lovers and who love IPython Notebook, there is IPython notebook for Emacs now. I have not tried this yet,  but I plan to try this out this week and post my experience.

Happy coding!

Follow

Get every new post delivered to your Inbox.