Skip to content

Commit 40c117d

Browse files
authored
fix: latest test recordings + use InteractiveBrowserCredential authentication fallback (#690)
* fix: latest test recordings + use EnvironmentCredential for tests * chore: group tests by target name avoiding failures during concurrent runs * fix: rigetti test
1 parent c045d55 commit 40c117d

File tree

154 files changed

+531087
-72257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+531087
-72257
lines changed

.ado/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ schedules:
1515
variables:
1616
- name: QSHARP_PYTHON_TELEMETRY
1717
value: none # Disable usage telemetry for internal test pipelines
18+
- name: PYTEST_MAX_PARALLEL_TESTS
19+
value: 'auto'
1820

1921
jobs:
2022
- job: "Build_Azure_Quantum_Python"
@@ -58,7 +60,7 @@ jobs:
5860
displayName: Set Python version
5961

6062
- script: |
61-
pip install pytest pytest-azurepipelines pytest-cov pytest-regressions
63+
pip install pytest pytest-azurepipelines pytest-cov pytest-xdist
6264
displayName: Install pytest dependencies
6365
6466
- script: |
@@ -68,7 +70,7 @@ jobs:
6870
- script: |
6971
cd $(Build.SourcesDirectory)/azure-quantum
7072
pip install .[qiskit,cirq,qsharp,dev]
71-
pytest --cov-report term --cov=azure.quantum --junitxml test-output-azure-quantum.xml $(Build.SourcesDirectory)/azure-quantum
73+
pytest --numprocesses $(PYTEST_MAX_PARALLEL_TESTS) --cov-report term --cov=azure.quantum --junitxml test-output-azure-quantum.xml $(Build.SourcesDirectory)/azure-quantum
7274
displayName: Run azure-quantum unit tests
7375
7476
- task: PublishTestResults@2

.ado/publish.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ variables:
4040
value: 'xiou'
4141
- name: QSHARP_PYTHON_TELEMETRY
4242
value: none # Disable usage telemetry for internal test pipelines
43+
- name: PYTEST_MAX_PARALLEL_TESTS
44+
value: 'auto'
4345

4446
resources:
4547
repositories:
@@ -108,7 +110,7 @@ extends:
108110
displayName: Set Python version
109111

110112
- script: |
111-
pip install pytest pytest-azurepipelines pytest-cov pytest-regressions
113+
pip install pytest pytest-azurepipelines pytest-cov pytest-xdist
112114
displayName: Install pytest dependencies
113115
114116
- script: |
@@ -118,7 +120,7 @@ extends:
118120
- script: |
119121
cd $(Build.SourcesDirectory)/azure-quantum
120122
pip install .[qiskit,cirq,qsharp,dev]
121-
pytest --cov-report term --cov=azure.quantum --junitxml test-output-azure-quantum.xml $(Build.SourcesDirectory)/azure-quantum
123+
pytest --numprocesses $(PYTEST_MAX_PARALLEL_TESTS) --cov-report term --cov=azure.quantum --junitxml test-output-azure-quantum.xml $(Build.SourcesDirectory)/azure-quantum
122124
displayName: Run Unit-tests
123125
124126
- task: PublishTestResults@2

.vscode/settings.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"pythonTestExplorer.testFramework": "pytest",
3+
"pythonTestExplorer.outputs.showOutputsOnRun": true,
4+
"testExplorer.useNativeTesting": false,
5+
"testExplorer.showOnRun": true,
6+
"testExplorer.addToEditorContextMenu": true,
7+
"python.testing.pytestArgs": [
8+
"./azure-quantum/tests/unit",
9+
"-n",
10+
"auto",
11+
"--dist",
12+
"loadgroup",
13+
],
14+
"python.testing.unittestEnabled": false,
15+
"python.testing.pytestEnabled": true
16+
}

CONTRIBUTING.md

Lines changed: 105 additions & 114 deletions
Large diffs are not rendered by default.

azure-quantum/.vscode/settings.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

azure-quantum/README.md

Lines changed: 7 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,20 @@
22

33
# Azure Quantum #
44

