Skip to content

Profiling vignette #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/Test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Install dependencies
run: |
install.packages(c("posterior", "cmdstanr", "remotes", "curl"),repos = c("https://mc-stan.org/r-packages/", getOption("repos")), dependencies = TRUE)
cmdstanr::install_cmdstan(cores = 2, overwrite = TRUE)
cmdstanr::install_cmdstan(cores = 2, overwrite = TRUE, version = "2.26.0-rc1")
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("covr")
remotes::install_cran("gridExtra")
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
- name: Install dependencies
run: |
install.packages(c("posterior", "cmdstanr", "remotes", "curl"),repos = c("https://mc-stan.org/r-packages/", getOption("repos")), dependencies = TRUE)
cmdstanr::install_cmdstan(cores = 2, overwrite = TRUE)
cmdstanr::install_cmdstan(cores = 2, overwrite = TRUE, version = "2.26.0-rc1")
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("covr")
remotes::install_cran("gridExtra")
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ files. (#414)
information from R if profiling used in the Stan program. Support for profiling
Stan programs requires CmdStan >= 2.26. (#434)

* New vignette on profiling Stan programs. (#435)


# cmdstanr 0.3.0

Expand Down
7 changes: 4 additions & 3 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ url: https://mc-stan.org/cmdstanr
destination: docs

development:
mode: auto
mode: release

template:
params:
Expand Down Expand Up @@ -65,10 +65,11 @@ articles:
- title: "More details"
desc: >
More information about compilation, passing in data,
how CmdStan ouput is written to CSV and read back into R, and
using CmdStanR in R Markdown documents.
how CmdStan ouput is written to CSV and read back into R,
profiling Stan programs, and using CmdStanR in R Markdown documents.
contents:
- cmdstanr-internals
- profiling
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When creating a new vignette you need to add the file name (without the .Rmd) to the articles section of _pkgdown.yml

- r-markdown

reference:
Expand Down
8 changes: 5 additions & 3 deletions docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

292 changes: 292 additions & 0 deletions docs/articles/profiling.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Hide empty <a> tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
// v0.0.1
// Written by JooYoung Seo ([email protected]) and Atsushi Yasumoto on June 1st, 2020.

document.addEventListener('DOMContentLoaded', function() {
const codeList = document.getElementsByClassName("sourceCode");
for (var i = 0; i < codeList.length; i++) {
var linkList = codeList[i].getElementsByTagName('a');
for (var j = 0; j < linkList.length; j++) {
if (linkList[j].innerHTML === "") {
linkList[j].setAttribute('aria-hidden', 'true');
}
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Styles for section anchors */
a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;}
a.anchor-section::before {content: '#';}
.hasAnchor:hover a.anchor-section {visibility: visible;}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020.
document.addEventListener('DOMContentLoaded', function() {
// Do nothing if AnchorJS is used
if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) {
return;
}

const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6');

// Do nothing if sections are already anchored
if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) {
return null;
}

// Use section id when pandoc runs with --section-divs
const section_id = function(x) {
return ((x.classList.contains('section') || (x.tagName === 'SECTION'))
? x.id : '');
};

// Add anchors
h.forEach(function(x) {
const id = x.id || section_id(x.parentElement);
if (id === '') {
return null;
}
let anchor = document.createElement('a');
anchor.href = '#' + id;
anchor.classList = ['anchor-section'];
x.classList.add('hasAnchor');
x.appendChild(anchor);
});
});
12 changes: 12 additions & 0 deletions docs/articles/profiling_files/header-attrs-2.3/header-attrs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});
10 changes: 5 additions & 5 deletions tests/testthat/test-install.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
context("install")

if (not_on_cran()) {
cmdstan_test_tarball_url <- Sys.getenv("CMDSTAN_TEST_TARBALL_URL")
#cmdstan_test_tarball_url <- Sys.getenv("CMDSTAN_TEST_TARBALL_URL")
cmdstan_test_tarball_url <-
"https://github.com/stan-dev/cmdstan/releases/download/v2.26.0-rc1/cmdstan-2.26.0-rc1.tar.gz"
if (!nzchar(cmdstan_test_tarball_url)) {
cmdstan_test_tarball_url <- NULL
}
Expand Down Expand Up @@ -38,14 +40,12 @@ test_that("install_cmdstan() errors if installation already exists", {
install_dir <- tempdir()
}
dir <- file.path(install_dir, "cmdstan-2.23.0")
fake_folder <- FALSE
if (!dir.exists(dir)) {
fake_folder <- TRUE
dir.create(dir)
}
expect_warning(
install_cmdstan(dir = install_dir, overwrite = FALSE,
release_url = cmdstan_test_tarball_url),
version = "2.23.0"),
"An installation already exists",
fixed = TRUE
)
Expand All @@ -59,7 +59,7 @@ test_that("install_cmdstan() errors if it times out", {
} else {
dir <- tempdir(check = TRUE)
}
ver <- latest_released_version()
ver <- "2.26.0-rc1" #latest_released_version()
dir_exists <- dir.exists(file.path(dir, paste0("cmdstan-",ver)))
# with quiet=TRUE
expect_warning(
Expand Down
2 changes: 2 additions & 0 deletions vignettes/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.html
*.R
profiling-files/profiling_bernoulli_logit_glm
profiling-files/profiling_bernoulli_logit
8 changes: 8 additions & 0 deletions vignettes/profiling-files/profiling.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@misc{gelman2020bayesian,
title={Bayesian Workflow},
author={Andrew Gelman and Aki Vehtari and Daniel Simpson and Charles C. Margossian and Bob Carpenter and Yuling Yao and Lauren Kennedy and Jonah Gabry and Paul-Christian Bürkner and Martin Modrák},
year={2020},
eprint={2011.01808},
archivePrefix={arXiv},
primaryClass={stat.ME}
}
19 changes: 19 additions & 0 deletions vignettes/profiling-files/profiling_bernoulli_logit.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
data {
int<lower=1> k;
int<lower=0> n;
matrix[n, k] X;
int y[n];
}
parameters {
vector[k] beta;
real alpha;
}
model {
profile("priors") {
target += std_normal_lpdf(beta);
target += std_normal_lpdf(alpha);
}
profile("likelihood") {
target += bernoulli_logit_lpmf(y | X * beta + alpha);
}
}
19 changes: 19 additions & 0 deletions vignettes/profiling-files/profiling_bernoulli_logit_glm.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
data {
int<lower=1> k;
int<lower=0> n;
matrix[n, k] X;
int y[n];
}
parameters {
vector[k] beta;
real alpha;
}
model {
profile("priors") {
target += std_normal_lpdf(beta);
target += std_normal_lpdf(alpha);
}
profile("likelihood") {
target += bernoulli_logit_glm_lpmf(y | X, alpha, beta);
}
}
Loading