Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ado/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:

- script: |
cd $(Build.SourcesDirectory)/azure-quantum
pip install .[all]
pip install .[qiskit,cirq,qsharp,dev]
pytest --cov-report term --cov=azure.quantum --junitxml test-output-azure-quantum.xml $(Build.SourcesDirectory)/azure-quantum
displayName: Run azure-quantum unit tests

Expand Down
2 changes: 1 addition & 1 deletion .ado/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ extends:

- script: |
cd $(Build.SourcesDirectory)/azure-quantum
pip install .[all]
pip install .[qiskit,cirq,qsharp,dev]
pytest --cov-report term --cov=azure.quantum --junitxml test-output-azure-quantum.xml $(Build.SourcesDirectory)/azure-quantum
displayName: Run Unit-tests

Expand Down
1 change: 0 additions & 1 deletion azure-quantum/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ include *.py
include *.md
recursive-include azure *.py
exclude MANIFEST.in
exclude environment.yml
recursive-exclude azure *.typed
recursive-exclude eng *
recursive-exclude tests *
42 changes: 42 additions & 0 deletions azure-quantum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,48 @@ result = job.get_results()

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.

## Development Setup ##

For developers who want to contribute to this package or run tests locally, follow these steps:

### Prerequisites

- Python 3.9 or later
- Git
- Powershell

### Setting up the development environment

1. Clone the repository:
```bash
git clone https://github.com/microsoft/qdk-python.git
cd qdk-python/azure-quantum
```

2. Set up a virtual environment and install development dependencies:
```powershell
# On Windows (PowerShell)
.\eng\Setup-Dev-Env.ps1
```

3. Run the tests:
```bash
pytest tests/unit/
```

4. (Optional) Install additional provider dependencies:
```bash
# For specific providers
pip install -e .[pulser,quil]

# For all providers (requires Rust toolchain for PyQuil)
pip install -e .[all]
```

### Running Tests

The development environment includes pytest for running unit tests. See [tests/README.md](tests/README.md) for detailed testing instructions.

## Contributing ##

