Drogar

Random thoughts, daily life, being a student, quantum computing.

2016-01-02

Udacity's "Intro to iOS App Development with Swift"

TL;DR:
The free Udacity.com course Intro to iOS App Development with Swift is an effective self-paced way to write your first iOS Swift application.

Since Apple introduced Swift for iOS and OSX development, I've wanted to jump in, thinking I could re-do my Getting Things Done app, written in Objective-C about 5 years ago. This time, I wanted to try something different than just reading a reference book or going to a class. So, I decided to try the free Udacity.com course Intro to iOS App Development with Swift.

By the 3rd lesson I've got an app that has the UI for recording and playback:
    


At this point, the course wants you to write a blog about either what you have learned or how to do something specific in Swift.

My main learning is that I like doing the Udacity course. I love that it is self paced, I can zoom through the easy parts and slow down or pause the video when I need a minute (usually to find one of the plethora of minuscule icons in the Xcode interface :).

As far as course content is concerned, most of it is review. A few new things for me were:
  • Applying constraints and how to tweak the settings of the constraint;
  • Use of AVAudioPlayer to play a sound;
  • Storyboarding and segues;
  • Specific Swift syntax for various method calls, including use of try?.
A unique aspect of the course, which I really like, is they encourage students to "find out for themselves" — something akin to "teach a man to fish". This is done by getting you to search documentation, stack overflow and the internet for specific items.  Nicely done.

Finally, the most interesting thing has been this blogging assignment. I found it the most thought provoking part of the course so far — Blogging / communicating with other programmers is (IMHO) such an important part of being a great programmer. I'm happy they are encouraging that aspect right from the beginning.

2014-11-11

The Ph.D. is Done!

My thesis: "An investigation of some theoretical aspects of reversible computing" was defended on September 29, 2014 and I finished the final revision on October 31. Grad Studies accepted the electronic submission a few days later. Yaaay!

The abstract from my thesis:

The categorical semantics of reversible computing must be a category which combines the concepts of partiality and the ability to reverse any map in the category. Inverse categories, restriction categories in which each map is a partial isomorphism, provide exactly this structure. This thesis explores inverse categories and relates them to both quantum computing and standard non-reversible computing. The former is achieved by showing that commutative Frobenius algebras form an inverse category. The latter is by establishing the equivalence of the category of discrete inverse categories to the category of discrete Cartesian restriction categories — this is the main result of this thesis. This allows one to transfer the formulation of computability given by Turing categories onto discrete inverse categories.

You can download a copy at my UofC website.

2012-02-20

Monkeybars with IntelliJ Swing Designer

I had originally intended to do this once I had cucumber testing integrated, but I think that would just make the blog too long.

This post lets you get monkeybars (which uses  JRuby) working on IntelliJ using their form designer.

The first step, as usual, is getting everything installed. I'll assume you have IntelliJ version 11 installed and have installed the ruby plug-in for IntelliJ. If not, see the jetbrains site.

If you haven't installed JRuby - use the excellent rvm package to do this if on Linux or Mac. If you are on windows, there is an installer for you at the JRuby site.

Disclaimer: I am using Mac OSX 10.7, JRuby 1.6.5.1 and rvm, so examples and experience is based on that.

The required background is:

  • Java 1.6 is installed
  • JRuby is installed (preferably via rvm)
  • You have set JRuby to be your default ruby (again, if using rvm)
  • IntelliJ is installed
  • The command line does not make you quiver in fear
  • You have decided to torture yourself and do swing development rather than Rails


Step1 - Install Monkeybars and rawr gems
Start a command window, go to it and do the following commands which add a new gem source and then install. The standard rubygems.org source is out of date for monkeybars.
  • jruby -S gem source -a http://gems.neurogami.com
  • jruby -S gem install monkeybars rawr
Installing monkeybars also installs the gems "bones" and "swingset".

Step2 - Set up the project
Change directory to wherever you want your project, (I am using ij in this example) then do the setup commands below.
  • jruby -S monkeybars ij
  • cd ij
  • jruby -S rawr -c com.yourdomain.ij.Main install
  • jruby -S rake generate ALL=src/ij
These commands will take a bit of time as they download a couple of gems and the latest version of the jruby-complete.jar. At this point, you will have a monkeybars project created in your directory.
 
