Skip to content

Commit 194c684

Browse files
committed
Pick up path to condor tools from env var
1 parent 5379e9a commit 194c684

File tree

3 files changed

+93
-7
lines changed

3 files changed

+93
-7
lines changed

README.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ dependencies:
2020
- htcondor
2121
- pip
2222
- pip:
23-
- ncsa-htcdaskgateway>=1.0.2
23+
- ncsa-htcdaskgateway>=1.0.4
24+
- dask==2025.2.0
25+
- distributed==2025.2.0
26+
- tornado==6.4.2
2427
```
2528
2629
From a Jupyter terminal window create the conda environment with:
@@ -30,6 +33,10 @@ conda env create -f conda.yaml
3033
conda activate dask-gateway
3134
```
3235

36+
_Note:_ Depending on your conda setup, the `conda activate` command may not be
37+
available you can also activate the environment with the command
38+
`source activate dask-gateway`.
39+
3340
Now you can use the `setup_condor` script to set up the HTCondor tools. This
3441
will request your Illinois password and attempt to log into the HTCondor login
3542
node and execute a command that generates a token file. This token file is used
@@ -46,6 +53,84 @@ with
4653
condor_q
4754
```
4855

56+
## Use in Jupyter Notebook
57+
58+
In your Jupyter notebook first thing you need to do is activate the conda
59+
environment:
60+
61+
```shell
62+
!source activate dask-gateway
63+
```
64+
65+
Now you can pip install any additional dependencies. For objects that are sent
66+
to dask or received as return values, you must have the exact same versions.
67+
68+
```shell
69+
! python -m pip install numpy==2.2.4
70+
```
71+
72+
### Providing Path to Condor Tools
73+
74+
There are some interesting interactions between conda and Jupyter. Conda has
75+
installed the condor binaries, but doesn't update PATH in the notebook kernel.
76+
We use an environment variable to tell the htcdaskgateway client how to find the
77+
binaries.
78+
79+
In a terminal window:
80+
81+
```shell
82+
source activate dask-gateway
83+
which condor_q
84+
```
85+
86+
Back in your notebook:
87+
88+
```python
89+
import os
90+
91+
os.environ["CONDOR_BIN_DIR"] = "/home/myhome/.conda/envs/dask-gateway/bin"
92+
```
93+
94+
### Setting up a dotenv file
95+
96+
It is good practice to keep passwords out of your notebooks. Create a `.env`
97+
file that contains an entry for `DASK_GATEWAY_PASSWORD`
98+
99+
Add `python-dotenv` to your pip installed dependencies and add this line to your
100+
notebook:
101+
102+
```python
103+
from dotenv import load_dotenv
104+
105+
load_dotenv() # take environment variables from .env.
106+
```
107+
108+
### Connecting to the Gateway and Scaling up Cluster
109+
110+
Now we can finally start up a cluster!
111+
112+
```python
113+
from htcdaskgateway import HTCGateway
114+
from dask_gateway.auth import BasicAuth
115+
import os
116+
117+
gateway = HTCGateway(
118+
address="https://dask.software-dev.ncsa.illinois.edu",
119+
proxy_address=8786,
120+
auth=BasicAuth(username=None, password=os.environ["DASK_GATEWAY_PASSWORD"]),
121+
)
122+
123+
cluster = gateway.new_cluster(
124+
image="ncsa/dask-public-health:latest",
125+
container_image="/u/bengal1/condor/PublicHealth.sif",
126+
)
127+
cluster.scale(2)
128+
client = cluster.get_client()
129+
client
130+
```
131+
132+
This will display the URL to access the cluster dashboard
133+
49134
## How it Works
50135

51136
This is a drop-in replacement for the official Dask Gateway client. It keeps the

htcdaskgateway/_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
__version_tuple__: VERSION_TUPLE
1818
version_tuple: VERSION_TUPLE
1919

20-
__version__ = version = '1.0.2.dev0+g6b8821d.d20250415'
21-
__version_tuple__ = version_tuple = (1, 0, 2, 'dev0', 'g6b8821d.d20250415')
20+
__version__ = version = '1.0.2.dev6+g5379e9a.d20250418'
21+
__version_tuple__ = version_tuple = (1, 0, 2, 'dev6', 'g5379e9a.d20250418')

htcdaskgateway/cluster.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def __init__(self, container_image=None, **kwargs):
2020
self.batchWorkerJobs = []
2121
self.cluster_options = kwargs.get("cluster_options")
2222
self.container_image = container_image
23+
self.condor_bin_dir = os.environ["CONDOR_BIN_DIR"]
2324

2425
super().__init__(**kwargs)
2526

@@ -141,7 +142,7 @@ def scale_batch_workers(self, n):
141142
# We add this to avoid a bug on Farruk's condor_submit wrapper (a fix is in progress)
142143
os.environ["LS_COLORS"] = "ExGxBxDxCxEgEdxbxgxcxd"
143144
# Submit our jdl, print the result and call the cluster widget
144-
cmd = ". ~/.profile && condor_submit htcdask_submitfile.jdl | grep -oP '(?<=cluster )[^ ]*'"
145+
cmd = f". ~/.profile && {self.condor_bin_dir}/condor_submit htcdask_submitfile.jdl | grep -oP '(?<=cluster )[^ ]*'"
145146
logger.info(
146147
" Submitting HTCondor job(s) for %d workers with command: %s", n, cmd
147148
)
@@ -153,7 +154,7 @@ def scale_batch_workers(self, n):
153154
worker_dict["Iwd"] = tmproot
154155
try:
155156
cmd = (
156-
". ~/.profile && condor_q "
157+
f". ~/.profile && {self.condor_bin_dir}/condor_q "
157158
+ clusterid
158159
+ " -af GlobalJobId | awk '{print $1}'| awk -F '#' '{print $1}' | uniq"
159160
)
@@ -176,7 +177,7 @@ def scale_batch_workers(self, n):
176177
def destroy_batch_cluster_id(self, clusterid):
177178
logger.info(" Shutting down HTCondor worker jobs from cluster %s", clusterid)
178179
cmd = (
179-
". ~/.profile && condor_rm "
180+
f". ~/.profile && {self.condor_bin_dir}/condor_rm "
180181
+ self.batchWorkerJobs["ClusterId"]
181182
+ " -name "
182183
+ self.batchWorkerJobs["ScheddName"]
@@ -194,7 +195,7 @@ def destroy_all_batch_clusters(self):
194195
for htc_cluster in self.batchWorkerJobs:
195196
try:
196197
cmd = (
197-
". ~/.profile && condor_rm "
198+
f". ~/.profile && {self.condor_bin_dir}/condor_rm "
198199
+ htc_cluster["ClusterId"]
199200
+ " -name "
200201
+ htc_cluster["ScheddName"]

0 commit comments

Comments
 (0)