For details on contributing to this package, see the [contributing guide](https://github.com/microsoft/qdk-python/blob/main/CONTRIBUTING.md).
Expand Down
9 changes: 8 additions & 1 deletion azure-quantum/eng/Record-Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ try
{
Push-Location (Join-Path $PSScriptRoot "../tests/")

conda activate azurequantum
# Activate virtual environment if it exists
$VenvPath = "../venv"
if (Test-Path $VenvPath) {
Write-Host "Activating virtual environment..."
& "$VenvPath\Scripts\Activate.ps1"
} else {
Write-Warning "Virtual environment not found at $VenvPath. Please run Setup-Dev-Env.ps1 first."
}

if ([string]::IsNullOrEmpty($TestFilter)) {
pytest
Expand Down
27 changes: 23 additions & 4 deletions azure-quantum/eng/Setup-Dev-Env.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,30 @@ try
{
Push-Location (Join-Path $PSScriptRoot "../")

conda env create -f environment.yml
conda env update -f environment.yml --prune
conda activate azurequantum
# Create virtual environment if it doesn't exist
$VenvPath = "venv"
if (-not (Test-Path $VenvPath)) {
Write-Host "Creating virtual environment..."
python -m venv $VenvPath
}

pip install -e .[qiskit,cirq]
# Activate virtual environment
Write-Host "Activating virtual environment..."
& ".\$VenvPath\Scripts\Activate.ps1"

# Upgrade pip and install build tools
Write-Host "Upgrading pip and installing build tools..."
python -m pip install --upgrade pip setuptools wheel

# Install package in editable mode with optional dependencies
Write-Host "Installing package in editable mode..."
pip install -e .[qiskit,cirq,qsharp,dev]

Write-Host ""
Write-Host "Development environment setup complete!"
Write-Host "To install additional optional dependencies later, run:"
Write-Host " pip install -e .[pulser,quil] # for specific providers"
Write-Host " pip install -e .[all] # for all providers (requires Rust toolchain)"
}
finally
{
Expand Down
11 changes: 0 additions & 11 deletions azure-quantum/environment.yml

This file was deleted.

3 changes: 2 additions & 1 deletion azure-quantum/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pytest>=7.1.2
vcrpy>=4.3.1 # fixes https://github.com/kevin1024/vcrpy/issues/688
azure-devtools>=1.2.0,<2.0
graphviz>=0.20.1
graphviz>=0.20.1
21 changes: 10 additions & 11 deletions azure-quantum/tests.live/Install-Artifacts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@

<#
.SYNOPSIS
Install-Artifacts: set up a Python environment using Anaconda
Install-Artifacts: set up a Python environment using virtual environments
#>

$PackageDir = Split-Path -parent $PSScriptRoot;
$PackageName = $PackageDir | Split-Path -Leaf;
$RootDir = Split-Path -parent $PackageDir;
Import-Module (Join-Path $RootDir "build" "conda-utils.psm1");
Import-Module (Join-Path $RootDir "build" "package-utils.psm1");
Import-Module (Join-Path $RootDir "build" "venv-utils.psm1") -Force;
Import-Module (Join-Path $RootDir "build" "package-utils.psm1") -Force;

# Enable conda hook
Enable-Conda

NewCondaEnvForPackage -PackageName $PackageName
New-VenvForPackage -PackageName $PackageName

if (-not $Env:PYTHON_OUTDIR) {
"" | Write-Host
"== Environment variable $Env:PYTHON_OUTDIR is not set. " | Write-Host
"== We will install $PackageName from source." | Write-Host
"" | Write-Host

Install-PackageInEnv -PackageName "$PackageName[all]" -FromSource $True
$PackageWithExtras = "$PackageName[qiskit,cirq,qsharp,dev]"
Install-PackageInEnv -PackageName $PackageWithExtras -FromSource $True

"" | Write-Host
"== $PackageName installed from source. ==" | Write-Host
Expand All @@ -34,7 +32,8 @@ if (-not $Env:PYTHON_OUTDIR) {
"== To use build artifacts, download the artifacts locally and point the variable to this folder." | Write-Warning
"" | Write-Warning
Exit 1
}
}

# this condition is used by the E2E Live test pipeline
elseif ($Env:PICK_QDK_VERSION -eq "auto") {
"== Installing latest published $PackageName package from PyPI..." | Write-Host
Expand All @@ -43,9 +42,9 @@ elseif ($Env:PICK_QDK_VERSION -eq "auto") {
"== Preparing environment to use artifacts with version '$Env:PYTHON_VERSION' " | Write-Host
"== from '$Env:PYTHON_OUTDIR'" | Write-Host
if ($Env:PYTHON_VERSION) {
$NameAndVersion = "$PackageName[all]==$($Env:PYTHON_VERSION)"
$NameAndVersion = "$PackageName[qiskit,cirq,qsharp,dev]==$($Env:PYTHON_VERSION)"
} else {
$NameAndVersion = "$PackageName[all]"
$NameAndVersion = "$PackageName[qiskit,cirq,qsharp,dev]"
}

Install-PackageInEnv -PackageName $NameAndVersion -FromSource $False -BuildArtifactPath $Env:PYTHON_OUTDIR
Expand Down
20 changes: 1 addition & 19 deletions azure-quantum/tests.live/Run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Get-ChildItem env:AZURE*, env:*VERSION, env:*OUTDIR | ForEach-Object {
$PackageDir = Split-Path -parent $PSScriptRoot;
$PackageName = $PackageDir | Split-Path -Leaf;
$RootDir = Split-Path -parent $PackageDir;
Import-Module (Join-Path $RootDir "build" "conda-utils.psm1");
Import-Module (Join-Path $RootDir "build" "venv-utils.psm1");
Import-Module (Join-Path $RootDir "build" "package-utils.psm1");

if ($True -eq $SkipInstall) {
Expand All @@ -27,24 +27,6 @@ if ($True -eq $SkipInstall) {
& (Join-Path $PSScriptRoot Install-Artifacts.ps1)
}

Enable-Conda

# Try activating the azurequantum conda environment
if ([string]::IsNullOrEmpty($PackageName) -or ($PackageName -eq "azure-quantum")) {
try {
$EnvExists = conda env list | Select-String -Pattern "azurequantum " | Measure-Object | Select-Object -Exp Count
if ($EnvExists) {
conda activate azurequantum
}
}
catch {
Write-Host "##[warning]Failed to active conda environment."
}
}

$EnvName = GetEnvName -PackageName $PackageName
Use-CondaEnv $EnvName

function PyTestMarkExpr() {
param (
[string[]] $AzureQuantumCapabilities
Expand Down
14 changes: 13 additions & 1 deletion azure-quantum/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@

## Environment Pre-reqs

Refer to [the parent README](../README.md) for how to prepare the development environment before running the unit tests.
Before running the unit tests, set up your development environment using the venv-based setup:

### On Windows (PowerShell):
```powershell
.\eng\Setup-Dev-Env.ps1
```

This will install the package with common optional dependencies (qiskit, cirq, qsharp). To install additional provider dependencies, run:
```powershell
./venv/Scripts/activate # Activate the virtual environment first
pip install -e .[pulser,quil] # for specific providers
pip install -e .[all] # for all providers (requires Rust toolchain)
```

### Environment variables for Recording and Live-Tests

Expand Down
142 changes: 0 additions & 142 deletions build/conda-utils.psm1

This file was deleted.

Loading
Loading