Miscellaneous

Local LLM Configuration

We have made available a locally hosted LLM API service at https://llm-1.stat.ubc.ca for use by faculty and staff.

In order to send prompts to the service, you'll first need an API key. Simply open the link https://llm-1.stat.ubc.ca on any browser and log in with your StatNet username and password. Then you can generate a key with the dialogue after you log in. Make sure to copy the key and save it in a secure location. 

To send prompts to the API, there are a few options. 

 

opencode

An open source terminal based coding assistant very similar to Claude Code. Installation instructions are here https://opencode.ai/docs/#install

Once installed, open a terminal window and launch it with the command opencode

Close it and then navigate to and open the file ~/.config/opencode/opencode.jsonc

Update the configuration file to the following replacing "YOUR_API_KEY" placeholder with the API key generated earlier. Then launch opencode again and you should now be able to send prompts to our local LLM.

{
  "$schema": "https://opencode.ai/config.json",
  "default_agent": "plan",
  "permission": {
    "edit": "ask"
  },
  "provider": {
    "llm-1-stat": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Qwen 3.6 (Stat UBC)",
      "options": {
        "baseURL": "https://llm-1.stat.ubc.ca/v1",
        "apiKey": "YOUR_API_KEY"
      },
      "models": {
        "qwen/Qwen3.6-35B-A3B-FP8": {
          "name": "Qwen 3.6 Coder",
          "attachment": true,
          "modalities": {
            "input": ["text", "image"],
            "output": ["text"]
          },
          "limit": {
            "context": 32768,
            "output": 16384
          }
        }
      }
    }
  },
  "model": "llm-1-stat/qwen/Qwen3.6-35B-A3B-FP8"
}

 

Visual Studio Code (VSCode)

VSCode is an easy to use UI based code editor maintained by Microsoft. Installation instructions are here https://code.visualstudio.com/docs/setup/linux choose the instructions for your OS (Linux/Mac/Windows) on the menu to the left of the site.
 
After installing VSCode, do these steps.
 
  1. Install the Continue extension within VSCode
  2. Within Continue, Add Chat Model +
  3. Choose GPT-5.4 Pro as the template so "provider: openai" will be in the config.yaml file.
  4. Edit config.yaml in VS Code; don't edit it manually from a Terminal.
The file is in ~/.continue/config.yaml replace 'your llm-1 API key' with the API key generated earlier.
 
- name: Qwen 3.6 (Stat UBC)
 provider: openai
 model: qwen/Qwen3.6-35B-A3B
 apiBase: https://llm-1.stat.ubc.ca/v1
 apiKey: your llm-1 API key
 roles:
  - chat
  - edit
  - apply
 capabilities:
  - image_input
 
  1. Save the file.
  2. Restart VSCode or Reload VS Code: Cmd/Ctrl+Shift+P"Developer: Reload Window".
  3. Open the Continue panel and try a chat message.

The Continue extension has three modes Chat, Plan, and Agent:

Here are descriptions for the three modes:

Chat Mode: Pure conversation with no tools.
Plan Mode: Safe, read-only tools for planning and exploration without making edits.
Agent Mode: Full tool access to autonomously make changes to your codebase.

 

Claude Code

Claude Code is a proprietary terminal based coding assistant maintained by Anthropic. While it works for now, it's not guaranteed to work with our local LLM in the future if they suddenly decide that they won't support it. 

Install Claude Code with instructions here https://code.claude.com/docs/en/quickstart

Open a terminal window and set the following environment variables. Replace "YOUR_API_KEY" with the API key generated earlier.

ANTHROPIC_BASE_URL="https://llm-1.stat.ubc.ca"

ANTHROPIC_API_KEY="YOUR_API_KEY"

Start Claude Code with command claude code 

FAQ Category

How do I find the true URL of an FAQ?

The key is to find the accordion-### for the true URL.
/node/accordion-###

1. Find your way to a FAQ page that includes the QA of interest.
Here is an example using Chrome:
I am interested being a Major in Statistics. How can I apply?
Navigate to
/faqs?page=3
2. When on that page, right-clicking over the FAQ item, select "Inspect".
The tool window will highlight the accordion-### line.
(The 'x' on the top right will close this tool window.)
3. The question sits inside a div with an id of the form accordion-###.
<div id="accordion-10142"
Copy or make note of the four digit code (10142 in the example).
4. Form a URL using this code as follows:
/node/accordion-###. For the example, it's
/node/10142. This URL can be shared with the student.