Now, start up IntelliJ and create a new project. In the dialog, chose "Create Project From Existing Sources". In the next panel, navigate to your directory. IntelliJ will properly detect your java and ruby sources (ruby in ij, java in ij/src), at least it did for me. The next panel will note the three jars: jruby-complete.jar, miglayout-3.7.3.1.jar, and monkeybars-1.1.1.jar. Next panel, it sets up a Java module based on your src directory. Then, the final panel detects the JRuby framework.

Expand the project pane in IntelliJ and you should see something like this:


In IntelliJ, remove the org.rubyforge.rawr package and the main file under it.

Create a "run configuration" in IntelliJ to run your Main.java file. The easiest way to do this is right click on the Main file and select "Create Main.main()...". In the config dialog, change the working directory to add the src directory at the end. It should look like this:


To complete the project setup, edit two ruby files: manifest.rb and main.rb

In manifest.rb add the two lines:
add_to_load_path '../lib/ruby'
require "ij/ij_controller"
in main.rb, near the bottom of the file, there is a begin/rescue/end block. Right after begin, add the line:
IjController.instance.open
Run the program via IntelliJ and this should appear:


Now - you have Monkeybars working with JRuby within IntelliJ. Whew!

In the old days with NetBeans, you would just design a form with the included designer and rock and roll. It is almost that simple with IntelliJ, there are just a couple of minor items to take care of.

