qbraid-cli 0.7.0__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 (39) hide show
  1. qbraid_cli/_version.py +14 -5
  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 +24 -0
  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.8.0.dist-info/METADATA +143 -0
  29. qbraid_cli-0.8.0.dist-info/RECORD +33 -0
  30. {qbraid_cli-0.7.0.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/bin/qbraid.sh +0 -1317
  33. qbraid_cli/configure.py +0 -87
  34. qbraid_cli/wrapper.py +0 -91
  35. qbraid_cli-0.7.0.data/scripts/qbraid.sh +0 -1317
  36. qbraid_cli-0.7.0.dist-info/METADATA +0 -118
  37. qbraid_cli-0.7.0.dist-info/RECORD +0 -11
  38. qbraid_cli-0.7.0.dist-info/entry_points.txt +0 -2
  39. {qbraid_cli-0.7.0.dist-info → qbraid_cli-0.8.0.dist-info}/top_level.txt +0 -0
qbraid_cli/bin/qbraid.sh DELETED
@@ -1,1317 +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 " get-credits : Get number of qBraid credits remaining."
853
- echo " add : Add qBraid Quantum Jobs to environment."
854
- echo " enable : Enable qBraid Quantum Jobs."
855
- echo " disable : Disable qBraid Quantum Jobs."
856
- echo ""
857
- echo "Optional Arguments"
858
- echo " -h, --help : Show this help message and exit."
859
- echo ""
860
- }
861
-
862
- # qbraid jobs list -h
863
- help_jobs_list() {
864
- echo ""
865
- echo "Command"
866
- echo " qbraid jobs list : Get list of qBraid Quantum Jobs."
867
- echo ""
868
- echo "Optional Arguments"
869
- echo " -h, --help : Show this help message and exit."
870
- echo ""
871
- }
872
-
873
- # qbraid jobs add -h
874
- help_jobs_add() {
875
- echo ""
876
- echo "Command"
877
- echo " qbraid jobs add [env_name] : Add qBraid AWS Quantum Jobs support for environment."
878
- echo ""
879
- echo "Positional Arguments"
880
- echo -e " env_name : Name of environment. Values from: \`qbraid envs list\`."
881
- echo ""
882
- echo "Optional Arguments"
883
- echo " -h, --help : Show this help message and exit."
884
- echo ""
885
- echo "Examples"
886
- echo " qbraid jobs add custom_braket_env"
887
- echo ""
888
- }
889
-
890
- # qbraids jobs enable -h
891
- help_jobs_enable() {
892
- echo ""
893
- echo "Command"
894
- echo " qbraid jobs enable [env_name] : Disable qBraid Quantum Jobs."
895
- echo ""
896
- echo "Positional Arguments"
897
- echo -e " env_name : Name of environment. Values from: \`qbraid envs list\`."
898
- echo ""
899
- echo "Optional Arguments"
900
- echo " -h, --help : Show this help message and exit."
901
- echo ""
902
- echo "Examples"
903
- echo " qbraid jobs enable amazon_braket"
904
- echo " qbraid jobs enable qbraid_sdk"
905
- echo ""
906
- }
907
-
908
- # qbraid jobs disable -h
909
- help_jobs_disable() {
910
- echo ""
911
- echo "Command"
912
- echo " qbraid jobs disable [env_name] : Disable qBraid Quantum Jobs."
913
- echo ""
914
- echo "Positional Arguments"
915
- echo -e " env_name : Name of environment. Values from: \`qbraid envs list\`."
916
- echo ""
917
- echo "Optional Arguments"
918
- echo " -h, --help : Show this help message and exit."
919
- echo ""
920
- echo "Examples"
921
- echo " qbraid jobs disable amazon_braket"
922
- echo " qbraid jobs disable qbraid_sdk"
923
- echo ""
924
- }
925
-
926
- #-------------------------------------------------------------------------
927
- # qbraid jobs commands
928
-
929
- jobs() {
930
-
931
- argDepth=2
932
-
933
- # qbraid jobs -h
934
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
935
- help_jobs
936
-
937
- # qbraid jobs
938
- elif [ -z "${1}" ]; then
939
- echo -e "${RED}ERROR: Invalid command ${NC}"
940
- echo ""
941
- echo -e "Use \`qbraid jobs -h\` to see available commands"
942
- exit 1
943
-
944
- # qbraid jobs list
945
- elif [ "${1}" = "list" ]; then
946
- ((argDepth++))
947
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
948
- help_jobs_list
949
- fi
950
-
951
- # qbraid jobs add
952
- elif [ "${1}" = "add" ]; then
953
- ((argDepth++))
954
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
955
- help_jobs_add
956
- else
957
- if [ "$(is_installed "${2}")" = true ]; then
958
- proxydir=$(which_jobs "${2}")
959
- if [ ${proxydir} = "None" ]; then
960
- package="amazon-braket-sdk"
961
- if [ "$(has_package "${2}" "${package}")" = true ]; then
962
- env_default=$(which_env "default")
963
- enabled=$(head -n 1 "${env_default}/qbraid/proxy" | grep true)
964
- if [[ $enabled == *"true"* ]]; then
965
- echo -e "${RED}ERROR: Resources unavailable${NC}"
966
- echo ""
967
- echo -e "Quantum jobs must be disabled in the ${PURPLE}default${NC} environment to complete operation."
968
- echo -e "Run ${NC} \`qbraid jobs disable default\`, and try again."
969
- exit 1
970
- else
971
- envdir=$(which_env "${2}")
972
- proxy_dir="${envdir}/qbraid"
973
- mkdir ${proxy_dir}
974
- slug=${envdir##*/}
975
- braketswap="${envdir}/qbraid/amazon-braket-sdk/swap"
976
- botoswap="${envdir}/qbraid/botocore/swap"
977
- cp -r ${env_default}/qbraid/* ${proxy_dir}
978
- sed -i "s_opt_home/jovyan_" "${braketswap}"
979
- sed -i "s/qbraid_000000/${slug}/" "${braketswap}"
980
- sed -i "s_opt_home/jovyan_" "${botoswap}"
981
- sed -i "s/qbraid_000000/${slug}/" "${botoswap}"
982
-
983
- default_python=$(get_python_version "${env_default}/pyenv")
984
- target_python=$(get_python_version "${envdir}/pyenv")
985
- update_swapfile_python "${envdir}/qbraid" "${default_python}" "${target_python}"
986
-
987
- echo -e "${PURPLE}Success! Your ${LIGHTPURPLE}${2}${NC}${PURPLE} environment now supports qBraid (AWS) Quantum Jobs${NC}."
988
- echo ""
989
- echo -e "${PURPLE}To enable Quantum Jobs, run:${NC} \`qbraid jobs enable ${2}\`"
990
- fi
991
- else
992
- echo -e "${RED}ERROR: Package(s) not found: ${NC}${package}"
993
- echo ""
994
- echo -e "Environment ${PURPLE}${2}${NC} must have '${package}' installed before qBraid Quantum Jobs can be added."
995
- exit 1
996
- fi
997
- else
998
- echo -e "${PURPLE}Your ${LIGHTPURPLE}${2}${NC}${PURPLE} environment already supports qBraid (AWS) Quantum Jobs${NC}!"
999
- fi
1000
- else
1001
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
1002
- echo ""
1003
- echo -e "Environment ${PURPLE}${2}${NC} is not installed. Use \`qbraid envs list\` to see installed environments."
1004
- exit 1
1005
- fi
1006
- fi
1007
-
1008
- # qbraid jobs enable
1009
- elif [ "${1}" = "enable" ]; then
1010
- ((argDepth++))
1011
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1012
- help_jobs_enable
1013
- else
1014
- if [ "$(is_installed "${2}")" = true ]; then
1015
- if [ "$(install_complete "${2}")" != true ]; then
1016
- echo -e "${RED}ERROR: Resource busy ${NC}${2}"
1017
- echo ""
1018
- echo -e "Cannot enable quantum jobs while installing. Please wait for environment to finish installing, and try again."
1019
- exit 1
1020
- fi
1021
- proxydir=$(which_jobs "${2}")
1022
- if [ ! ${proxydir} = "None" ]; then
1023
- qbraid_verify
1024
- provider=$(get_provider "${proxydir}" "${1}")
1025
- proxyfile="$proxydir/proxy"
1026
- enabled=$(head -n 1 "${proxyfile}" | grep true)
1027
- if [[ $enabled == *"true"* ]]; then
1028
- echo -e "${PURPLE}You have already enabled qBraid Quantum Jobs in the ${2} environment.${NC}"
1029
- else
1030
- toggle_proxy "${proxydir}" "${1}"
1031
- enabled=$(head -n 1 "${proxyfile}" | grep true)
1032
- if [[ $enabled == *"true"* ]]; then
1033
- echo -e "${PURPLE}Successfully enabled qBraid Quantum Jobs in the ${LIGHTPURPLE}${2}${NC}${PURPLE} environment.${NC}"
1034
- 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}"
1035
- echo ""
1036
- echo -e "${PURPLE}To disable, run:${NC} \`qbraid jobs disable ${2}\`"
1037
- else
1038
- echo -e "${RED}ERROR: Failed to enable qBraid Quantum Jobs.${NC}"
1039
- exit 1
1040
- fi
1041
- fi
1042
- else
1043
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
1044
- echo ""
1045
- echo -e "qBraid Quantum Jobs not configured for ${PURPLE}${2}${NC} environment."
1046
- exit 1
1047
- fi
1048
- else
1049
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
1050
- echo ""
1051
- echo -e "Environment ${PURPLE}${2}${NC} is not installed. Use \`qbraid envs list\` to see installed environments."
1052
- exit 1
1053
- fi
1054
- fi
1055
-
1056
- # qbraid jobs disable
1057
- elif [ "${1}" = "disable" ]; then
1058
- ((argDepth++))
1059
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1060
- help_jobs_disable
1061
- else
1062
- if [ "$(is_installed "${2}")" = true ]; then
1063
- proxydir=$(which_jobs "${2}")
1064
- if [ ! ${proxydir} = "None" ]; then
1065
- provider=$(get_provider "${proxydir}" "${1}")
1066
- proxyfile="$proxydir/proxy"
1067
- enabled=$(head -n 1 "${proxyfile}" | grep false)
1068
- if [[ $enabled == *"false"* ]]; then
1069
- echo -e "${PURPLE} You have already disabled qBraid Quantum Jobs in the ${LIGHTPURPLE}${2}${NC}${PURPLE} environment.${NC}"
1070
- else
1071
- toggle_proxy "${proxydir}" "${1}"
1072
- executed=$(head -n 1 "${proxyfile}" | grep false)
1073
- if [[ $executed == *"false"* ]]; then
1074
- echo -e "${PURPLE}Disable successful. You are now submitting quantum jobs with your own $provider credentials.${NC}"
1075
- echo ""
1076
- echo -e "${PURPLE}To re-enable, run:${NC} \`qbraid jobs enable ${2}\`"
1077
- else
1078
- echo -e "${RED}ERROR: Failed to disable qBraid Quantum Jobs. ${NC}"
1079
- exit 1
1080
- fi
1081
- fi
1082
- else
1083
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
1084
- echo ""
1085
- echo -e "qBraid Quantum Jobs not configured for ${PURPLE}${2}${NC} environment."
1086
- exit 1
1087
- fi
1088
- else
1089
- echo -e "${RED}ERROR: Invalid argument ${NC}${2}"
1090
- echo ""
1091
- echo -e "Environment ${PURPLE}${2}${NC} is not installed. Use \`qbraid envs list\` to see installed environments."
1092
- exit 1
1093
- fi
1094
- fi
1095
-
1096
- # qbraid jobs get-credits
1097
- elif [ "${1}" = "get-credits" ]; then
1098
- ((argDepth++))
1099
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1100
- help_jobs_credits
1101
- else
1102
- creditsFile="$HOME/.qbraid/qBraidCredits";
1103
- if [ ! -f "${creditsFile}" ]; then
1104
- echo -e "${RED}ERROR: Number of qBraid credits could not be determined. ${NC}"
1105
- exit 1
1106
- else
1107
- # Read number from the file
1108
- credits=$(head -n 1 "${creditsFile}")
1109
-
1110
- # Round the number to two decimal places
1111
- rounded_credits=$(printf "%.2f\n" "$credits")
1112
-
1113
- echo -e "${PURPLE}You have ${NC}$rounded_credits${PURPLE} remaining qBraid credits.${NC}"
1114
- fi
1115
- fi
1116
-
1117
- else
1118
- echo -e "${RED}ERROR: Invalid argument ${NC}${1}"
1119
- echo ""
1120
- echo -e "Use \`qbraid jobs -h\` to see available commands"
1121
- exit 1
1122
-
1123
- fi
1124
- }
1125
-
1126
- ############################### DEVICES GROUP ###############################
1127
- #-------------------------------------------------------------------------
1128
- # Help functions
1129
-
1130
- # qbraid devices -h
1131
- help_devices() {
1132
- echo ""
1133
- echo "Group"
1134
- echo " qbraid devices : Manage qBraid Quantum Devices."
1135
- echo ""
1136
- echo "Commands"
1137
- echo " list : Get list of qBraid Quantum Devices."
1138
- echo ""
1139
- echo "Optional Arguments"
1140
- echo " -h, --help : Show this help message and exit."
1141
- echo ""
1142
- }
1143
-
1144
- # qbraid devices list -h
1145
- help_devices_list() {
1146
- echo ""
1147
- echo "Command"
1148
- echo " qbraid devices list : Get list of qBraid Quantum Jobs."
1149
- echo ""
1150
- echo "Optional Arguments"
1151
- echo " -h, --help : Show this help message and exit."
1152
- echo ""
1153
- }
1154
-
1155
- #-------------------------------------------------------------------------
1156
- # qbraid devices commands
1157
-
1158
- devices() {
1159
-
1160
- argDepth=2
1161
-
1162
- # qbraid jobs -h
1163
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1164
- help_devices
1165
-
1166
- # qbraid jobs
1167
- elif [ -z "${1}" ]; then
1168
- echo -e "${RED}ERROR: Invalid command ${NC}"
1169
- echo ""
1170
- echo -e "Use \`qbraid devices -h\` to see available commands"
1171
- exit 1
1172
-
1173
- # qbraid devices list
1174
- elif [ "${1}" = "list" ]; then
1175
- ((argDepth++))
1176
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1177
- help_devices_list
1178
- fi
1179
- else
1180
- echo -e "${RED}ERROR: Invalid argument ${NC}${1}"
1181
- echo ""
1182
- echo -e "Use \`qbraid devices -h\` to see available commands"
1183
- exit 1
1184
- fi
1185
- }
1186
-
1187
- ############################### CLI ENTRYPOINT ###########################
1188
- #-------------------------------------------------------------------------
1189
- # Help functions
1190
-
1191
- # qbraid -h
1192
- help() {
1193
- echo ""
1194
- echo "Group"
1195
- echo " qbraid"
1196
- echo ""
1197
- echo "Commands"
1198
- echo " configure : Update or add qbraidrc config values."
1199
- echo " credits : Get number of qBraid credits remaining."
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 credits -h
1233
- help_credits() {
1234
- echo ""
1235
- echo "Command"
1236
- echo " qbraid credits : Get number of qBraid credits remaining."
1237
- echo ""
1238
- echo "Optional Arguments"
1239
- echo " -h, --help : Show this help message and exit."
1240
- echo ""
1241
- }
1242
-
1243
- #-------------------------------------------------------------------------
1244
- # command parser / dispatch
1245
-
1246
- qbraid() {
1247
-
1248
- argDepth=1
1249
-
1250
- # qbraid -h
1251
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1252
- help
1253
-
1254
- # qbraid
1255
- elif [ -z "${1}" ]; then
1256
- echo -e "---------------------------------"
1257
- echo -e " * ${PURPLE}Welcome to the qBraid CLI!${NC} * "
1258
- echo -e "---------------------------------"
1259
- echo -e ""
1260
- echo -e " ____ _ _ "
1261
- echo -e " __ _| __ ) _ __ __ _(_) __| | "
1262
- echo -e " / _ | _ \| __/ _ | |/ _ | "
1263
- echo -e " | (_| | |_) | | | (_| | | (_| | "
1264
- echo -e " \__ |____/|_| \__ _|_|\__ _| "
1265
- echo -e " |_| "
1266
- echo -e ""
1267
- echo -e ""
1268
- echo -e "- Use \`qbraid -h\` to see available commands."
1269
- echo -e ""
1270
- echo -e "- Use \`qbraid --version\` to display the current version."
1271
- echo -e ""
1272
- echo -e "Reference Docs: https://docs.qbraid.com/projects/cli/en/latest/cli/qbraid.html"
1273
-
1274
- # qbraid configure
1275
- elif [ "${1}" = "configure" ]; then
1276
- ((argDepth++))
1277
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1278
- help_configure
1279
- fi
1280
-
1281
- # qbraid credits
1282
- elif [ "${1}" = "credits" ]; then
1283
- ((argDepth++))
1284
- if [ "$(help_command "${argDepth}")" = "yes" ]; then
1285
- help_credits
1286
- fi
1287
-
1288
- # qbraid envs
1289
- elif [ "${1}" = "envs" ]; then
1290
- envs "${@:2}"
1291
-
1292
- # qbraid kernels
1293
- elif [ "${1}" = "kernels" ]; then
1294
- kernels "${@:2}"
1295
-
1296
- # qbraid jobs
1297
- elif [ "${1}" = "jobs" ]; then
1298
- jobs "${@:2}"
1299
-
1300
- # qbraid devices
1301
- elif [ "${1}" = "devices" ]; then
1302
- devices "${@:2}"
1303
-
1304
- else
1305
- echo -e "${RED}ERROR: Invalid argument ${NC}${1}"
1306
- echo ""
1307
- echo -e "Use \`qbraid -h\` to see available commands"
1308
- exit 1
1309
- fi
1310
-
1311
- }
1312
-
1313
-
1314
- #-------------------------------------------------------------------------
1315
- # run command
1316
-
1317
- qbraid "$@"