qbraid-cli 0.7.1__py3-none-any.whl → 0.8.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of qbraid-cli might be problematic. Click here for more details.

Files changed (41) hide show
  1. qbraid_cli/_version.py +14 -6
  2. qbraid_cli/admin/__init__.py +9 -0
  3. qbraid_cli/admin/app.py +50 -0
  4. qbraid_cli/admin/headers.py +193 -0
  5. qbraid_cli/admin/validation.py +33 -0
  6. qbraid_cli/configure/__init__.py +9 -0
  7. qbraid_cli/configure/actions.py +111 -0
  8. qbraid_cli/configure/app.py +77 -0
  9. qbraid_cli/credits/__init__.py +9 -0
  10. qbraid_cli/credits/app.py +32 -0
  11. qbraid_cli/devices/__init__.py +9 -0
  12. qbraid_cli/devices/app.py +80 -0
  13. qbraid_cli/devices/validation.py +26 -0
  14. qbraid_cli/envs/__init__.py +9 -0
  15. qbraid_cli/envs/activate.py +65 -0
  16. qbraid_cli/envs/app.py +270 -0
  17. qbraid_cli/envs/create.py +128 -0
  18. qbraid_cli/envs/data_handling.py +140 -0
  19. qbraid_cli/exceptions.py +17 -5
  20. qbraid_cli/handlers.py +168 -0
  21. qbraid_cli/jobs/__init__.py +9 -0
  22. qbraid_cli/jobs/app.py +149 -0
  23. qbraid_cli/jobs/toggle_braket.py +185 -0
  24. qbraid_cli/jobs/validation.py +93 -0
  25. qbraid_cli/kernels/__init__.py +9 -0
  26. qbraid_cli/kernels/app.py +111 -0
  27. qbraid_cli/main.py +80 -0
  28. {qbraid_cli-0.7.1.dist-info → qbraid_cli-0.8.0.dist-info}/METADATA +68 -46
  29. qbraid_cli-0.8.0.dist-info/RECORD +33 -0
  30. {qbraid_cli-0.7.1.dist-info → qbraid_cli-0.8.0.dist-info}/WHEEL +1 -1
  31. qbraid_cli-0.8.0.dist-info/entry_points.txt +2 -0
  32. qbraid_cli/_display.py +0 -44
  33. qbraid_cli/bin/qbraid.sh +0 -1346
  34. qbraid_cli/configure.py +0 -113
  35. qbraid_cli/envs.py +0 -195
  36. qbraid_cli/jobs.py +0 -226
  37. qbraid_cli/wrapper.py +0 -103
  38. qbraid_cli-0.7.1.data/scripts/qbraid.sh +0 -1346
  39. qbraid_cli-0.7.1.dist-info/RECORD +0 -15
  40. qbraid_cli-0.7.1.dist-info/entry_points.txt +0 -2
  41. {qbraid_cli-0.7.1.dist-info → qbraid_cli-0.8.0.dist-info}/top_level.txt +0 -0