Step 3 - Design a little form in IntelliJ
Add a new package for your forms (not required, I'm just anal about separating such things :). Within that package, right click and in the pop-up menu, select "Gui Form". Name it "Iform".

In the properties list on the left side, select the top level panel and give it the name "topPanel". (You can name any of the components, we need the top panel named to make things work in one of the alternate scenarios below. :). For purposes of the example, I just added a Jlabel and a Jbutton. Name them message and my_button respectively.

By default, IntelliJ associates a class with the form and will add private members for the elements on your form - panels are an exception, unless you name them as noted above.

If you preview the form, it should now look like this:



and the code of the associated form should look like this:



Step 4 - Create the top level frame.
IntelliJ's gui designer is for panels, forms and dialogs but not the top frame and its menu. It seems the simplest way to do this is just take the form class and extend it from a JFrame. The resulting code in Iform should look like this.

package com.yourdomain.ij.forms;

import javax.swing.*;
import java.awt.*;


public class Iform extends JFrame{


    public Iform(){
        super("Ij Frame");
        setMinimumSize(new Dimension(300,200));
        setDefaultCloseOperation(EXIT_ON_CLOSE);


        setContentPane(topPanel);
    }


    private JPanel topPanel;
    private JButton my_button;
    private JLabel message;}

Alternate to Step 4 - use JRuby and Swingset:
You can use JRuby with a swing wrapper to drive the form if you prefer. swingset is included with monkey bars, but I expect others such as Rubeus would work as well. Using JRuby, we would add a new JRuby class (I just re-used the ij_ui code that was generated. Then the JRuby code for step 4 looks like:

require 'swingset'
include  Neurogami::SwingSet::Core

class IjUi < Frame
  include  Neurogami::SwingSet::MiG
  attr_accessor :form
  attr_accessor :my_button
  mig_layout
  FRAME_WIDTH  = 300
  FRAME_HEIGHT = 200
  def initialize *args
    super
    self.minimum_width  = FRAME_WIDTH
    self.minimum_height = FRAME_HEIGHT
    set_up_form
    default_close_operation = EXIT_ON_CLOSE
  end
  def set_up_form
    @form =   com.yourdomain.ij.forms.Iform.new
    add  @form.get_top_panel
  end
  def my_button
    @form.get_mbutton
  end
end

This code requires you to add accessors for any of the form fields that require interaction - my_button so you can define handlers, form so you can gain access to message. for mapping between the view and the model. Note this would change some of the wiring in step 5.

Step 5 - wire everything up the monkey bars way
The last step! (assuming you just changed Iform to extend JFrame).

First, update the model code to include a message for the label:

class IjModel
  attr_accessor :message
  def initialize
    @message = "Swing is ok..."
  end
end


Next, in the file ij_view.rb found under src/ij, change the value IjUi to com.yourdomain.ij.forms.Iform. Then add a mapping from the view label to the model. The code will now look like this

class IjView < ApplicationView
  set_java_class com.yourdomain.ij.forms.Iform
  map :view => "message.text", :model => :message
end


Finally, add a handler for your button in the ij_controller:


class IjController < ApplicationController
  set_model 'IjModel'
  set_view 'IjView'
  set_close_action :exit
  def my_button_action_performed
    model.message = "<html>But Swing with Monkeybars<br>is awesome!"
    update_view
  end
end


And then BOOM - run it and you will see your form appear. Click the button and the label text will change.

That is the VERY beginning of getting started.

I hope this helps - comments welcomed!

Acknowledgements:

  • I got most of the way using the book "Using JRuby" by Nutter, Sieger, Enobo, Bini and Dees.
  • Examples in the monkeybars source code shamelessly copied and hardly modified (Thanks James Britt)



2012-01-19

Approaching HUnit

My January goals for LQPL include using TDD practices to create the code for the LQPL server. I am doing that, and at this point, I am starting to see some of the "warts" with the way I am tackling the TDD. For example, to be able to parse a set of five input text commands, I've created 56 cases (assertions).  Each case is a single line, but that is a lot of reading. For the "error out" cases, I created a function that improved the readability quite a bit.

    
    expectLeftString :: Either String a -> Bool
    expectLeftString (Left _)  = True
    expectLeftString _ = False
    
    makeBoolParseError :: String -> Assertion
    makeBoolParseError s = assertBool ("'"++s++"' returns error") (expectLeftString (getCommand s))
This gets used in the test creation like this:  

    "parseL3 " ~: makeBoolParseError "load"


For the positive cases, however, it becomes quite a bit messier. For example:

    "parseL2aSpace " ~: "'load     /x/xxx addint.qpo' returns QCLoad" ~:
               Right (QCLoad "/a/bc with space.qpo") @=? (getCommand "load /a/bc with space.qpo") 


Multiple lines of this become rather difficult to parse.

One solution would be to create a helper function for creating the positive assertions as well. I'll give that a shot and see how it looks!

2012-01-02

Thesis, Here I come!

2012 is going to be a banner year for my research! I will be able to dedicate myself to it full-time starting in April, which is like a dream come true. To get ready for that, I've set myself some goals for the first three months of the year, while I am still working.

LQPL Goals:

  • January - Document new separated View and Controller interfaces for the new "server" type emulator.
  • January - Write tests in HUnit (or SmallCheck or QuickCheck) as part of the development of this server and client interface
  • January - Actually write the code!
  • January - Have Grover's Algorithm working as before.
  • February - Write a new HCAR entry
Inverse Categories Research Goals:

  • February - Review and update the proofs on lifting inverse product to a product and the equivalence proof
  • March - Beef up Inverse Co-Product paper
  • March - Get Inverse Products paper ready for submission to TAC
Other (things to support research):
  • Make physical fitness a habit.
  • Catch up on reading
  • Present something (Likely on reversible computing and linear logic)

2011-05-23

Quantum Mechanics and Cobordisms

In last weeks post, I noted that I was planning to do work every day, starting by getting up at 5:00 AM, put in a couple of hours on research and then go to work.

Did not pan out. Physically, I'm finding it tough to keep up that schedule. Since that is very important to me, I am doing something about it.

I did still manage to tackle a few things. I've started watching the excellent introduction to Quantum Mechanics by James Binney on iTunesU. While so far it is all review, it is nice to have it as something to watch on the bus into work or coming home.

As well, I have completed chapter 1 of Frobenius Algebras and 2-D Topological Quantum Field Theories (available as a Kindle eBook).

Finally, I did get the Message Passing Language to work on Linux. Interestingly, at the same time that I was struggling with wxHaskell on the mac, there were numerous posts about the issues with GUIs for Haskell (on Mac etc.). No real resolutions, a few pointers on getting wxHaskell and GTK2HS working on the Mac and lots of posts on Haskell Café.

The biggest thing not done is that I still haven't chosen a topic for FMCS '11. I would really like to start talking about coproducts in inverse categories, the next phase to my research on reversible computing and its relationship to quantum computing. The issue with that is that I haven't done any research on it yet.

So, main plans for this week include:
  • More on Frobenius Algebras.
  • Decide on FMCS '11 topic. Potentials include Coproducts in inverse categories, Cobordisms and their relationship to Frobenius Algebras, or possibly something on LQPL.
  • Don't be tempted and watch 3 sessions of the Quantum Mechanics course.

2011-05-15

Back in the saddle...?

After a few months of huge time commitments at work, I am once again making some time for research. I did a kickstart in a great way - the U Calgary Grad Studies faculty had a free seminar entitled "The seven secrets of a successful PhD student".

Being a sucker for all of these time management and self-improvement seminars, I went for it.

The seminar was good, highly entertaining, but most important, I was reminded of two gems:
  • Do some work on the PhD, first thing in the AM, EVERY work day.
  • Create weekly, monthly and longer plans and review them
This is the old common sense world coming back in and it makes such a difference. In the couple of weeks since the seminar, I've made more progress that I did in the previous 6 months.

Current upcoming plans include:
  • Prepping a talk for FMCS '11
  • Studying "Frobenius Algebras and 2-D Topological Quantum Field Theories" by Kock once again
  • Submitting the paper on inverse products for publication
  • Updating LQPL to break the presentation code from the emulator code
  • Attending some upcoming conferences
Check back later, I'll update this in a couple of weeks.

2010-05-30

A new and better way to procrastinate

The most striking thing I find about my iPad is how effective I find it to use. The continuing refrain in the news - for example in a recent BBC article about the iPad's first day in the UK - is that it is a device for consuming, but not producing content.

I beg to differ.

I think the real issue is that we can't produce it in exactly the same way that we have grown used to with our current PCs because it is a much more structured device. This leads to having to relearn some of our paradigms and change our habits - always an uncomfortable thing to do.

This blog is an example of content creation. The iWork suite is a great example of apps for creating content and there will be more.

Latest reviews: (Canada Centric, eh?)
- silly that iBooks won't sell books in Canada
- BBC has a great free news app (helloooo CBC, CNN?)
- AccuWeather is pretty and great to use
- buying a Kindle book on Amazon is just too easy ;)
- a competitor for BlogPress wouldn't have much problem blowing it out of the water

- Posted using BlogPress from my iPad

Location:13 Ave SW,Calgary,Canada

2009-07-23

Upcoming plans for LQPL

Well, it has been a while, hasn't it.

I finally submitted the Linear Quantum Programming Languages project to HCAR as noted in a previous post. So that means I actually need to do something about it.

In the past, I had concentrated on performance and the UI things I wanted. Now that the public will actually get to see code, I thought the first thing to do would be to tidy the code a bit.

First step was to "cabalize" it (Cabal is the default Haskell build system). That was fun and not too tough.

Then, I finally made use of Neil Mitchell's great product, hlint. Lovely product and a great example of why functional languages are so great. Transforms are definable and after you transform the source you have the same program. Hah - try doing that in C.

The next big thing for the program - get it handling source files rather than just the compiled files. Right now, the compiler is a separate console program. Nobody likes a console program any more. (Except me - but I'm freakin' old :)

I'll just be doing the minimal work on that, using GtkSourceView in Gtk2Hs to display the file, have some way of compiling it, (menu item on the sourceview window? button there? menu item on the main window????) and an autoload of the compiled file.

Further plans can be found at my LQPL page.

2009-05-27

FMCS 2009 schedule

Schedule was just posted:


Thursday, May 28, 2009

3:00p.m. Gage residence rooms available for check-in

6:00p.m. Welcome Reception - Ruth Blair AB - Gage Residence


Friday, May 29, 2009

Tutorial Sessions - WMAX 240 - 1933 West Mall

9:00-10:30a.m. Ernie Manes - Equationally definable full subcategories of spaces.

10:30-11:00a.m. Break

11:00-12:30p.m. Vaughan Pratt - Axiomatizing affine and Euclidean space.

12:30-2:30p.m. Lunch

2:30-4:00p.m. Pieter Hofstra - Types, groupoids and homotopy.

4:00-4:30p.m. Break

4:30-5:30p.m. Dorette Pronk - The left and right adjoints of Span.


Saturday, May 30, 2009

Research talks - WMAX 240 - 1933 West Mall

9:00-9:50a.m. Mehrnoosh Sadrzadeh - What is the vector space content of
what we say? A compact categorical approach to distributed meaning.

9:50-10:30a.m. Robert Seely - The basics of Cartesian differential restriction
categories.

10:30-11:00a.m. Break

11:00-12:00 Michael Johnson - Monadicity, descent, and classical database view
updating.

12:00-12:30p.m. Art Stone - What might Counter-bi-algebras be?

12:30-2:00p.m. Lunch

2:00-2:40p.m. Robin Cockett - Cartesian differential restriction categories.

2:40-3:05p.m. Brian Redmond - TBA

3:05-3:40p.m. Shusaku Tsumoto - Medical data mining.

3:40-4:10p.m. Break

4:10-4:35p.m. Brett Giles - Reversible computation and Frobenius algebras.

4:35-5:00p.m. Aaron Hunter - Algebraic considerations on the dynamics of belief.

6:00p.m. Banquet - Cedar Room in the Ponderosa Building


Sunday, May 31, 2005

Sunday talks will be in WMAX 240 - 1933 West Mall

9:00- 9:50a.m. Bob Rosebrugh - EASIK: Database design and manipulation
implemented categorically.

9:50-10:20a.m. Sean Nichols - On strong reduction in combinatory logic.

10:20-11:00a.m. Break

11:00-12:00 Vaughan Pratt - Euclid's postulates at all dimensions.

2009-05-13

The first HCAR submission

Taking a cue from others - an easy blogging entry :).