FAQ Category

How to get Mouse to focus or FocusFollowsMouse on a MacIntosh?

This can be made to work only for X11 applications. The following seems to work. In your .bashrc file, add

  defaults write com.apple.x11 wm_ffm -bool true
  defaults write com.apple.Terminal FocusFollowsMouse -string YES

Logout and then login again. Open two xterm's and focus should follow mouse for the xterm's.

FAQ Category

Focus follows mouse

Open A Terminal (Black Icon).  You don't need admin right to run the command.
Type this:
defaults write com.apple.Terminal FocusFollowsMouse -string YES
Quit and restart Terminal program.

FAQ Category

How to read SAS data files int Splus?

Method 1. 

If you are using SAS version 6.12 in Unix... 

Step 1 
Output SAS data to the desired directory as usual. The file extension using SAS version 6.12 should be .ssd01. Suppose a SAS data file named myfile.ssd01 is located under /home/user/data/

Step 2 
In Splus 3.4 or above, use the function sas.get(). For example, if you want to name the data set as "mydata" in Splus, type the following at the Splus prompt: 

      mylibrary <- "/home/user/data/" 
      mydata <- sas.get(mylibrary,"myfile") 

For more detail, do help(sas.get)

OR 

In Splus 5 or above, use the function importData(). For example, if you want to name the data set as "mydata" in Splus, type the following at the Splus prompt: 

      mydata <- importData("/home/user/data/myfile.ssd01",type="SAS1") 

For more detail, do help(importData)

If you are using SAS version 7 in Unix... 

Step 1 
Output SAS data to the desired directory as usual. The file extension using SAS version 7 should be .sas7bdat. Suppose a SAS data file named myfile.sas7bdat is located under /home/user/data/

Step 2 
In Splus 5 or above, use the function importData(). For example, if you want to name the data set as "mydata" in Splus, type the following at the Splus prompt: 

      mydata <- importData("/home/user/data/myfile.sas7bdat",type="SAS7") 

For more detail, do help(importData)

If you are using SAS version 8 in Unix... see Method 2. 


Method 2 (recommended). Create a transport file from SAS (this works for SAS version 6.12 or above) 

Step 1 
In the SAS code, include the following line when defining SAS libraries: 

      libname sasdata xport "/home/user/data/file.tpt"; 
 

  • "libname" and "xport" are required in the syntax
  • "sasdata" is the user-defined library name
  • "/home/user/data/file.tpt" is the full path name of the transport file (Note the .tpt extension!). "file.tpt" is the file you want to output from SAS and later to be read into Splus


Don't forget to name the file to be outputted in a SAS procedure as "sasdata.file.tpt" in the SAS code!

Step 2 
In Splus 5 or above, use the function importData(). For example, if you want to name the data set as "mydata" in Splus, type the following at the Splus prompt: 

      mydata <- importData("/home/user/data/file.tpt",type="SAS_TPT") 

For more detail, do help(importData)

Note: 
1. Splus 3.4 does not have the importData() function. 
2. The sas.get() function may not read data files created by SAS of version 7 or above. 
3. The importData() function may not read data files from SAS of version 8 even though the file suffix can be the same as version 7 files (.sas7bdat). 
4. For Splus 4+ in Windows, use the import.data() function instead.

FAQ Category

How to read Microsoft Excel format (.xls) data file by R?