5-
[![Build Status](https://dev.azure.com/ms-quantum-public/Microsoft%20Quantum%20(public)/_apis/build/status/microsoft.qdk-python?branchName=main)](https://dev.azure.com/ms-quantum-public/Microsoft%20Quantum%20(public)/_build/latest?definitionId=32&branchName=main) [![PyPI version](https://badge.fury.io/py/azure-quantum.svg)](https://badge.fury.io/py/azure-quantum)
5+
[![PyPI version](https://badge.fury.io/py/azure-quantum.svg)](https://badge.fury.io/py/azure-quantum)
66

7-
Azure Quantum is Microsoft's cloud service for running Quantum Computing programs and circuits with our quantum partners and technologies. The `azure-quantum` package for Python provides functionality for interacting with Azure Quantum workspaces, including creating jobs, listing jobs, and retrieving job results. For more information, view the [Azure Quantum Documentation](https://learn.microsoft.com/en-us/azure/quantum/).
7+
Azure Quantum is Microsoft's cloud service for running Quantum Computing programs. The `azure-quantum` package for Python provides functionality for interacting with Azure Quantum workspaces, including creating jobs, listing jobs, and retrieving job results. For more information, view the [Azure Quantum Documentation](https://learn.microsoft.com/en-us/azure/quantum/).
88

99
This package supports submitting quantum programs or circuits written with Python. To submit quantum programs written with Q#, Microsoft's Domain-specific language for Quantum Programming, view [Submit Q# Jobs to Azure Quantum](https://learn.microsoft.com/azure/quantum/how-to-submit-jobs).
1010

1111
## Installation ##
1212

1313
The package is released on PyPI and can be installed via `pip`:
1414

15-
```bash
16-
pip install azure-quantum
17-
```
18-
19-
To use `azure-quantum` for submitting quantum circuits expressed with [Qiskit](https://pypi.org/project/qiskit), install with optional dependencies:
20-
21-
```bash
22-
pip install azure-quantum[qiskit]
23-
```
24-
25-
To use `azure-quantum` for submitting quantum circuits expressed with [Cirq](https://pypi.org/project/cirq), install with optional dependencies:
26-
27-
```bash
28-
pip install azure-quantum[cirq]
29-
```
15+
- For default installation - `pip install azure-quantum`
16+
- Submit quantum circuits written in [Q#](https://pypi.org/project/qsharp) - `pip install azure-quantum[qsharp]`
17+
- Submit quantum circuits written in [Qiskit](https://pypi.org/project/qiskit) - `pip install azure-quantum[qiskit]`
18+
- Submit quantum circuits written in [Cirq](https://pypi.org/project/cirq) - `pip install azure-quantum[cirq]`
3019

3120
## Getting started and Quickstart guides ##
3221

@@ -77,49 +66,7 @@ result = job.get_results()
7766

7867
## Examples ##
7968

80-
You can find example Python scripts that use the Azure Quantum Python API in the [examples](https://github.com/microsoft/qdk-python/tree/main/azure-quantum/examples) directory.
81-
82-
## Development Setup ##
83-
84-
For developers who want to contribute to this package or run tests locally, follow these steps:
85-
86-
### Prerequisites
87-
88-
- Python 3.9 or later
89-
- Git
90-
- Powershell
91-
92-
### Setting up the development environment
93-
94-
1. Clone the repository:
95-
```bash
96-
git clone https://github.com/microsoft/qdk-python.git
97-
cd qdk-python/azure-quantum
98-
```
99-
100-
2. Set up a virtual environment and install development dependencies:
101-
```powershell
102-
# On Windows (PowerShell)
103-
.\eng\Setup-Dev-Env.ps1
104-
```
105-
106-
3. Run the tests:
107-
```bash
108-
pytest tests/unit/
109-
```
110-
111-
4. (Optional) Install additional provider dependencies:
112-
```bash
113-
# For specific providers
114-
pip install -e .[pulser,quil]
115-
116-
# For all providers (requires Rust toolchain for PyQuil)
117-
pip install -e .[all]
118-
```
119-
120-
### Running Tests
121-
122-
The development environment includes pytest for running unit tests. See [tests/README.md](tests/README.md) for detailed testing instructions.
69+
You can find example Python scripts that use the Azure Quantum Python API in the [samples](https://github.com/microsoft/azure-quantum-python/tree/main/samples) directory.
12370

12471
## Contributing ##
12572

azure-quantum/azure/quantum/_workspace_connection_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def get_credential_or_default(self) -> Any:
406406
or defaults to a new DefaultAzureCredential.
407407
"""
408408
return (self.credential
409-
or DefaultAzureCredential())
409+
or DefaultAzureCredential(exclude_interactive_browser_credential=False))
410410

411411
def get_auth_policy(self) -> Any:
412412
"""

azure-quantum/requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pytest>=7.1.2
2+
pytest-xdist>=3.8.0,<4.0
23
vcrpy>=4.3.1 # fixes https://github.com/kevin1024/vcrpy/issues/688
34
azure-devtools>=1.2.0,<2.0
45
graphviz>=0.20.1

azure-quantum/tests/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ This will force the recording files to be deleted before running the tests.
3131

3232
To run the tests in recording or live mode, make sure:
3333

34-
- You have installed [Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest).
35-
- You're logged into your Azure Entra ID Tenant in the Azure CLI - `az login` (or `az login --tenant <tenantId>`).
34+
- You have a client app registered in Microsoft Entra ID (formerly Azure Active Directory)
35+
- The client app is configured with [certificate-based authentication](https://learn.microsoft.com/en-us/entra/identity/authentication/how-to-certificate-based-authentication)
36+
- The client app has "Contributor" permissions to your Azure Quantum Workspace
3637
- You have "Quantum Workspace Owner" or "Quantum Workspace Data Contributor" or "Contributor" role on the Azure Quantum Workspace against which you would like to capture the recordings.
3738
- You have all necessary Providers added to the Azure Quantum Workspace.
3839
- The following environment variables are set:
40+
- `AZURE_CLIENT_ID` - application (client) ID from Microsoft Entra ID
41+
- `AZURE_TENANT_ID` - directory (tenant) ID from Microsoft Entra ID
42+
- `AZURE_CLIENT_CERTIFICATE_PATH` - path to PEM or PKCS12 certificate file (including the private key) that is configured for the client app
43+
- `AZURE_CLIENT_SEND_CERTIFICATE_CHAIN=True` - prompts Azure.Identity to set X5C header (specifying certificate chain) required to support SNI authentication
3944
- `AZURE_QUANTUM_SUBSCRIPTION_ID` - ID of the Subscription where Azure Quantum Workspace is deployed
4045
- `AZURE_QUANTUM_WORKSPACE_RG` - name of the Resource Group where Azure Quantum Workspace is deployed
4146
- `AZURE_QUANTUM_WORKSPACE_NAME` - name of the Azure Quantum Workspace
@@ -154,3 +159,6 @@ skip_older_version = pytest.mark.skipif(__version__ != "0.0.1" and __version__ <
154159
def test_my_test(self):
155160
pass
156161
```
162+
163+
Additionally, some of the Live Tests are marked with `@pytest.mark.xdist_group(name="<targetName>")` annotation.
164+
This is to avoid failing concurrent tests when they're waiting in the same target queue on the provider side.

azure-quantum/tests/unit/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
)
2727
from azure.quantum import Job
2828
from azure.quantum.target import Target
29-
from azure.identity import ClientSecretCredential, AzureCliCredential
29+
from azure.identity import ClientSecretCredential, EnvironmentCredential
3030

3131

3232
ZERO_UID = "00000000-0000-0000-0000-000000000000"
@@ -304,7 +304,7 @@ def create_workspace(
304304
client_secret=PLACEHOLDER)
305305

306306
workspace = Workspace(
307-
credential=credential if credential else AzureCliCredential(),
307+
credential=credential if credential else EnvironmentCredential(),
308308
subscription_id=connection_params.subscription_id,
309309
resource_group=connection_params.resource_group,
310310
name=connection_params.workspace_name,

0 commit comments

Comments
 (0)