I've finally made a submission to the HCAR for L-QPL. Content below:

LQPL - A quantum programming language compiler and emulator

LQPL (Linear Quantum Programming Language) consists of two main pieces, a compiler for a functional quantum programming language and an associated assembler / emulator.

The system was the main subject of the author's master's thesis and was inspired by Peter Selinger's paper Towards a Quantum Programming Language. LQPL incorporates a simplified module / include system (more like C's include than Haskell's import), various predefined unitary transforms, algebraic data types, and operations on purely classical data. The compiler translates LQPL programs into an assembler like language. The emulator, written using Gtk2Hs, translates the assembler to machine code and provides visualization of the program as it executes.

For example, the following procedure implements quantum teleportation:

teleport::(n:Qubit, a:Qubit, b:Qubit ; b:Qubit) =
{
Not a <= n ;
Had n;
measure a of
0> => {}
1> => {Not b};
measure n of
0> => {}
1> => {RhoZ b}
}


The emulator will allow a person to step through this program, displaying the quantum values as a tree. The figure below is a screen shot showing the results after the first measure in
teleport.





Since the publication of the thesis, some time and attention has been spent on improving performance and the UI of the emulator.

We plan to release this to the public sometime this year. It will be made available from the author's website and the programming languages research group's website at
the University of Calgary.