There seem direct way to read .xls format file (see http://maths.newcastle.edu.au/~rking/R/help/00b/2519.html).

However, there some ways to indirectly read .xls file. For example, you can save the .xls file into .csv (comma separated value) format. Then use R's function read.csv to read it.

The reason to save .xls file to .csv file is that usually there are some columns in .xls file which are strings containing white spaces. So if to save .xls file to white space delimited or TAB delimited, then it is still difficult to read the file into R.

FAQ Category

How to call Fortran subroutines in R?

In R, we can call Fortran subroutines. For example, we have the following toy Fortran subroutine in the file test.f.

CCCCCCCCCCCCCCCCC
C      The subroutine is to calculate Hadama product of two matrices.
C      out[i][j]=x[i][j]*y[i][j].
C      Both R and Fortran store matrix by column.
CCCCCCCCCCCCCCCCC

CCCCCCCCC Fortran program (f77) has to be between 7-th and 72-th column.
CCCCCCCCC The 6-th column is for continuation marker.

         subroutine myHadamaProduct(x, y, nrow,  ncol, mo)
           integer i, j, nrow, ncol
CCCCCCC In Fortran, you don't need to specify the second dimension for matrix
           double precision x(nrow, *), y(nrow, *), mo(nrow, *)

           do i = 1, nrow
            do j = 1, ncol
              mo(i,j)=x(i,j)*y(i,j)
            enddo
           enddo
           return
           end
  1. First, we need to compile the file test.f to create a shared library, test.so say, by using the GNU Fortran compiler:

     

        g77 -fpic -shared -fno-gnu-linker -o test.so test.f
    
  2. Next, we need to use the R function dyn.load to load the shared library test.so.

        if(!is.loaded("myhadamaproduct")){ dyn.load("./test.so") }
    

    The R function is.loaded is to check if the Fortran subroutine myHadamaProduct is already be loaded to R. If yes, then we do not need to loaded it again.

  3. Next, we use the R function .Fortran to call the Fortran subroutine myHadamaProduct. For example,

        x<-matrix(1:10,nrow=5, ncol=2) # get a 5x2 matrix
        y<-matrix(1:10,nrow=5, ncol=2) # get a 5x2 matrix
        out<-matrix(0, nrow=5, ncol=2) # initialize output matrix
    
        # to format matrix or array, use function storage.mode()
        storage.mode(x)<-"double"
        storage.mode(y)<-"double"
        storage.mode(out)<-"double"
        nr<-as.integer(nrow(x))
        nc<-as.integer(ncol(x))
    
        # Fortran is *NOT* case-sensitive. So it will change the all characters
        # to lower case. Thus, to use .Fortran call Fortran subroutines, you
        # have to type lower case. Otherwise, R will prompt error message.
        res<-.Fortran("myhadamaproduct", x, y, nr, nc, out=out)
    
        cat("Hadama product >>n")
        print(res$out)
    
  4. If you do not need to use the shared library test.so any more, you can use the R function dyn.unload to unload it.

        if(is.loaded("myhadamaproduct")){ dyn.unload("./test.so") }
    

Note:

  • The Fortran program called by R must be subroutines, not functions. For the example above, myHadamaProduct is defined as subroutine.

             subroutine myHadamaProduct(x, y, nrow,  ncol, mo)
    

    The arguments in Fortran subroutines are passed by address instead of by values. And not like C language, there is no "pointer" concept in Fortran.

     

  • When you use ".Fortran" to call Fortran subroutines, the name of the Fortran subroutines must be in lower case.
  • Any values returned by Fortran subroutines which are called in R must be initialized and must have the format:

        # if the variable is defined as double in the Fortran subroutine
        variablename=as.double(initialized values) # inside .Fortran
        # if the variable is defined as integer in the Fortran subroutine
        variablename=as.integer(initialized values) # inside .Fortran
        # if the output is double precision matrix or array
        storage.mode(variablename)<-"double" # before .Fortran
        variablename=variablename # inside .Fortran
    

    The input values must also be initialized and must have the above format. However, they can be formated before the ".Fortran" function.

     

  • If the output is not written as variablename=variablename format (e.g. out=out in the above example), You still can get results. However, you have to use res[[5]] to refer out in the above example. In fact, the .Fortran function return a list containing all arguments of the Fortran subroutine myHadamaProduct. Since out is the 5-th argument, you can use res[[5]] to refer to the 5-th elements of the list.
  • It is okay that the file test.f contains the main program.
  • Sometimes, the command "dyn.load("test.so")" gets error message. This is probably caused by the environment variable "$PATH" was not set correctly. You can either add the following line to the file ".bashrc" in your home directory:

        export PATH=$PATH:.:
    

    or use the command

        dyn.load("./test.so")
FAQ Category