From 41a9c9666a2e53ccf648f9c091adf6e91f603765 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Wed, 16 Jun 2021 15:30:40 -0700 Subject: [PATCH 01/10] notes for myself --- src/quantum/LocalDev.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/quantum/LocalDev.md diff --git a/src/quantum/LocalDev.md b/src/quantum/LocalDev.md new file mode 100644 index 00000000000..af9876a8eee --- /dev/null +++ b/src/quantum/LocalDev.md @@ -0,0 +1,18 @@ +Local conda environment: az-dev +Commands for new creation: +- conda create -n az-dev python=3.8 pip +- pip install azdev +- azdev setup --cli C:\Users\beheim\Source\Repos\az-cli --repo C:\Users\beheim\Source\Repos\az-quantum + +Bug workaround that was needed for the last one (https://github.com/Azure/azure-cli-dev-tools/issues/307): +in C:\Users\beheim\AppData\Local\Continuum\anaconda3\envs\az-dev\lib\site-packages\azdev\command.py +edited py_cmd to replace + python_bin = sys.executable if not env_path else os.path.join(env_path, 'Scripts' if sys.platform == 'win32' else 'bin', 'python') +with + python_bin = sys.executable + + +documentation for az cli development: https://github.com/Azure/azure-cli-dev-tools +Commands: +- open Anaconda Powershell Prompt +- conda activate az-dev From 1207943d40d9a73bb25cbddf4a474fded83f0a97 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Wed, 16 Jun 2021 19:15:43 -0700 Subject: [PATCH 02/10] instructions now work --- src/quantum/LocalDev.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/quantum/LocalDev.md b/src/quantum/LocalDev.md index af9876a8eee..6608a28d432 100644 --- a/src/quantum/LocalDev.md +++ b/src/quantum/LocalDev.md @@ -1,18 +1,23 @@ -Local conda environment: az-dev +Local conda environment: azdevenv Commands for new creation: -- conda create -n az-dev python=3.8 pip +- open Anaconda Powershell Prompt +- conda create -n azdevenv python=3.8 pip +- conda activate azdevenv - pip install azdev - azdev setup --cli C:\Users\beheim\Source\Repos\az-cli --repo C:\Users\beheim\Source\Repos\az-quantum +IMPORTANT: +To make sure the source code version of extensions is used, make sure to install them using + azdev extension add + Bug workaround that was needed for the last one (https://github.com/Azure/azure-cli-dev-tools/issues/307): -in C:\Users\beheim\AppData\Local\Continuum\anaconda3\envs\az-dev\lib\site-packages\azdev\command.py +in C:\Users\beheim\Anaconda3\envs\azdevenv\Lib\site-packages\azdev\utilities\command.py edited py_cmd to replace python_bin = sys.executable if not env_path else os.path.join(env_path, 'Scripts' if sys.platform == 'win32' else 'bin', 'python') with - python_bin = sys.executable - + python_bin = sys.executable if not env_path else os.path.join(env_path, 'python') if sys.platform == 'win32' else os.path.join(env_path, 'bin', 'python') documentation for az cli development: https://github.com/Azure/azure-cli-dev-tools Commands: - open Anaconda Powershell Prompt -- conda activate az-dev +- conda activate azdevenv From 8f4e99c611890fa26933b6dfa367c655830e3c01 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Wed, 16 Jun 2021 20:16:33 -0700 Subject: [PATCH 03/10] more notes --- src/quantum/LocalDev.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/quantum/LocalDev.md b/src/quantum/LocalDev.md index 6608a28d432..43b478a091d 100644 --- a/src/quantum/LocalDev.md +++ b/src/quantum/LocalDev.md @@ -1,14 +1,18 @@ +Initial conda installation: +- need to run `conda init` after installation to make the command prompt work +- needed to run `python .\pywin32_postinstall.py -install` in C:\Users\beheim\Anaconda3\Scripts + Local conda environment: azdevenv Commands for new creation: - open Anaconda Powershell Prompt -- conda create -n azdevenv python=3.8 pip -- conda activate azdevenv -- pip install azdev -- azdev setup --cli C:\Users\beheim\Source\Repos\az-cli --repo C:\Users\beheim\Source\Repos\az-quantum +- `conda create -n azdevenv python=3.8 pip` +- `conda activate azdevenv` +- `pip install azdev` +- `azdev setup --cli C:\Users\beheim\Source\Repos\az-cli --repo C:\Users\beheim\Source\Repos\az-quantum` IMPORTANT: To make sure the source code version of extensions is used, make sure to install them using - azdev extension add + `azdev extension add ` Bug workaround that was needed for the last one (https://github.com/Azure/azure-cli-dev-tools/issues/307): in C:\Users\beheim\Anaconda3\envs\azdevenv\Lib\site-packages\azdev\utilities\command.py @@ -20,4 +24,4 @@ with documentation for az cli development: https://github.com/Azure/azure-cli-dev-tools Commands: - open Anaconda Powershell Prompt -- conda activate azdevenv +- `conda activate azdevenv` From 920d4d9f3f27f0c7c2cfac5082079f5bfa062546 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Thu, 17 Jun 2021 00:31:17 -0700 Subject: [PATCH 04/10] enable table visualization for simulator jobs --- src/quantum/azext_quantum/commands.py | 2 +- src/quantum/azext_quantum/operations/job.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/quantum/azext_quantum/commands.py b/src/quantum/azext_quantum/commands.py index 8dba4d30994..3abfb159b1d 100644 --- a/src/quantum/azext_quantum/commands.py +++ b/src/quantum/azext_quantum/commands.py @@ -64,7 +64,7 @@ def one(key, value): return OrderedDict([ ('Result', key), ('Frequency', f"{value:10.8f}"), - ('', f"\u2590{barra:<22} |"), + ('', f"\u007C{barra:^20}\u007C") # f"\u23B9{barra:^22}\u23B8") ]) if 'Histogram' in results: diff --git a/src/quantum/azext_quantum/operations/job.py b/src/quantum/azext_quantum/operations/job.py index 97cedc129a1..b840f2865f2 100644 --- a/src/quantum/azext_quantum/operations/job.py +++ b/src/quantum/azext_quantum/operations/job.py @@ -186,16 +186,15 @@ def output(cmd, job_id, resource_group_name=None, workspace_name=None, location= from azure.cli.command_modules.storage._client_factory import blob_data_service_factory path = os.path.join(tempfile.gettempdir(), job_id) + info = WorkspaceInfo(cmd, resource_group_name, workspace_name, location) + client = cf_jobs(cmd.cli_ctx, info.subscription, info.resource_group, info.name, info.location) + job = client.get(job_id) if os.path.exists(path): logger.debug("Using existing blob from %s", path) else: logger.debug("Downloading job results blob into %s", path) - info = WorkspaceInfo(cmd, resource_group_name, workspace_name, location) - client = cf_jobs(cmd.cli_ctx, info.subscription, info.resource_group, info.name, info.location) - job = client.get(job_id) - if job.status != "Succeeded": return f"Job status: {job.status}. Output only available if Succeeded." @@ -204,7 +203,14 @@ def output(cmd, job_id, resource_group_name=None, workspace_name=None, location= blob_service.get_blob_to_path(args['container'], args['blob'], path) with open(path) as json_file: - data = json.load(json_file) + if job.target.startswith("microsoft.simulator"): + lines = [line.strip() for line in json_file.readlines()] + print('\n'.join(lines[:-1])) + print("_" * len(lines[-1]) + "\n") + json_string = "{ \"histogram\" : { \"" + lines[-1] + "\" : 1 } }" + data = json.loads(json_string) + else: + data = json.load(json_file) return data From 37c76b08ebb0236faddebaccfc2320791ec85cfa Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Wed, 30 Jun 2021 19:52:44 -0700 Subject: [PATCH 05/10] addition to the readme --- src/quantum/LocalDev.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quantum/LocalDev.md b/src/quantum/LocalDev.md index 43b478a091d..728b04df0e7 100644 --- a/src/quantum/LocalDev.md +++ b/src/quantum/LocalDev.md @@ -1,6 +1,6 @@ Initial conda installation: - need to run `conda init` after installation to make the command prompt work -- needed to run `python .\pywin32_postinstall.py -install` in C:\Users\beheim\Anaconda3\Scripts +- needed to run `python .\pywin32_postinstall.py -install` in C:\Users\beheim\Anaconda3\Scripts to fix "DLL load failed while importing win32file: The specified module could not be found." Local conda environment: azdevenv Commands for new creation: From 80b8ef1b830c50598878a7c81ac019ad9ef2e753 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Wed, 30 Jun 2021 19:55:07 -0700 Subject: [PATCH 06/10] removing local dev --- src/quantum/LocalDev.md | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 src/quantum/LocalDev.md diff --git a/src/quantum/LocalDev.md b/src/quantum/LocalDev.md deleted file mode 100644 index 728b04df0e7..00000000000 --- a/src/quantum/LocalDev.md +++ /dev/null @@ -1,27 +0,0 @@ -Initial conda installation: -- need to run `conda init` after installation to make the command prompt work -- needed to run `python .\pywin32_postinstall.py -install` in C:\Users\beheim\Anaconda3\Scripts to fix "DLL load failed while importing win32file: The specified module could not be found." - -Local conda environment: azdevenv -Commands for new creation: -- open Anaconda Powershell Prompt -- `conda create -n azdevenv python=3.8 pip` -- `conda activate azdevenv` -- `pip install azdev` -- `azdev setup --cli C:\Users\beheim\Source\Repos\az-cli --repo C:\Users\beheim\Source\Repos\az-quantum` - -IMPORTANT: -To make sure the source code version of extensions is used, make sure to install them using - `azdev extension add ` - -Bug workaround that was needed for the last one (https://github.com/Azure/azure-cli-dev-tools/issues/307): -in C:\Users\beheim\Anaconda3\envs\azdevenv\Lib\site-packages\azdev\utilities\command.py -edited py_cmd to replace - python_bin = sys.executable if not env_path else os.path.join(env_path, 'Scripts' if sys.platform == 'win32' else 'bin', 'python') -with - python_bin = sys.executable if not env_path else os.path.join(env_path, 'python') if sys.platform == 'win32' else os.path.join(env_path, 'bin', 'python') - -documentation for az cli development: https://github.com/Azure/azure-cli-dev-tools -Commands: -- open Anaconda Powershell Prompt -- `conda activate azdevenv` From 120c3706cbd0ba95d2f2dacee6fb45e0a7e1a924 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Wed, 30 Jun 2021 19:49:59 -0700 Subject: [PATCH 07/10] works for multiline strings --- src/quantum/azext_quantum/operations/job.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/quantum/azext_quantum/operations/job.py b/src/quantum/azext_quantum/operations/job.py index b840f2865f2..bf00d43e41c 100644 --- a/src/quantum/azext_quantum/operations/job.py +++ b/src/quantum/azext_quantum/operations/job.py @@ -204,10 +204,15 @@ def output(cmd, job_id, resource_group_name=None, workspace_name=None, location= with open(path) as json_file: if job.target.startswith("microsoft.simulator"): + print("getting job output for simulator") lines = [line.strip() for line in json_file.readlines()] - print('\n'.join(lines[:-1])) - print("_" * len(lines[-1]) + "\n") - json_string = "{ \"histogram\" : { \"" + lines[-1] + "\" : 1 } }" + result_start_line = len(lines) - 1 + if lines[-1].endswith('"'): + while not lines[result_start_line].startswith('"'): result_start_line -= 1 + print('\n'.join(lines[:result_start_line])) + result = ' '.join(lines[result_start_line:])[1:-1] # seems the cleanest version to display + print("_" * len(result) + "\n") + json_string = "{ \"histogram\" : { \"" + result + "\" : 1 } }" data = json.loads(json_string) else: data = json.load(json_file) From 72986823b88c2e2392fa2617a5672b4a1458aaae Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Wed, 30 Jun 2021 19:57:19 -0700 Subject: [PATCH 08/10] forgot to remove a pring --- src/quantum/azext_quantum/operations/job.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/quantum/azext_quantum/operations/job.py b/src/quantum/azext_quantum/operations/job.py index bf00d43e41c..58f13a5d985 100644 --- a/src/quantum/azext_quantum/operations/job.py +++ b/src/quantum/azext_quantum/operations/job.py @@ -204,14 +204,16 @@ def output(cmd, job_id, resource_group_name=None, workspace_name=None, location= with open(path) as json_file: if job.target.startswith("microsoft.simulator"): - print("getting job output for simulator") + lines = [line.strip() for line in json_file.readlines()] result_start_line = len(lines) - 1 if lines[-1].endswith('"'): while not lines[result_start_line].startswith('"'): result_start_line -= 1 + print('\n'.join(lines[:result_start_line])) result = ' '.join(lines[result_start_line:])[1:-1] # seems the cleanest version to display print("_" * len(result) + "\n") + json_string = "{ \"histogram\" : { \"" + result + "\" : 1 } }" data = json.loads(json_string) else: From 6f49453ccb763195a329691f8a23af9448539689 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Thu, 1 Jul 2021 18:15:01 -0700 Subject: [PATCH 09/10] fixing style issues --- src/quantum/azext_quantum/commands.py | 2 +- src/quantum/azext_quantum/operations/job.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/quantum/azext_quantum/commands.py b/src/quantum/azext_quantum/commands.py index 3abfb159b1d..bd6baefc287 100644 --- a/src/quantum/azext_quantum/commands.py +++ b/src/quantum/azext_quantum/commands.py @@ -64,7 +64,7 @@ def one(key, value): return OrderedDict([ ('Result', key), ('Frequency', f"{value:10.8f}"), - ('', f"\u007C{barra:^20}\u007C") # f"\u23B9{barra:^22}\u23B8") + ('', f"\u007C{barra:^20}\u007C") # f"\u23B9{barra:^22}\u23B8") ]) if 'Histogram' in results: diff --git a/src/quantum/azext_quantum/operations/job.py b/src/quantum/azext_quantum/operations/job.py index 58f13a5d985..776f7c51bf0 100644 --- a/src/quantum/azext_quantum/operations/job.py +++ b/src/quantum/azext_quantum/operations/job.py @@ -208,12 +208,13 @@ def output(cmd, job_id, resource_group_name=None, workspace_name=None, location= lines = [line.strip() for line in json_file.readlines()] result_start_line = len(lines) - 1 if lines[-1].endswith('"'): - while not lines[result_start_line].startswith('"'): result_start_line -= 1 + while not lines[result_start_line].startswith('"'): + result_start_line -= 1 print('\n'.join(lines[:result_start_line])) - result = ' '.join(lines[result_start_line:])[1:-1] # seems the cleanest version to display + result = ' '.join(lines[result_start_line:])[1:-1] # seems the cleanest version to display print("_" * len(result) + "\n") - + json_string = "{ \"histogram\" : { \"" + result + "\" : 1 } }" data = json.loads(json_string) else: From b7c2fa7b290f7836ed99970b759fcadd1a82b1a2 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Mon, 5 Jul 2021 15:18:08 -0700 Subject: [PATCH 10/10] removing comment --- src/quantum/azext_quantum/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quantum/azext_quantum/commands.py b/src/quantum/azext_quantum/commands.py index bd6baefc287..b99e711e29c 100644 --- a/src/quantum/azext_quantum/commands.py +++ b/src/quantum/azext_quantum/commands.py @@ -64,7 +64,7 @@ def one(key, value): return OrderedDict([ ('Result', key), ('Frequency', f"{value:10.8f}"), - ('', f"\u007C{barra:^20}\u007C") # f"\u23B9{barra:^22}\u23B8") + ('', f"\u007C{barra:^20}\u007C") ]) if 'Histogram' in results: