Scientific Computing

Update MiKTeX packages

Update MiKTeX packages to avoid issues with compiling documents. This is even true for a fresh MiKTeX install.

  1. Start → MiKTeX Console → Updates → Check for updates
  2. if updates available, click Update now

Anytime you get an unexpected error, try updating MiKTeX packages.

Convert IDL code to MATLAB

IDL2Matlab automatically partially converts IDL code to MATLAB / Octave code. However, this project appears to be abandoned; there haven’t been updates in a few years.

I avoid converting code if possible, because it can introduce subtle errors. Here are some alternatives to run the unmodified IDL code for free.

Try using free GDL that is compatible with IDL.

Another possibility is to call IDL from Python or Python from IDL.

Call GDL from Python by simply: import GDL see PYTHON.TXT

Install idl2matlab for Linux: download prereqs and code:

apt install libbison-dev flex

git clone https://github.com/farhi/idl2matlab

cd idl2matlab

Prepare to install in $HOME directory

./configure --prefix=$HOME

Edit Makefile

CFLAGS = -g -fno-stack-protector

Compile and install under $HOME

make && make install

The MATLAB code that idl2matlab produces uses a sort of cumbersome Matlab script that calls its own Matlab functions to do common tasks. The converted code can be further optimized. Still, probably easier than doing it all manually.

Completely undo errant git remote push

For any Git remote repo, you can undo (delete from git history) previous commits to eliminate wrong files via git push. If you only git revert, this leaves the big mess inside the .git directory, slowing down operations and wasting space.

Erase previous git commits

Before attempting recovery, copy local project to a remote backup location e.g. Dropbox.

Assuming it’s the last commit and push to delete from the Git history:

git reset --hard HEAD^
git push --force

Any time the git --force option is used, work can be permanently and irrecoverably lost, so always use care.

Reapply desired commit work

Copy any files from the old repo and make a new commit/push in the new repo. Every other computer with a copy of this repo will need to:

  1. make a backup copy of their local repo, if they did any work that needs to be saved
  2. git clone the repo again and likewise copy their changes back in.

Yes, they could git reset, but they might erase their work in that repo, if any.

Git remote write permissions

Implicit in this procedure is that those with write access to the remote Git repo can overwrite history, potentially causing permanent file loss. Remember that Git is a revision tracking system, NOT a backup system.

Restrict Git remote write access: for GitHub, from the repo branches Settings page, Add Rules according to the needs.

JAVA_HOME environment variable

Java programs like ImageJ may refuse to start because they cannot find JAVA_HOME environment variable. Be sure Java JRE is installed.

apt install default-jre

Try commands:

which default-java

suppose it’s at /usr/lib/jvm/default-java, then:

JAVA_HOME=/usr/lib/jvm/default-java imagej

where imagej is the Java program of interest. If the command now works, in ~/.profile set

export JAVA_HOME=/usr/lib/jvm/default-java

non-sudo Homebrew on Linux

Homebrew is for Linux and macOS, allowing install of the latest compilers and other packages without sudo.

Use the Homebrew install script without sudo.

Install desired packages such as Gfortran:

brew install gcc

Generally the latest compilers are available from Homebrew for Linux and macOS.

Instead of putting Homebrew environment variables into ~/.profile, consider putting them into ~/brew.sh activate them when needed, instead of constantly being active. Either choice is fine of course.

Create ~/brew.sh containing:

PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
MANPATH="/home/linuxbrew/.linuxbrew/share/man:$MANPATH"
INFOPATH="/home/linuxbrew/.linuxbrew/share/info:$INFOPATH"
HOMEBREW_EDITOR="nano"

To use Homebrew, type

source ~/brew.sh

Upon closing the terminal, the configuration falls back to default (non-Homebrew)

Prolific driver version on Windows

Some older Prolific-based USB interfaces–such as used to program two-way radios–can fail to be recognized on Windows upon first plugin. Looking in Windows Device Manager, the device shows up with a yellow caution sign, and an error message like:

This device cannot start. (Code 10) {Not Enough Quota} Not enough virtual memory or paging file quota is available to complete the specified operation.

Usually the fix is to install an older version of the Prolific driver that is less sensitive to Prolific chip version. We have experienced that the Prolific 3.6 - 3.8 drivers are subject to this issue.

We can’t vouch for the older Prolific 3.2 drivers available but they do work.

Easy install PyPy3

PyPy:

  • allows running Python code up to multiple times faster.
  • particularly suited for heavy “pure Python” workloads.
  • does not significantly help for workloads heavy in Numpy array operations, for example.
  • slower to start, so if a program isn’t “big enough”, PyPy can be slower than standard CPython.
  • available for Linux, macOS and Windows.
  1. download and extract PyPy3 for your operating system.
  2. add the pypy3 directory containing the PyPy3 executable to the PATH and reopen Terminal

Install/upgrade Pip so that you can install other packages:

pypy3 -m ensurepip

pypy3 -m pip install --upgrade pip setuptools wheel

Many PyPI packages can be installed with pip as usual. On Windows, the appropriate version of Microsoft Visual Studio may be required to compile packages from source.

pypy3 -m pip install numpy

Some packages don’t work yet easily, particularly on Windows where the compilers and prerequisite libraries may need to be manually built.