---
title: "Frequently Asked Questions"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{faq}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

### 1) How to define a new transformer? 

Transformers are unary functions that are applied on the covariates. Here is an example of "to the power of 5".

```{r, include = TRUE}
pow5 <- function(x) {x^5}
```
Which you can pass it into the transformers list as `"pow5"`.

### 2) Is the order of transformers important?

The `gen_pseudo_pop` function tries transformers if the covariate balance test has not been met in the previous attempt. The covariate with the worst balance value will be chosen to apply a transformer. The first transformer from the list will be selected for this purpose. If the transformer has been used for this specific covariate, the next value will be selected. 

### 3) How change the logger level?

You can use `set_logger` function and set logger_level to one of "TRACE", "DEBUG", "INFO", "SUCCES", "WARN", "ERROR", or"FATAL". In this package most of the internal information are logged in INFO and DEBUG level. If you need to see a new information in the .log file, please consider opening and issue [here](https://github.com/fasrc/CausalGPS/issues).

### 4) Is there any trade-off between number of CPU cores (nthread) and memory usage?

We are using a spawning mechanism in multicore processing. Each worker processor gets a copy of the required data and libraries. In case of limited available memory and a large dataset, you can reduce the number of CPU cores (nthread) to fit the processing into your system. Following this recommendation, the processing time will increase; however, the memory usage will decrease.

### 5) I am using macOS, however, I cannot see any performance increase with increasing number of threads (nthread).

Many internal libraries (e.g., `XGBoost`) are dependent on OpenMP library for parallel computation. Please make sure that you have installed OpenMP library and configured it correctly. Please see the following links for more details:

- [Installing data.table on macOS](https://github.com/Rdatatable/data.table/wiki/Installation)  
- [Installing XGBoost on macOS ](https://xgboost.readthedocs.io/en/latest/install.html#r)  
 
### 6) I am running the package on HPC; however, I think the package is using only one core. 

In order to activate OpenMP on HPC, you need to load the required modules. For example, if you are using SLURM on Cannon at Harvard University, you need to load the intel module.

```sh
module load intel/19.0.5-fasrc01
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK
```

Please read more [here](https://docs.rc.fas.harvard.edu/kb/running-jobs/#Using_Threads_such_as_OpenMP).