2008-10-01

Grover's search algorithm, Part 1

So, as I've alluded to over the past while, I have written a quantum compiler and associated emulator. First, what's the difference between a simulator and an emulator. Well, to my mind, a simulator typically "roll's the dice" as it proceeds. Quantum algorithms tend to end with probabalistic results. For example, Grover's search with 3 qubits gives the correct result with a probability of .945. A simulator will use a random number generator to show the correct result 94.5% of the time, and the wrong result 5.5% of the time. Naturally, you have to run it a few times to be sure you have the correct result. (OK - not too many :).



With an emulator, you see all the potential results and their probabilities.


In the above diagram, you can see the desired result is 6 (110) and the probability of getting any other result is .007813 . (A green dot is a probabilistic integer, the blue dot is a leaf - think of it as an entry in the "matrix" describing the quantum state).

So - how do we do this... Well, with QPL, we write this code:


#Import gtrans.qpl
#Import qubitListToInt.qpl
#Import intToZeroQubitList.qpl

main ::()=
{
dataqbs = intToZeroQubitList(15|);
hadList dataqbs;
doNGrovers(4) dataqbs;
i = qubitListToInt(dataqbs);
}



The #Import constructs work similarly to Haskell's import, brining in the code at the named file.

The main function consists of 4 statements. The first creates what can be called a quantum integer, consisting of a list of qubits. The 15 is a classical value and represents the largest integer we would like to store (as an unsigned value). The next statement calls a function that will apply the Hadamard transform to each of the qubits. We then apply Grover's transform to the list (see the next posting), convert back to a probabilistic integer by measuring each of the qubits and voila - the answer appears.

