Skip to content

Commit

Permalink
fix cache resizing not working (#53)
Browse files Browse the repository at this point in the history
- Also moves version up to 1.2.2
- Also exposes the env variables used by `panel serve`
  • Loading branch information
SarahG-579462 authored Jun 5, 2024
2 parents 5ae9c29 + 5e0d97e commit 7d0d986
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
10 changes: 9 additions & 1 deletion core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@
datavar_path = WRITE_DIR / Path('datavars.json')
cache_path = WRITE_DIR / Path('cache/')
version_path = WRITE_DIR / Path('versions.json')
cities_file = Path('cities_tmp.geojson')
cities_file = Path('cities_tmp.geojson')

# Cache Size (in bytes). Set to None for no limit.
# 1e9 = 1 GB. 1e6 = 1 MB.
# CACHE_SIZE = None
CACHE_SIZE=1e9
# Number of items to keep in the cache. Set to None for no limit.
# CACHE_ITEMS = None
CACHE_ITEMS=None
10 changes: 7 additions & 3 deletions core/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
cache_path,
minpts,
maxpts,
min_density)
min_density,
CACHE_SIZE,
CACHE_ITEMS)

from .utils import (
get_quality_flag,
Expand All @@ -38,7 +40,7 @@

import logging
from joblib import Memory
mem = Memory(cache_path, verbose=0, bytes_limit=1e9, compress=9)
mem = Memory(cache_path, verbose=0, bytes_limit=CACHE_SIZE, compress=9)
logger = logging.getLogger('analogs')

@mem.cache(ignore=["cities","dref","dsim"])
Expand Down Expand Up @@ -290,7 +292,9 @@ def _analogs_search( sim,
ilon = ilon_ref.get_loc(lon,method='nearest')

analogs[ireal,:] = np.around(_to_short(site,zscore.item(),score.item(),ilat,ilon))


mem.reduce_size(bytes_limit=CACHE_SIZE, items_limit=CACHE_ITEMS)

return np.array(analogs,dtype='<u2').tobytes()


Expand Down
2 changes: 1 addition & 1 deletion scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Important - in order to notify the CCDP portal that the iframe has been successfully loaded.
window.parent.postMessage("JESUISICI", "*");
console.log("Analogues Spatiaux v1.0.2", "*");
console.log("Analogues Spatiaux v1.2.2", "*");
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup, find_packages
setup(
name='AnaloguesCore',
version='1.0.2',
version='1.2.2',
author='Sarah Gammon',
author_email='[email protected]',
description='Core module for spatial analogues dashboard app',
Expand Down
24 changes: 15 additions & 9 deletions start_panel.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
#!/bin/bash

SETUP_FILE="setup_cache.py"
DASHBOARD_FILE="Dashboard.py"
SETUP_FILE="${SETUP_FILE:-setup_cache.py}" # default to "setup_cache.py"
DASHBOARD_FILE="${DASHBOARD_FILE:-Dashboard.py}" # default to "Dashboard.py"
echo "SETUP_FILE: $SETUP_FILE"
echo "DASHBOARD_FILE: $DASHBOARD_FILE"

SESSION_TOKEN_EXPIRATION=86400
LOG_LEVEL="debug"
MAX_PROCS=$(nproc --all)

NUM_PROCS=$((MAX_PROCS - 1 > 16 ? 16 : MAX_PROCS - 1))
NUM_PROCS=0
SESSION_TOKEN_EXPIRATION="${SESSION_TOKEN_EXPIRATION:-86400}"
echo "SESSION_TOKEN_EXPIRATION: $SESSION_TOKEN_EXPIRATION"
# one of [debug, info, warning, error, critical]
LOG_LEVEL="${LOG_LEVEL:-info}" # default to "info"
echo "LOG_LEVEL: $LOG_LEVEL"
MAX_PROCS="${MAX_PROCS:-$(nproc --all)}" # default to number of cores
echo "MAX_PROCS: $MAX_PROCS"
NUM_PROCS="${NUM_PROCS:-$((MAX_PROCS - 1 > 16 ? 16 : MAX_PROCS - 1))}" # default to number of cores - 1, or 16, if number of cores is more than 16.
echo "NUM_PROCS: $NUM_PROCS"
#NUM_PROCS=0
NUM_THREADS=0

panel serve \
"${DASHBOARD_FILE}" \
--setup "${SETUP_FILE}" \
--session-token-expiration "${SESSION_TOKEN_EXPIRATION}" \
--prefix "${PREFIX}" \
--use-xheaders --log-level="${LOG_LEVEL}" \
--use-xheaders --log-level "${LOG_LEVEL}" \
--static-dirs fonts=./fonts scripts=./scripts \
--num-procs $NUM_PROCS \
--num-threads $NUM_THREADS

0 comments on commit 7d0d986

Please sign in to comment.