qbraid_cli/bin/qbraid.sh DELETED
@@ -1,1346 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- ############################### QBRAID CLI ###############################
4
- ##########################################################################
5
- # Command Line Interface for interacting with the qBraid Lab platform
6
-
7
- # (C) Copyright 2024 qBraid Development Team
8
-
9
- ############################### PRESCRIPT ################################
10
- #-------------------------------------------------------------------------
11
- # Global variables
12
-
13
- # Styling
14
- NC="\033[0m" # No Color
15
- PURPLE="\033[0;35m"
16
- LIGHTPURPLE="\033[1;35m"
17
- RED="\033[0;31m"
18
- GREEN="\033[0;32m"
19
-
20
- # Environment directory paths
21
- USER_ENVS=${QBRAID_USR_ENVS:-"/home/jovyan/.qbraid/environments"}
22
- OPT_ENVS=${QBRAID_SYS_ENVS:-"/opt/.qbraid/environments"}
23
-
24
- # Arg parse
25
- NUMARGS=$#
26
- FLAGHELP=false
27
-
28
- if [ "${NUMARGS}" -gt 0 ]; then
29
- lastArg=$(echo "${@: -1}")
30
- if [ "${lastArg}" = "-h" ] || [ "${lastArg}" = "--help" ] || [ "${lastArg}" = "help" ]; then
31
- FLAGHELP=true
32
- fi
33
- fi
34
-
35
-
36
- #-------------------------------------------------------------------------
37
- # Environment slug to display name associative array
38
-
39
- declare -A jovyan_envs
40
- declare -A opt_envs=(
41
- ["qbraid_000000"]="default"
42
- )
43
- declare -A installed_envs
44
-
45
- #-------------------------------------------------------------------------
46
- # Environment display name to slug associative array
47
-
48
- is_valid_slug() {
49
- local slug=$1
50
- local len_slug=${#slug}
51
-
52
- # Check if the slug is of valid length
53
- if [ "$len_slug" -gt 20 ]; then
54
- return 1
55
- fi
56
-
57
- # Extract the alphanumeric part and check its length
58
- local alphanumeric_part=${slug: -6}
59
- if ! [[ $alphanumeric_part =~ ^[a-zA-Z0-9]{6}$ ]]; then
60
- return 1
61
- fi
62
-
63
- # Check if it contains an underscore before the alphanumeric part
64
- if [ "${slug: -7:-6}" != "_" ]; then
65
- return 1
66
- fi
67
-
68
- # Check if the remaining part of the slug contains only lowercase letters, numbers, and underscores
69
- local remaining_part=${slug:0:-7}
70
- if ! [[ $remaining_part =~ ^[a-z0-9_]*$ ]]; then
71
- return 1
72
- fi
73
-
74
- return 0 # Valid slug
75
- }
76
-
77
- process_installed_envs() {
78
- local directory=$1
79
- local -n envs=$2
80
-
81
- for entry in "$directory"/*
82
- do
83
- dir_name=$(basename "$entry")
84
-
85
- if is_valid_slug "$dir_name"; then
86
- slug_prefix=${dir_name:0:-7}
87
-
88
- if [[ -v envs[$dir_name] ]]; then
89
- env_name=${envs[$dir_name]}
90
- elif [[ -v installed_envs[$slug_prefix] ]]; then
91
- env_name=${dir_name}
92
- envs[$dir_name]=$env_name
93
- else
94
- env_name=${slug_prefix}
95
- envs[$dir_name]=$env_name
96
- fi
97
-
98
- # Check if env_name already exists in installed_envs
99
- if [[ -v installed_envs[$env_name] ]]; then
100
- # Use dir_name as the new environment name
101
- env_name=$dir_name
102
- fi
103
-
104
- if [ "$env_name" != "" ]; then
105
- installed_envs[$env_name]=$dir_name
106
- fi
107
- fi
108
- done
109
- }
110
-
111
- process_installed_envs "$OPT_ENVS" opt_envs
112
- process_installed_envs "$USER_ENVS" jovyan_envs
113
-
114
-
115
-
116
- #-------------------------------------------------------------------------
117
- # Helper functions
118
-
119
- # echos yes if should print help else no
120
- help_command() {
121
- if [ "${FLAGHELP}" = true ] && [ "${1}" = "${NUMARGS}" ]; then
122
- echo "yes"
123
- fi
124
- }
125
-
126
- find_match() {
127
- local -n envs=$1
128
- local target=$2
129
- local path=$3
130
-
131
- # Check if the item is a key
132
- if [[ -n "${envs["$target"]+isset}" ]]; then
133
- echo "$path/$target"
134
- return 0
135
- fi
136
-
137
- # Check if the item is a value
138
- for key in "${!envs[@]}"; do
139
- if [ "$target" = "${envs[$key]}" ]; then
140
- echo "$path/$key"
141
- return 0
142
- fi
143
- done
144
-
145
- # backwards compatibility
146
- if [ "$target" = "amazon_braket" ]; then
147
- slug="aws_braket_kwx6dl"
148
- echo "$path/$slug"
149
- return 0
150
- fi
151
-
152
- return 1
153
- }
154
-
155
- which_env() {
156
- local result
157
-
158
- result=$(find_match jovyan_envs "$1" "${USER_ENVS}")
159
- if [ $? -eq 0 ]; then
160
- echo "$result"
161
- return
162
- fi
163
-
164
- result=$(find_match opt_envs "$1" "${OPT_ENVS}")
165
- if [ $? -eq 0 ]; then
166
- echo "$result"
167
- return
168
- fi
169
-
170
- echo "None"
171
- }
172
-
173
- is_installed() {
174
- local result
175
-
176
- # use which_env helper with dummy argument for path
177
- result=$(find_match installed_envs "$1" "dummy_path")
178
- if [ $? -eq 0 ]; then
179
- echo true
180
- else
181
- echo false
182
- fi
183
- }
184
-
185
-
186
- print_env_entry() {
187
- env_name=$1
188
- count=$((25-${#env_name}))
189
- env_path=$(which_env "${env_name}")
190
- proxydir=$(which_jobs "${env_name}")
191
- python_path="${env_path}/pyenv/bin/python"
192
- active_indicator=""
193
-
194
- if [ "${python_path}" = "$(which python)" ]; then
195
- active_indicator="* "
196
- count=$((count-2))
197
- fi
198
-
199
- if [ "${proxydir}" = "None" ]; then
200
- echo -e "${env_name}$(spaces ${count})${active_indicator} ${env_path}"
201
- else
202
- proxyfile="${proxydir}/proxy"
203
- enabled=$(head -n 1 "${proxyfile}" | grep true)
204
- if [[ $enabled == *"true"* ]]; then
205
- echo -e "${env_name}$(spaces ${count})${active_indicator}${GREEN}jobs${NC} ${env_path}"
206
- else
207
- echo -e "${env_name}$(spaces ${count})${active_indicator}${RED}jobs${NC} ${env_path}"
208
- fi
209
- fi
210
- }
211
-
212
-
213
- has_package() {
214
-
215
- local env_path=$(which_env "${1}")
216
- local venv_path="${env_path}/pyenv"
217
- local cfg_file="$venv_path/pyvenv.cfg"
218
- local package_name=$2
219
-
220
-
221
- # Check if the virtual environment directory exists
222
- if [ ! -d "$venv_path" ]; then
223
- echo "Error: Virtual environment path '$venv_path' does not exist." >&2
224
- return 1
225
- fi
226
-
227
- # Check if the pyvenv.cfg file exists
228
- if [ ! -f "$cfg_file" ]; then
229
- echo "Error: Configuration file '$cfg_file' does not exist." >&2
230
- return 1
231
- fi
232
-
233
- # Get original value of include-system-site-packages
234
- local original_value=$(grep "^include-system-site-packages = " "$cfg_file" | cut -d ' ' -f 3)
235
-
236
- # Set include-system-site-packages to false
237
- sed -i "s/^include-system-site-packages = .*/include-system-site-packages = false/" "$cfg_file"
238
-
239
- # Activate the virtual environment and check if the package is installed
240
- source "$venv_path/bin/activate"
241
- if pip freeze | grep -i "^$package_name==" >/dev/null; then
242
- local package_installed=true
243
- else
244
- local package_installed=false
245
- fi
246
- deactivate
247
-
248
- # Set include-system-site-packages back to original value
249
- sed -i "s/^include-system-site-packages = .*/include-system-site-packages = $original_value/" "$cfg_file"
250
-
251
- # Return boolean of whether package exists in venv
252
- echo $package_installed
253
- }
254
-
255
- install_complete() {
256
- local result
257
-
258
- result=$(find_match opt_envs "$1" "${OPT_ENVS}")
259
- if [ $? -eq 0 ]; then
260
- echo true
261
- return 0
262
- fi
263
-
264
- env_path=$(which_env "${1}")
265
- if [ -z "$env_path" ]; then
266
- >&2 echo -e "${RED}ERROR: Failed to determine the environment path for ${NC}'${1}'"
267
- exit 1
268
- fi
269
-
270
- status_txt="${env_path}/install_status.txt"
271
- if [[ ! -f "$status_txt" ]]; then
272
- echo true
273
- # >&2 echo -e "${RED}ERROR: File not found${NC} \"$status_txt\""
274
- # exit 1
275
- # fi
276
-
277
- elif grep -q "complete:1" "$status_txt"; then
278
- echo true
279
- else
280
- echo false
281
- fi
282
-
283
- return 0
284
- }
285
-
286
- which_jobs() {
287
- local env_path proxy_dir
288
-
289
- env_path=$(which_env "${1}")
290
- proxy_dir="${env_path}/qbraid"
291
- # Temporarily only support AWS jobs
292
- if [[ ! -f "${proxy_dir}/proxy" ]]; then
293
- echo "None"
294
- elif [ -d "${proxy_dir}/botocore" ]; then
295
- echo "${proxy_dir}"
296
- else
297
- echo "None"
298
- fi
299
- }
300
-
301
- jobs_enabled() {
302
-
303
- local env_name=$1
304
- local proxydir=$(which_jobs "${env_name}")
305
-
306
- if [ "${proxydir}" = "None" ]; then
307
- echo false
308
- return 0
309
- fi
310
-
311
- local proxyfile="${proxydir}/proxy"
312
- if [[ ! -f "$proxyfile" ]]; then
313
- >&2 echo -e "${RED}ERROR: File not found${NC} \"$proxyfile\""
314
- exit 1
315
- fi
316
-
317
- local enabled=$(head -n 1 "${proxyfile}" | grep true)
318
- if [[ $enabled == *"true"* ]]; then
319
- echo true
320
- else
321
- echo false
322
- fi
323
-
324
- return 0
325
- }
326
-
327
- swap_files() {
328
-
329
- if [[ ! -f "$1" ]]; then
330
- >&2 echo -e "${RED}ERROR: File not found${NC} \"$1\""
331
- exit 1
332
- fi
333
-
334
- local TMPFILE=tmp.$$
335
- sudo mv "$1" $TMPFILE && sudo mv "$2" "$1" && sudo mv $TMPFILE "$2"
336
- }
337
-
338
- qbraid_verify() {
339
-
340
- local qbraidrc="$HOME/.qbraid/qbraidrc"
341
-
342
- if [[ ! -f "$qbraidrc" ]]; then
343
- >&2 echo -e "${RED}ERROR: File not found${NC} \"$qbraidrc\""
344
- exit 1
345
- fi
346
- }
347
-
348
- aws_configure() {
349
-
350
- local conf=$HOME/.aws/config
351
- local cred=$HOME/.aws/credentials
352
-
353
- if [[ ! -f "$conf" ]] || ! grep -q region "$conf"; then
354
- aws configure set region us-east-1
355
- fi
356
-
357
- if ! grep -q output "$conf"; then
358
- aws configure set output json
359
- fi
360
-
361
- if [[ ! -f "$cred" ]] || ! grep -q aws_access_key_id "$cred"; then
362
- aws configure set aws_access_key_id MYACCESSKEY # dummy variable
363
- fi
364
-
365
- if ! grep -q aws_secret_access_key "$cred"; then
366
- aws configure set aws_secret_access_key MYSECRETKEY # dummy variable
367
- fi
368
-
369
- }
370
-
371
- ibm_save_account() {
372
- # get jobs command (enable/disable)
373
- command=$1
374
-
375
- local qiskit_dir="$HOME/.qiskit"
376
- local qiskit_ibm="$qiskit_dir/qiskit-ibm.json"
377
- local qiskit_rc="$qiskit_dir/qiskitrc"
378
- local qbraid_rc="$HOME/.qbraid/qbraidrc"
379
-
380
- write_qiskit_ibm_json() {
381
- local url="$1"
382
- local file_path="$qiskit_ibm"
383
-
384
- local content="{
385
- \"default-ibm-quantum\": {
386
- \"channel\": \"ibm_quantum\",
387
- \"token\": \"QISKIT_IBM_TOKEN\",
388
- \"url\": \"${url}\"
389
- }
390
- }"
391
-
392
- echo "$content" > "$file_path"
393
- }
394
-
395
- write_qiskitrc() {
396
- local url="$1"
397
- local file_path="$qiskit_rc"
398
-
399
- local content="[ibmq]
400
- token = QISKIT_IBM_TOKEN
401
- url = ${url}
402
- verify = True
403
- default_provider = ibm-q/open/main"
404
-
405
- echo "$content" > "$file_path"
406
- }
407
-
408
- if [ -f "$qbraid_rc" ]; then
409
- qbraid_url=$(grep -E '^url\s*=' "$qbraid_rc" | sed -E 's/^url\s*=\s*(.*)/\1/' | sed 's/[[:space:]]*$//')
410
- else
411
- qbraid_url="https://api.qbraid.com/api"
412
- fi
413
-
414
- ibm_url="https://auth.quantum-computing.ibm.com/api"
415
- qbraid_ibm_url="${qbraid_url}/ibm-routes?route="
416
-
417
- if [ "$command" = "enable" ]; then
418
- mkdir -p "$qiskit_dir"
419
-
420
- if [ ! -f "$qiskit_rc" ]; then
421
- write_qiskitrc "$qbraid_ibm_url"
422
- else
423
- sed -i "s|${ibm_url}|${qbraid_ibm_url}|g" "$qiskit_rc"
424
- fi
425
-
426
- if [ ! -f "$qiskit_ibm" ]; then
427
- write_qiskit_ibm_json "$qbraid_ibm_url"
428
- else
429
- sed -i "s|${ibm_url}|${qbraid_ibm_url}|g" "$qiskit_ibm"
430
- fi
431
- else
432
- if [ -f "$qiskit_rc" ]; then
433
- sed -i "s|${qbraid_ibm_url}|${ibm_url}|g" "$qiskit_rc"
434
- fi
435
-
436
- if [ -f "$qiskit_ibm" ]; then
437
- sed -i "s|${qbraid_ibm_url}|${ibm_url}|g" "$qiskit_ibm"
438
- fi
439
- fi
440
- }
441
-
442
- get_provider() {
443
- aws=false
444
- ibm=false
445
- proxydir=${1}
446
- command=${2}
447
-
448
- # Temporarily disabling IBM quantum jobs
449
- # if [ -d "${proxydir}/requests" ]; then
450
- # ibm=true
451
- # ibm_save_account "$command"
452
- # fi
453
-
454
- if [ -d "${proxydir}/botocore" ]; then
455
- aws=true
456
- if [ "${command}" = "enable" ]; then
457
- aws_configure
458
- fi
459
- fi
460
-
461
- if [ "$aws" = true ] && [ "$ibm" = true ]; then
462
- echo "AWS + IBM"
463
- elif [ "$aws" = true ]; then
464
- echo "AWS"
465
- elif [ "$ibm" = true ]; then
466
- echo "IBM"
467
- else
468
- echo ""
469
- fi
470
- }
471
-
472
- toggle_proxy() {
473
-
474
- local proxydir=$1
475
- local action=$2
476
- local proxyfile="${proxydir}/proxy"
477
-
478
- if [[ ! -f "$proxyfile" ]]; then
479
- >&2 echo -e "${RED}ERROR: File not found${NC} \"$proxyfile\""
480
- exit 1
481
-
482
- else
483
- for pkgdir in `find "$proxydir" -type d`; do
484
- # Temporarily skip swap for IBM jobs
485
- if [ "$pkgdir" != "$proxydir" ] && [[ ! "$pkgdir" =~ "requests" ]]; then
486
- swapfile="${pkgdir}/swap"
487
- src=$(grep "src = " "$swapfile" | cut -b 7-)
488
- dst=$(grep "dst = " "$swapfile" | cut -b 7-)
489
-
490
- # Check if both src and dst files exist
491
- if [ ! -f "$src" ] || [ ! -f "$dst" ]; then
492
- echo -e "${RED}ERROR: Failed to enable qBraid Quantum Jobs.${NC}"
493
- echo ""
494
- echo "File '$src' or '$dst' does not exist." >&2
495
- exit 1
496
- fi
497
-
498
- swap_files "$src" "$dst"
499
- fi
500
- done
501
-
502
- if [ "${action}" = "enable" ]; then
503
- sudo sed -i 's/false/true/' "$proxyfile"
504
- elif [ "${action}" = "disable" ]; then
505
- sudo sed -i 's/true/false/' "$proxyfile"
506
- else
507
- enabled=$(head -n 1 "${proxyfile}" | grep true)
508
- if [[ $enabled == *"true"* ]]; then
509
- sudo sed -i 's/true/false/' "$proxyfile"
510
- else
511
- sudo sed -i 's/false/true/' "$proxyfile"
512
- fi
513
- fi
514
- fi
515
-
516
- }
517
-
518
- get_python_version() {
519
- local venv_path=$1
520
-
521
- # Check if the virtual environment directory exists
522
- if [ ! -d "$venv_path" ]; then
523
- echo "Error: Virtual environment path '$venv_path' does not exist." >&2
524
- return 1
525
- fi
526
-
527
- # Activate the virtual environment
528
- source "$venv_path/bin/activate"
529
-
530
- # Get Python major and minor version
531
- python_version=$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
532
-
533
- # Deactivate the virtual environment
534
- deactivate
535
-
536
- echo $python_version
537
- }
538
-
539
- update_swapfile_python() {
540
- local qbraid_dir=$1
541
- local src_version=$2
542
- local target_version=$3
543
-
544
- # Check if the qbraid directory exists
545
- if [ ! -d "$qbraid_dir" ]; then
546
- echo "Error: Directory '$qbraid_dir' does not exist." >&2
547
- return 1
548
- fi
549
-
550
- # Find and process each swap.txt file
551
- find "$qbraid_dir" -type f -name "swap" | while read swapfile; do
552
- # Check if the file contains the source version
553
- if grep -q "$src_version" "$swapfile"; then
554
- # Replace the source version with the target version
555
- sed -i "s/$src_version/$target_version/g" "$swapfile"
556
- fi
557
- done
558
- }
559
-
560
-
561
- ############################### ENVS GROUP ###############################
562
- #-------------------------------------------------------------------------
563
- # Help functions
564
-
565
- # qbraid envs -h
566
- help_envs() {
567
- echo ""
568
- echo "Group"
569
- echo " qbraid envs : Manage qBraid environments."
570
- echo ""
571
- echo "Commands"
572
- echo " list : Get list of installed qBraid environments."
573
- echo " activate : Activate qBraid environment."
574
- echo " uninstall : Uninstall qBraid environment."
575
- echo ""
576
- echo "Optional Arguments"
577
- echo " -h, --help : Show this help message and exit."
578
- echo ""
579
- }
580
-
581
- # qbraid envs list -h
582
- help_envs_list() {
583
- echo ""
584
- echo "Command"
585
- echo " qbraid envs list : Get list of installed qBraid environments."
586
- echo ""
587
- echo "Optional Arguments"
588
- echo " -h, --help : Show this help message and exit."
589
- echo ""
590
- }
591
-
592
- # qbraids envs activate -h
593
- help_envs_activate() {
594
- echo ""
595
- echo "Command"
596
- echo " qbraid envs activate [env_name] : Activate qBraid environment."
597
- echo ""
598
- echo "Positional Arguments"
599
- echo -e " env_name : Name of environment. Values from: \`qbraid envs list\`."
600
- echo ""
601
- echo "Optional Arguments"
602
- echo " -h, --help : Show this help message and exit."
603
- echo ""
604
- echo "Examples"
605
- echo " qbraid envs activate amazon_braket"
606
- echo " qbraid envs activate qbraid_sdk"
607
- echo ""
608
- }
609
-
610
- # qbraids envs uninstall -h
611
- help_envs_uninstall() {
612
- echo ""
613
- echo "Command"
614
- echo " qbraid envs uninstall [env_name] : Uninstall qBraid environment."
615
- echo ""
616
- echo "Positional Arguments"
617
- echo -e " env_name : Name of environment. Values from: \`qbraid envs list\`."
618
- echo ""
619
- echo "Optional Arguments"
620
- echo " -h, --help : Show this help message and exit."
621
- echo ""
622
- echo "Examples"
623
- echo " qbraid envs uninstall amazon_braket"
624
- echo " qbraid envs uninstall qbraid_sdk"
625
- echo ""
626
- }
627
-
628
- # qbraids envs sys-packages -h
629
- help_envs_sys_packages() {
630
- echo ""
631
- echo "Help command not available"
632
- echo ""
633
- }
634
-
635
-
636
- #-------------------------------------------------------------------------
637
- # qbraid envs commands
638
- spaces() {
639
- for (( a=0; a<(( $1 )); a++ )); do echo -n " "; done
640
- }
641
-
642
- envs() {
643
-
644
- argDepth=2
645
-
646
- # qbraid envs -h
647
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
648
- help_envs
649
-
650
- # qbraid envs
651
- elif [ -z "${1}" ]; then
652
- echo -e "${RED}ERROR: Invalid command${NC}"
653
- echo ""
654
- echo -e "Use \`qbraid envs -h\` to see available commands"
655
- exit 1
656
-
657
- # qbraid envs list
658
- elif [ "${1}" = "list" ]; then
659
- ((argDepth++))
660
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
661
- help_envs_list
662
- else
663
- echo -e "# installed environments:"
664
- echo "#"
665
-
666
- # Print the "default" environment first
667
- print_env_entry "default"
668
-
669
- # Next, loop through opt_envs
670
- for key in "${!opt_envs[@]}"; do
671
- env_name=${opt_envs[$key]}
672
- if [ "${env_name}" = "default" ]; then
673
- continue
674
- fi
675
- if [ "$(is_installed "${key}")" = true ]; then
676
- print_env_entry "${env_name}"
677
- fi
678
- done
679
-
680
- # Finally, loop through installed_envs (done in 2 steps for ordering list by opt then user envs)
681
- for key in "${!installed_envs[@]}"; do
682
- # Skip the opt_envs and "default" environment since they've already been displayed
683
- if [[ -v opt_envs[${installed_envs[$key]}] ]] || [ "${key}" = "default" ]; then
684
- continue
685
- fi
686
- print_env_entry "${key}"
687
- done
688
- echo ""
689
- fi
690
-
691
- # qbraid envs activate
692
- elif [ "${1}" = "activate" ]; then
693
- ((argDepth++))
694
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
695
- help_envs_activate
696
- else
697
- env_path=$(which_env "${2}")
698
- if [ "${env_path}" != "None" ] && [ "$(is_installed "${2}")" = true ]; then
699
- if [ "${2}" = "qsharp" ]; then
700
- echo -e "The ${LIGHTPURPLE}${2}${NC} environment uses the base \`/opt/conda/bin/python\` interpreter, so is already \"active\", by default."
701
- elif [ "$(install_complete "${2}")" != true ]; then
702
- echo -e "${RED}ERROR: Resource busy ${NC}${2}"
703
- echo ""
704
- echo -e "Cannot activate while installing. Please wait for environment to finish installing, and try again."
705
- exit 1
706
- else
707
- echo -e "${PURPLE}Activating ${LIGHTPURPLE}${2}${PURPLE} environment... ${NC}"
708
- echo -e ""
709
- echo -e "${PURPLE}Once active, use ${NC}\`deactivate\`${PURPLE} to deactivate the environment.${NC}"
710
- if [ "$(jobs_enabled "${2}")" = true ]; then
711
- echo ""
712
- echo -e "${RED}WARNING: Quantum jobs enabled for ${NC}${2}. ${RED}Executing ${NC}\`pip install\`${RED} commands with quantum jobs enabled can break environment's qBraid configuration. It is recommended to disable quantum jobs before proceeding${NC}."
713
- fi
714
- echo "${env_path}/pyenv/bin"
715
- fi
716
- else
717
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
718
- echo ""
719
- echo -e "Environment ${PURPLE}${2}${NC} is not installed. Use \`qbraid envs list\` to see installed environments."
720
- exit 1
721
- fi
722
- fi
723
-
724
- # qbraid envs uninstall
725
- elif [ "${1}" = "uninstall" ]; then
726
- ((argDepth++))
727
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
728
- help_envs_uninstall
729
- elif [ "${2}" = "default" ] || [ "${2}" = "qsharp" ] || [ "${2}" = "intel" ]; then
730
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
731
- echo ""
732
- echo -e "Environment ${2} comes pre-installed with qBraid Lab, so cannot be uninstalled."
733
- else
734
- envdir=$(which_env "${2}")
735
- if [ "${envdir}" != "None" ] && [ "$(is_installed "${2}")" = true ]; then
736
- tmpdir="${HOME}/.qbraid/environments/tmp_${2}"
737
- mv "${envdir}" "${tmpdir}"
738
- rm -rf "${tmpdir}" &
739
- echo -e "Uninstalling ${2}..."
740
- echo ""
741
- echo -e "${PURPLE}Use ${NC}\`qbraid envs list\` ${PURPLE}to see updated list of installed environments.${NC}"
742
- echo -e "${PURPLE}Click refresh button in ENVS sidebar to sync lab environment manager frontend.${NC}"
743
- else
744
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
745
- echo ""
746
- echo -e "Environment ${PURPLE}${2}${NC} is not installed. Use \`qbraid envs list\` to see installed environments."
747
- exit 1
748
- fi
749
- fi
750
-
751
- # qbraid envs sys-packages
752
- elif [ "${1}" = "sys-packages" ]; then
753
- ((argDepth++))
754
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
755
- help_envs_sys_packages
756
- elif [ "${2}" = "default" ] || [ "${2}" = "qsharp" ] || [ "${2}" = "intel" ]; then
757
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
758
- echo ""
759
- echo -e "Environment ${2} comes pre-installed with qBraid Lab, so value cannot be set."
760
- else
761
- envdir=$(which_env "${2}")
762
- if [ "${envdir}" != "None" ] && [ "$(is_installed "${2}")" = true ]; then
763
- cfg_path="${envdir}/pyenv/pyvenv.cfg"
764
- if [[ ! -f "$cfg_path" ]]; then
765
- echo "File $cfg_path not found"
766
- return 1
767
- fi
768
-
769
- local from_str
770
- local to_str
771
-
772
- if [[ "${3}" == "true" ]]; then
773
- from_str="include-system-site-packages = false"
774
- to_str="include-system-site-packages = true"
775
- else
776
- from_str="include-system-site-packages = true"
777
- to_str="include-system-site-packages = false"
778
- fi
779
-
780
- sed -i "s/$from_str/$to_str/g" "$cfg_path"
781
- else
782
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
783
- echo ""
784
- echo -e "Environment ${PURPLE}${2}${NC} is not installed. Use \`qbraid envs list\` to see installed environments."
785
- exit 1
786
- fi
787
- fi
788
-
789
- else
790
- echo -e "${RED}ERROR: Invalid argument ${NC}${1}"
791
- echo ""
792
- echo -e "Use \`qbraid envs -h\` to see available commands"
793
- exit 1
794
- fi
795
- }
796
-
797
-
798
- ############################### KERNELS GROUP ############################
799
- #-------------------------------------------------------------------------
800
- # Help functions
801
-
802
- # qbraid kernels -h
803
- help_kernels() {
804
- echo ""
805
- echo "Group"
806
- echo " qbraid kernels : Manage qBraid kernel specifications."
807
- echo ""
808
- echo "Commands"
809
- echo " list : List installed qBraid kernel specifications."
810
- echo " install : Install a kernel specification directory."
811
- echo " uninstall : Alias for remove"
812
- echo " remove : Remove one or more qBraid kernelspecs by name."
813
- echo ""
814
- echo "Optional Arguments"
815
- echo " -h, --help : Show this help message and exit."
816
- echo ""
817
- }
818
-
819
- #-------------------------------------------------------------------------
820
- # qbraid kernels commands
821
-
822
- kernels() {
823
- argDepth=2
824
-
825
- # qbraid kernels -h
826
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
827
- help_kernels
828
-
829
- # qbraid kernels
830
- elif [ -z "${1}" ]; then
831
- echo -e "${RED}ERROR: Invalid command ${NC}"
832
- echo ""
833
- echo -e "Use \`qbraid kernels -h\` to see available commands"
834
- exit 1
835
- else
836
- jupyter kernelspec "${@:1}"
837
- fi
838
- }
839
-
840
- ############################### JOBS GROUP ###############################
841
- #-------------------------------------------------------------------------
842
- # Help functions
843
-
844
- # qbraid jobs -h
845
- help_jobs() {
846
- echo ""
847
- echo "Group"
848
- echo " qbraid jobs : Manage qBraid Quantum Jobs."
849
- echo ""
850
- echo "Commands"
851
- echo " list : Get list of qBraid Quantum Jobs."
852
- echo " add : Add qBraid Quantum Jobs to environment."
853
- echo " enable : Enable qBraid Quantum Jobs."
854
- echo " disable : Disable qBraid Quantum Jobs."
855
- echo ""
856
- echo "Optional Arguments"
857
- echo " -h, --help : Show this help message and exit."
858
- echo ""
859
- }
860
-
861
- # qbraid jobs list -h
862
- help_jobs_list() {
863
- echo ""
864
- echo "Command"
865
- echo " qbraid jobs list : Get list of qBraid Quantum Jobs."
866
- echo ""
867
- echo "Optional Arguments"
868
- echo " -h, --help : Show this help message and exit."
869
- echo ""
870
- }
871
-
872
- # qbraid jobs add -h
873
- help_jobs_add() {
874
- echo ""
875
- echo "Command"
876
- echo " qbraid jobs add [env_name] : Add qBraid AWS Quantum Jobs support for environment."
877
- echo ""
878
- echo "Positional Arguments"
879
- echo -e " env_name : Name of environment. Values from: \`qbraid envs list\`."
880
- echo ""
881
- echo "Optional Arguments"
882
- echo " -h, --help : Show this help message and exit."
883
- echo ""
884
- echo "Examples"
885
- echo " qbraid jobs add custom_braket_env"
886
- echo ""
887
- }
888
-
889
- # qbraids jobs enable -h
890
- help_jobs_enable() {
891
- echo ""
892
- echo "Command"
893
- echo " qbraid jobs enable [env_name] : Disable qBraid Quantum Jobs."
894
- echo ""
895
- echo "Positional Arguments"
896
- echo -e " env_name : Name of environment. Values from: \`qbraid envs list\`."
897
- echo ""
898
- echo "Optional Arguments"
899
- echo " -h, --help : Show this help message and exit."
900
- echo ""
901
- echo "Examples"
902
- echo " qbraid jobs enable amazon_braket"
903
- echo " qbraid jobs enable qbraid_sdk"
904
- echo ""
905
- }
906
-
907
- # qbraid jobs disable -h
908
- help_jobs_disable() {
909
- echo ""
910
- echo "Command"
911
- echo " qbraid jobs disable [env_name] : Disable qBraid Quantum Jobs."
912
- echo ""
913
- echo "Positional Arguments"
914
- echo -e " env_name : Name of environment. Values from: \`qbraid envs list\`."
915
- echo ""
916
- echo "Optional Arguments"
917
- echo " -h, --help : Show this help message and exit."
918
- echo ""
919
- echo "Examples"
920
- echo " qbraid jobs disable amazon_braket"
921
- echo " qbraid jobs disable qbraid_sdk"
922
- echo ""
923
- }
924
-
925
- #-------------------------------------------------------------------------
926
- # qbraid jobs commands
927
-
928
- jobs() {
929
-
930
- argDepth=2
931
-
932
- # qbraid jobs -h
933
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
934
- help_jobs
935
-
936
- # qbraid jobs
937
- elif [ -z "${1}" ]; then
938
- echo -e "${RED}ERROR: Invalid command ${NC}"
939
- echo ""
940
- echo -e "Use \`qbraid jobs -h\` to see available commands"
941
- exit 1
942
-
943
- # qbraid jobs list
944
- elif [ "${1}" = "list" ]; then
945
- ((argDepth++))
946
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
947
- help_jobs_list
948
- fi
949
-
950
- # qbraid jobs add
951
- elif [ "${1}" = "add" ]; then
952
- ((argDepth++))
953
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
954
- help_jobs_add
955
- else
956
- if [ "$(is_installed "${2}")" = true ]; then
957
- proxydir=$(which_jobs "${2}")
958
- if [ ${proxydir} = "None" ]; then
959
- package="amazon-braket-sdk"
960
- if [ "$(has_package "${2}" "${package}")" = true ]; then
961
- env_default=$(which_env "default")
962
- enabled=$(head -n 1 "${env_default}/qbraid/proxy" | grep true)
963
- if [[ $enabled == *"true"* ]]; then
964
- echo -e "${RED}ERROR: Resources unavailable${NC}"
965
- echo ""
966
- echo -e "Quantum jobs must be disabled in the ${PURPLE}default${NC} environment to complete operation."
967
- echo -e "Run ${NC} \`qbraid jobs disable default\`, and try again."
968
- exit 1
969
- else
970
- envdir=$(which_env "${2}")
971
- proxy_dir="${envdir}/qbraid"
972
- mkdir ${proxy_dir}
973
- slug=${envdir##*/}
974
- braketswap="${envdir}/qbraid/amazon-braket-sdk/swap"
975
- botoswap="${envdir}/qbraid/botocore/swap"
976
- cp -r ${env_default}/qbraid/* ${proxy_dir}
977
- sed -i "s_opt_home/jovyan_" "${braketswap}"
978
- sed -i "s/qbraid_000000/${slug}/" "${braketswap}"
979
- sed -i "s_opt_home/jovyan_" "${botoswap}"
980
- sed -i "s/qbraid_000000/${slug}/" "${botoswap}"
981
-
982
- default_python=$(get_python_version "${env_default}/pyenv")
983
- target_python=$(get_python_version "${envdir}/pyenv")
984
- update_swapfile_python "${envdir}/qbraid" "${default_python}" "${target_python}"
985
-
986
- echo -e "${PURPLE}Success! Your ${LIGHTPURPLE}${2}${NC}${PURPLE} environment now supports qBraid (AWS) Quantum Jobs${NC}."
987
- echo ""
988
- echo -e "${PURPLE}To enable Quantum Jobs, run:${NC} \`qbraid jobs enable ${2}\`"
989
- fi
990
- else
991
- echo -e "${RED}ERROR: Package(s) not found: ${NC}${package}"
992
- echo ""
993
- echo -e "Environment ${PURPLE}${2}${NC} must have '${package}' installed before qBraid Quantum Jobs can be added."
994
- exit 1
995
- fi
996
- else
997
- echo -e "${PURPLE}Your ${LIGHTPURPLE}${2}${NC}${PURPLE} environment already supports qBraid (AWS) Quantum Jobs${NC}!"
998
- fi
999
- else
1000
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
1001
- echo ""
1002
- echo -e "Environment ${PURPLE}${2}${NC} is not installed. Use \`qbraid envs list\` to see installed environments."
1003
- exit 1
1004
- fi
1005
- fi
1006
-
1007
- # qbraid jobs enable
1008
- elif [ "${1}" = "enable" ]; then
1009
- ((argDepth++))
1010
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1011
- help_jobs_enable
1012
- else
1013
- if [ "$(is_installed "${2}")" = true ]; then
1014
- if [ "$(install_complete "${2}")" != true ]; then
1015
- echo -e "${RED}ERROR: Resource busy ${NC}${2}"
1016
- echo ""
1017
- echo -e "Cannot enable quantum jobs while installing. Please wait for environment to finish installing, and try again."
1018
- exit 1
1019
- fi
1020
- proxydir=$(which_jobs "${2}")
1021
- if [ ! ${proxydir} = "None" ]; then
1022
- qbraid_verify
1023
- provider=$(get_provider "${proxydir}" "${1}")
1024
- proxyfile="$proxydir/proxy"
1025
- enabled=$(head -n 1 "${proxyfile}" | grep true)
1026
- if [[ $enabled == *"true"* ]]; then
1027
- echo -e "${PURPLE}You have already enabled qBraid Quantum Jobs in the ${2} environment.${NC}"
1028
- else
1029
- toggle_proxy "${proxydir}" "${1}"
1030
- enabled=$(head -n 1 "${proxyfile}" | grep true)
1031
- if [[ $enabled == *"true"* ]]; then
1032
- echo -e "${PURPLE}Successfully enabled qBraid Quantum Jobs in the ${LIGHTPURPLE}${2}${NC}${PURPLE} environment.${NC}"
1033
- echo -e "${PURPLE}Every ${LIGHTPURPLE}${provider}${NC}${PURPLE} job you run will now be submitted through the qBraid API, so no access keys/tokens are necessary. ${NC}"
1034
- echo ""
1035
- echo -e "${PURPLE}To disable, run:${NC} \`qbraid jobs disable ${2}\`"
1036
- else
1037
- echo -e "${RED}ERROR: Failed to enable qBraid Quantum Jobs.${NC}"
1038
- exit 1
1039
- fi
1040
- fi
1041
- else
1042
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
1043
- echo ""
1044
- echo -e "qBraid Quantum Jobs not configured for ${PURPLE}${2}${NC} environment."
1045
- exit 1
1046
- fi
1047
- else
1048
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
1049
- echo ""
1050
- echo -e "Environment ${PURPLE}${2}${NC} is not installed. Use \`qbraid envs list\` to see installed environments."
1051
- exit 1
1052
- fi
1053
- fi
1054
-
1055
- # qbraid jobs disable
1056
- elif [ "${1}" = "disable" ]; then
1057
- ((argDepth++))
1058
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1059
- help_jobs_disable
1060
- else
1061
- if [ "$(is_installed "${2}")" = true ]; then
1062
- proxydir=$(which_jobs "${2}")
1063
- if [ ! ${proxydir} = "None" ]; then
1064
- provider=$(get_provider "${proxydir}" "${1}")
1065
- proxyfile="$proxydir/proxy"
1066
- enabled=$(head -n 1 "${proxyfile}" | grep false)
1067
- if [[ $enabled == *"false"* ]]; then
1068
- echo -e "${PURPLE} You have already disabled qBraid Quantum Jobs in the ${LIGHTPURPLE}${2}${NC}${PURPLE} environment.${NC}"
1069
- else
1070
- toggle_proxy "${proxydir}" "${1}"
1071
- executed=$(head -n 1 "${proxyfile}" | grep false)
1072
- if [[ $executed == *"false"* ]]; then
1073
- echo -e "${PURPLE}Disable successful. You are now submitting quantum jobs with your own $provider credentials.${NC}"
1074
- echo ""
1075
- echo -e "${PURPLE}To re-enable, run:${NC} \`qbraid jobs enable ${2}\`"
1076
- else
1077
- echo -e "${RED}ERROR: Failed to disable qBraid Quantum Jobs. ${NC}"
1078
- exit 1
1079
- fi
1080
- fi
1081
- else
1082
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
1083
- echo ""
1084
- echo -e "qBraid Quantum Jobs not configured for ${PURPLE}${2}${NC} environment."
1085
- exit 1
1086
- fi
1087
- else
1088
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
1089
- echo ""
1090
- echo -e "Environment ${PURPLE}${2}${NC} is not installed. Use \`qbraid envs list\` to see installed environments."
1091
- exit 1
1092
- fi
1093
- fi
1094
-
1095
- # qbraid jobs get-credits
1096
- elif [ "${1}" = "get-credits" ]; then
1097
- ((argDepth++))
1098
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1099
- help_jobs_credits
1100
- else
1101
- creditsFile="$HOME/.qbraid/qBraidCredits";
1102
- if [ ! -f "${creditsFile}" ]; then
1103
- echo -e "${RED}ERROR: Number of qBraid credits could not be determined. ${NC}"
1104
- exit 1
1105
- else
1106
- # Read number from the file
1107
- credits=$(head -n 1 "${creditsFile}")
1108
-
1109
- # Round the number to two decimal places
1110
- rounded_credits=$(printf "%.2f\n" "$credits")
1111
-
1112
- echo -e "${PURPLE}You have ${NC}$rounded_credits${PURPLE} remaining qBraid credits.${NC}"
1113
- fi
1114
- fi
1115
-
1116
- else
1117
- echo -e "${RED}ERROR: Invalid argument ${NC}${1}"
1118
- echo ""
1119
- echo -e "Use \`qbraid jobs -h\` to see available commands"
1120
- exit 1
1121
-
1122
- fi
1123
- }
1124
-
1125
- ############################### DEVICES GROUP ###############################
1126
- #-------------------------------------------------------------------------
1127
- # Help functions
1128
-
1129
- # qbraid devices -h
1130
- help_devices() {
1131
- echo ""
1132
- echo "Group"
1133
- echo " qbraid devices : Manage qBraid Quantum Devices."
1134
- echo ""
1135
- echo "Commands"
1136
- echo " list : Get list of qBraid Quantum Devices."
1137
- echo ""
1138
- echo "Optional Arguments"
1139
- echo " -h, --help : Show this help message and exit."
1140
- echo ""
1141
- }
1142
-
1143
- # qbraid devices list -h
1144
- help_devices_list() {
1145
- echo ""
1146
- echo "Command"
1147
- echo " qbraid devices list : Get list of qBraid Quantum Jobs."
1148
- echo ""
1149
- echo "Optional Arguments"
1150
- echo " -h, --help : Show this help message and exit."
1151
- echo ""
1152
- }
1153
-
1154
- #-------------------------------------------------------------------------
1155
- # qbraid devices commands
1156
-
1157
- devices() {
1158
-
1159
- argDepth=2
1160
-
1161
- # qbraid jobs -h
1162
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1163
- help_devices
1164
-
1165
- # qbraid jobs
1166
- elif [ -z "${1}" ]; then
1167
- echo -e "${RED}ERROR: Invalid command ${NC}"
1168
- echo ""
1169
- echo -e "Use \`qbraid devices -h\` to see available commands"
1170
- exit 1
1171
-
1172
- # qbraid devices list
1173
- elif [ "${1}" = "list" ]; then
1174
- ((argDepth++))
1175
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1176
- help_devices_list
1177
- fi
1178
- else
1179
- echo -e "${RED}ERROR: Invalid argument ${NC}${1}"
1180
- echo ""
1181
- echo -e "Use \`qbraid devices -h\` to see available commands"
1182
- exit 1
1183
- fi
1184
- }
1185
-
1186
- ############################### CLI ENTRYPOINT ###########################
1187
- #-------------------------------------------------------------------------
1188
- # Help functions
1189
-
1190
- # qbraid -h
1191
- help() {
1192
- echo ""
1193
- echo "Group"
1194
- echo " qbraid"
1195
- echo ""
1196
- echo "Commands"
1197
- echo " credits : Get number of qBraid credits remaining."
1198
- echo " configure : Update or add qbraidrc config values."
1199
- echo " configure set : Update single qbraidrc config value."
1200
- echo ""
1201
- echo "Subgroups"
1202
- echo " envs : Manage qBraid environments."
1203
- echo " kernels : Manage qBraid kernels."
1204
- echo " jobs : Manage qBraid Quantum Jobs."
1205
- echo " devices : Manage qBraid Quantum Devices."
1206
- echo ""
1207
- echo "Arguments"
1208
- echo " -V, --version : Show version and exit"
1209
- echo ""
1210
- echo "Global Arguments"
1211
- echo " -h, --help : Show this help message and exit."
1212
- echo ""
1213
- echo "Reference Docs: https://docs.qbraid.com/projects/cli/en/latest/cli/qbraid.html"
1214
- }
1215
-
1216
- # qbraid configure -h
1217
- help_configure() {
1218
- echo ""
1219
- echo "Command"
1220
- echo " qbraid configure : Update or add qbraidrc config values."
1221
- echo ""
1222
- echo "Optional Arguments"
1223
- echo " -h, --help : Show this help message and exit."
1224
- echo ""
1225
- echo "Examples"
1226
- echo " $ qbraid configure"
1227
- echo " email [None]: contact@qbraid.com"
1228
- echo " api-key [None]: 1234567890"
1229
- echo ""
1230
- }
1231
-
1232
- # qbraid configure set -h
1233
- help_configure_set() {
1234
- echo ""
1235
- echo "Command"
1236
- echo " qbraid configure set [key] [value] : Update qbraidrc config value."
1237
- echo ""
1238
- echo "Optional Arguments"
1239
- echo " -h, --help : Show this help message and exit."
1240
- echo ""
1241
- echo "Examples"
1242
- echo " $ qbraid configure set email contact@qbraid.com"
1243
- echo ""
1244
- }
1245
-
1246
- # qbraid credits -h
1247
- help_credits() {
1248
- echo ""
1249
- echo "Command"
1250
- echo " qbraid credits : Get number of qBraid credits remaining."
1251
- echo ""
1252
- echo "Optional Arguments"
1253
- echo " -h, --help : Show this help message and exit."
1254
- echo ""
1255
- }
1256
-
1257
- #-------------------------------------------------------------------------
1258
- # command parser / dispatch
1259
-
1260
- qbraid() {
1261
-
1262
- argDepth=1
1263
-
1264
- # qbraid -h
1265
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1266
- help
1267
-
1268
- # qbraid
1269
- elif [ -z "${1}" ]; then
1270
- echo -e "---------------------------------"
1271
- echo -e " * ${PURPLE}Welcome to the qBraid CLI!${NC} * "
1272
- echo -e "---------------------------------"
1273
- echo -e ""
1274
- echo -e " ____ _ _ "
1275
- echo -e " __ _| __ ) _ __ __ _(_) __| | "
1276
- echo -e " / _ | _ \| __/ _ | |/ _ | "
1277
- echo -e " | (_| | |_) | | | (_| | | (_| | "
1278
- echo -e " \__ |____/|_| \__ _|_|\__ _| "
1279
- echo -e " |_| "
1280
- echo -e ""
1281
- echo -e ""
1282
- echo -e "- Use \`qbraid -h\` to see available commands."
1283
- echo -e ""
1284
- echo -e "- Use \`qbraid --version\` to display the current version."
1285
- echo -e ""
1286
- echo -e "Reference Docs: https://docs.qbraid.com/projects/cli/en/latest/cli/qbraid.html"
1287
-
1288
- # qbraid configure
1289
- elif [ "${1}" = "configure" ]; then
1290
- ((argDepth++))
1291
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1292
- help_configure
1293
- elif [ "${2}" = "set" ]; then
1294
- ((argDepth++))
1295
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1296
- help_configure_set
1297
- else
1298
- echo -e "${RED}ERROR: Invalid command ${NC}"
1299
- echo ""
1300
- echo -e "Use \`qbraid configure set -h\` to see available commands"
1301
- exit 1
1302
- fi
1303
- else
1304
- echo -e "${RED}ERROR: Invalid command ${NC}"
1305
- echo ""
1306
- echo -e "Use \`qbraid -h\` to see available commands"
1307
- exit 1
1308
- fi
1309
-
1310
- # qbraid credits
1311
- elif [ "${1}" = "credits" ]; then
1312
- ((argDepth++))
1313
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1314
- help_credits
1315
- fi
1316
-
1317
- # qbraid envs
1318
- elif [ "${1}" = "envs" ]; then
1319
- envs "${@:2}"
1320
-
1321
- # qbraid kernels
1322
- elif [ "${1}" = "kernels" ]; then
1323
- kernels "${@:2}"
1324
-
1325
- # qbraid jobs
1326
- elif [ "${1}" = "jobs" ]; then
1327
- jobs "${@:2}"
1328
-
1329
- # qbraid devices
1330
- elif [ "${1}" = "devices" ]; then
1331
- devices "${@:2}"
1332
-
1333
- else
1334
- echo -e "${RED}ERROR: Invalid argument ${NC}${1}"
1335
- echo ""
1336
- echo -e "Use \`qbraid -h\` to see available commands"
1337
- exit 1
1338
- fi
1339
-
1340
- }
1341
-
1342
-
1343
- #-------------------------------------------------------------------------
1344
- # run command
1345
-
1346
- qbraid "$@"