Next posting - more details about the doNGrovers function.

2008-09-29

What to do, what to do ...

Every few months, I feel like I go through a "blogspurt", where I just want to get out and blog.

Then, it tapers off and nothing appears for the next 6 months. I've had thoughts of posting daily, and those just peter out over time.


So, what next?

I'm back taking a class at the U of C.

Oh yes - the other thing is that I have Grover's search algorithm working for at least up to 8 qubits. I actually use that as a benchmark as I make changes / updates in my quantum stack compiler and emulator.

So, I keep thinking about this and that's what I'm going to do. Start blogging about the quantum algorithms I've been programming.

2008-02-24

Some of Washington's Wonders

So, while down visiting my sister here in the sunny state of Washington (No kidding - the weather is fantastic), I heard on the news that 16% of the drivers here are uninsured. I find that simply a manifestation of insanity. How can people tolerate this? What's more, how can they tolerate a government that does nothing about it? Apparently the fine for no insurance is a paltry $250. My god!

In Alberta, where I drive, you can't renew your license without proof that you are insured. In fact the penalty for even trying is a court appearance. I'm sure there are some drivers that let their insurance lapse, but in a recent thanksgiving blitz, only 13 drivers were found to be uninsured out of over 2000 infractions! We have some hefty fines if you fail to produce an insurance card and if you repeat offend, your license will be suspended.

But possibly what is more interesting is that our culture in Canada tends to make it unthinkable to even consider driving with no insurance. See for instance the PDF of uninsured drivers estimates at http://www.ircweb.org/News/20060628.pdf.

But enough shaking my head negatively in wonder, let's take a look at the Ferries! Fantastic items man. I'm currently sitting on the Kingston - Edmonds ferry (Near the start of the line - yay!) and what a cool thing. On top of that, I'm able to connect via their wireless network and post this little item - again - major coolness. BC Ferries just don't seem to compare.

Well - maybe not so cool. It is one of those pay for access plans. Guess I'll post later.

On a final note - what's with all the ColdFusion pages in government sites? Don't they know how to write JSP?

2008-02-20

Blogging by email

As I've said on other posts, I don't know where people find the time to live as well as blog.

Perhaps email blogging is the key!

Here I am sitting on the bus typing away on a Blackberry, filling in what I want to blog. I spend approximately an hour a day on the bus.

Lately that time has been devoted to studying type theory, but why not use some of it for the blog?


(Addendum - Sadly the bb I have appends a ton of corporate stuff - not that suitable for this. Sigh)

2008-02-19

64 Bits and lovin' it

So, I finally bought a recent computer and have a bit of memory now (8GB - Yay). Note that when you install a 32 bit OS, you just don't get to see those extra gigs (oops :).

A brief note about this thought, when you install some x86_64 apps outside of ubuntu's managed packages, you may need to install the package "ia32-libs". This happened to me when I finally gave up trying to get vmware 5.5 working and downloaded the 64bit version 6. It installed and ran, but when trying to start a machine it failed with the error "Failed to connect to process". Sheesh!

Luckily I found the fix eventually through google.

Now to see how the quantum orderfinding goes...

2007-07-30

Setting Goals

So, how do you set them? How do you determine what is or isn't important enough in your life to be a goal?

Stephen Covey gives a very simple method in his 7 habits book. Write your eulogy. Determine how you want to be remembered by family, friends and others.

I've done this in my past and the biggest thing that comes up for me is that I really want to get a doctorate and teach. So, that is my long term direction. At the same time, there are many other items in my life that are very important. Among them are:
  • Financial security

  • Family

  • Health


Obviously the list is at a higher level than "Get a Ph.D.". That one fits under an item probably called "Personal Improvement".

So, for a start, I have the four areas I want to concentrate on. Thinking somewhat more abstractly though, what are the principles and purpose I want to govern my life? Purpose is usually an angst filled discussion :). Typically, if someone asks me that, i would respond, "To fullfill god's will." (For god - feel free to replace with your higher power of choice. I was raised an Anglican, but feel more agnostic / Buddhist than anything else now) .

At times, I have felt this was a cop-out. What if my purpose really is to teach math and computer science. (I am quite good at teaching this stuff, and really enjoy it)

Well, time will tell. The next post(s) will explore how to turn the concentration areas into actual goals.