Monday, October 10, 2016

Check Python Code for Syntax

A friend recommended I use Pylint to check my code for syntax errors.  Why not just run the code?  In complex code you can write a python module that cannot be run because it is part of a complex system.  You have to check your code into a code repository used by other people.  You want to check your code before checking it into the code repository.  But the Pylint program is not available for Windows.  It works on Linux systems, but the yum install tool finds all dependencies and installs everything needed to make Pylint work.  That does not happen in Windows, where you have to find and fix dependency after dependency.  You really cannot get Pylint to work on Windows, but you do not need to.

Say you want to check a file called my_python_program.py for syntax errors.  The trick is that importing a python module compiles that module, and the compilation finds all the syntax errors.  Here is what you do:  write a program called my_test.py that looks like this:


import my_python_program



print "***************"

print "finished test"
print "***************"

 Run this program and the first syntax error found will throw an exception.  Fix my_python_program.py and run my_test.py again.  When all the errors are fixed, the  program will print "finished test."  Now you can check-in your program into the code repository and know that it will not roll-over-and-die.  It might not work, but it will not die!

I launch the IDLE program, open the file through File > Open.  Then  in the file edit window I do Run > Run Module.  The output is printed in the IDLE shell window.

Update January 2017

A friend told me Pylint would catch some errors that compiling Python code would not catch.  It turns out he was right.  I was glad I used Pylint.  I said earlier that it is hard to test Python modules that are part of complex systems.  You could use the unittest unit testing framework from Python, which is patterned after JUnit for Java, but then you have to write the test code.  It is nice to have the budget and schedule to write test code, but that happens rarely.  When your code interacts with an external software system then you have to wait until you have access to the other system or must have a simulator for the other system.  A decent simulator is important for expensive and complex systems, but the simulator should be provided by the company supplying the external system.  The external system can be a networked hardware unit.  Getting good interface documentation (command messages and response messages) from the company providing the networked hardware or software is vital.  Remember that both the interface documentation and the simulator must be in the contract.  The other company cannot be relied upon to supply these unless they are contractually obligated to supply them.

Robert

Monday, July 25, 2016

Notepad++ Tips

Changing Font Size in  Notepad++
Notepad++ is a very nice editor for use on a Windows computer.  I have it on a number of machines.  For some reason, on one of my machines, the text font was too small.  It was easy to find on the internet that I could change the font size with Settings > Style Configurator.  However, the font size did not change.  Here is the trick:  if you decide to change the global font, you will also need to check the "Enable global font" and "Enable global font size" check boxes.

I found that advice here.

White Space
I described in the past how to have good visibility and good control over white space.  Now I want to tip you off to a side-effect of updating Notepad++ to a new version:  A new version of Notepad++ wipes out your white space setting.  You will end up with tabs again for the automatic indents, which can break code. So, when you update to a newer version, check the white space settings and fix them in necessary.

Robert

Thursday, March 10, 2016

Google AlphaGo Software Defeats World Class Go Player

The Wall Street Journal article "Google Beats Go Champion" by Alastair Gale and Jonathan Chen, March 10, 2016, page B5, describes how the Go program owned by Google, AlphaGo, defeated former world champion Lee Se-dol in the first game of their 5 game match.  Previously, this computer program had defeated the European Go champion Fan Hui 5-0.

The importance of AlphaGo is enormous. The same techniques could be applied not only to robotics and scientific research, but so many other tasks .... “You can apply it to any adversarial problem—anything that you can conceive of as a game, where strategy matters,” says Chris Nicholson, founder of the deep learning startup Skymind. “That includes war or business or [financial] trading.”
The quote above is from this article:
http://www.wired.com/2016/01/in-a-huge-breakthrough-googles-ai-beats-a-top-player-at-the-game-of-go/

Both the business aspects of this development and the software developments are interesting.  From the business perspective, it is interesting to notice that Google did not develop this program.  Google acquired AlphaGo when it purchased the U.K. company called DeepMind. 

From the software perspective, the types of algorithms used by AlphaGo are of interest.  At its core, the program uses a machine-learning method known as deep learning.  The AlphaGo team says in a technical article that they introduced a new search algorithm that combines Monte Carlo simulation with value and policy networks.  The program uses two neural networks.  One is a policy network that suggests a limited number of moves.  The second is a value network that reduces the depth of a search, maybe looking only 20 moves deep.  The technical article also makes reference to convolutional filters, so there is some serious math used in the program.

AlphaGo is not just software.  The hardware for the program used about 170 GPU (Graphical Processing Unit) cards and 1,200 standard processors, or CPUs.

The following article has a good description of the development of the program: 
https://www.technologyreview.com/s/546066/googles-ai-masters-the-game-of-go-a-decade-earlier-than-expected/
There is a brief YouTube video embedded in the article that is very nice.

The game of Go is very different from the game of chess. In chess you start with all the pieces on the board in fixed locations.  As a chess game progresses, the pieces move and when captured are removed from the board.  In Go the board is empty at the start and pieces are added with every move, never moving after they are placed.  There is only one type of piece in Go, a stone.  In chess there are six types of pieces.  The goal of chess is to capture the opposing king.  In Go the goal is to control more space on the board than your opponent.  The game of Go is more abstract than chess.

Having a Go program that defeats world caliber players is a monumental achievement. There is great anticipation in the business world for exploiting the type of algorithms used by AlphaGo.

Programmers always want to know which programming language was used in a program like AlphaGo.  The programming language is not mentioned anywhere.  The artificial intelligence and mathematics techniques are the driving factors towards the success of this endeavor.

The important take-away for programmers is that programming is not necessarily the star of a successful software product.

Robert

Friday, January 1, 2016