Skip to content

Commit

Permalink
Merge branch 'oscarpuente/noisy-simulator' of https://github.com/micr…
Browse files Browse the repository at this point in the history
…osoft/qsharp into oscarpuente/noisy-simulator
  • Loading branch information
orpuente-MS committed Jul 8, 2024
2 parents 1b260d4 + 498ac13 commit f1a6f9e
Show file tree
Hide file tree
Showing 226 changed files with 4,729 additions and 2,200 deletions.
2 changes: 0 additions & 2 deletions .ado/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ trigger:
include:
- main

pr: none

# Run the pipeline every day at 6:00 AM to ensure
# codeql and other governance checks are up-to-date.
schedules:
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/bench-reports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Benchmark Reports

on:
pull_request:
branches: "main"
types:
- opened
- reopened
- synchronize
- ready_for_review
merge_group:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
NODE_VERSION: "18.17.1"
PYTHON_VERSION: "3.11"
RUST_TOOLCHAIN_VERSION: "1.78"
RUST_TOOLCHAIN_COMPONENTS: rustfmt clippy

jobs:
runBenchmark:
if: ${{ !github.event.pull_request.draft }}
name: run benchmark
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: boa-dev/criterion-compare-action@v3
with:
branchName: ${{ github.base_ref }}
cwd: "compiler/qsc"
if: ${{ github.base_ref != null }}

runMemoryProfile:
if: ${{ !github.event.pull_request.draft }}
name: run memory profile
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v2
with:
ref: main
- uses: Swatinem/rust-cache@v2
- run: |
MAIN_MEASUREMENT=$(cargo run --bin memtest)
echo "MAIN_MEASUREMENT<<EOF" >> $GITHUB_ENV
echo "$MAIN_MEASUREMENT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- run: |
echo "${{env.MAIN_MEASUREMENT}}"
echo $MAIN_MEASUREMENT
- uses: actions/checkout@v2
- run: |
BRANCH_MEASUREMENT=$(cargo run --bin memtest)
echo "BRANCH_MEASUREMENT<<EOF" >> $GITHUB_ENV
echo "$BRANCH_MEASUREMENT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- run: |
echo "${{env.BRANCH_MEASUREMENT}}"
echo $BRANCH_MEASUREMENT
- uses: actions/github-script@v6
with:
script: |
if (${{ env.BRANCH_MEASUREMENT }} !== ${{ env.MAIN_MEASUREMENT }}) {
const difference = ${{ env.BRANCH_MEASUREMENT }} - ${{ env.MAIN_MEASUREMENT }};
try {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `_Change in memory usage detected by benchmark._
## Memory Report for ${{ github.sha }}
| Test | This Branch | On Main | Difference |
|-----------------------------|-------------|----------| ---------- |
| compile core + standard lib | ${{ env.BRANCH_MEASUREMENT }} bytes | ${{ env.MAIN_MEASUREMENT }} bytes | ${difference} bytes`
})
} catch (err) {
core.warning(`Failed writing comment on GitHub issue: ${err}`)
}
} else {
console.log("no change in memory usage detected by benchmark");
}
if: ${{ github.base_ref != null }}
103 changes: 34 additions & 69 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,10 @@ jobs:
- name: Prereqs
run: python ./prereqs.py --install
- name: Build and Test
run: python ./build.py --no-check
run: python ./build.py --no-check --wasm --npm --vscode --play --pip --widgets --jupyterlab

integration-tests:
name: Integration tests
timeout-minutes: 15
unit-tests:
name: Rust Unit and Samples tests
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-14]
Expand Down Expand Up @@ -149,80 +148,46 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: Prereqs
run: python ./prereqs.py --install
- name: Run integration tests
run: python ./build.py --no-check --no-test --wasm --npm --vscode --pip --widgets --integration-tests
- name: Build and Test
run: python ./build.py --no-check --cli --samples

integration-tests:
name: Integration tests
timeout-minutes: 15
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-14]

runs-on: ${{matrix.os}}

runBenchmark:
name: run benchmark
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: boa-dev/criterion-compare-action@v3
with:
branchName: ${{ github.base_ref }}
cwd: "compiler/qsc"
if: ${{ github.base_ref != null }}

runMemoryProfile:
name: run memory profile
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v2
submodules: "true"
- name: Setup rust toolchain
uses: ./.github/actions/toolchains/rust
with:
ref: main
toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }}
components: ${{ env.RUST_TOOLCHAIN_COMPONENTS }}
- name: Add additional Rust targets
run: |
rustup target add x86_64-apple-darwin
if: matrix.os == 'macos-14'
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- uses: Swatinem/rust-cache@v2
- run: |
MAIN_MEASUREMENT=$(cargo run --bin memtest)
echo "MAIN_MEASUREMENT<<EOF" >> $GITHUB_ENV
echo "$MAIN_MEASUREMENT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- run: |
echo "${{env.MAIN_MEASUREMENT}}"
echo $MAIN_MEASUREMENT
- uses: actions/checkout@v2
- run: |
BRANCH_MEASUREMENT=$(cargo run --bin memtest)
echo "BRANCH_MEASUREMENT<<EOF" >> $GITHUB_ENV
echo "$BRANCH_MEASUREMENT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- run: |
echo "${{env.BRANCH_MEASUREMENT}}"
echo $BRANCH_MEASUREMENT
- uses: actions/github-script@v6
with:
script: |
if (${{ env.BRANCH_MEASUREMENT }} !== ${{ env.MAIN_MEASUREMENT }}) {
const difference = ${{ env.BRANCH_MEASUREMENT }} - ${{ env.MAIN_MEASUREMENT }};
try {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `_Change in memory usage detected by benchmark._
## Memory Report for ${{ github.sha }}
| Test | This Branch | On Main | Difference |
|-----------------------------|-------------|----------| ---------- |
| compile core + standard lib | ${{ env.BRANCH_MEASUREMENT }} bytes | ${{ env.MAIN_MEASUREMENT }} bytes | ${difference} bytes`
})
} catch (err) {
core.warning(`Failed writing comment on GitHub issue: ${err}`)
}
} else {
console.log("no change in memory usage detected by benchmark");
}
if: ${{ github.base_ref != null }}
- name: Prereqs
run: python ./prereqs.py --install
- name: Run integration tests
run: python ./build.py --no-check --no-test --wasm --npm --vscode --pip --widgets --integration-tests

status-check:
name: Status Check
needs: [format, clippy, web-check, build, format-qsc, integration-tests, runBenchmark, runMemoryProfile]
needs: [format, clippy, web-check, build, unit-tests, format-qsc, integration-tests]
runs-on: ubuntu-latest
if: failure()
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Prereqs
run: python ./prereqs.py --install
- name: Build and Test
run: python ./build.py
run: python ./build.py --no-check --no-test --wasm --npm --play
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
Expand Down
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ members = [
"library",
"pip",
"resource_estimator",
"samples_test",
"wasm",
]
resolver = "2"
Expand Down
18 changes: 11 additions & 7 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,22 @@ def use_python_env(folder):
step_end()

if build_cli:
step_start("Building the command line compiler")
cargo_build_args = ["cargo", "build"]
if build_type == "release":
cargo_build_args.append("--release")
subprocess.run(cargo_build_args, check=True, text=True, cwd=root_dir)

if run_tests:
print("Running tests for the command line compiler")
step_start("Running Rust unit tests")
cargo_test_args = ["cargo", "test"]
if build_type == "release":
cargo_test_args.append("--release")
# Disable LTO for release tests to speed up compilation
cargo_test_args.append("--config")
cargo_test_args.append('profile.release.lto="off"')
subprocess.run(cargo_test_args, check=True, text=True, cwd=root_dir)
step_end()

step_start("Building the command line compiler")
cargo_build_args = ["cargo", "build", "--bin", "qsc"]
if build_type == "release":
cargo_build_args.append("--release")
subprocess.run(cargo_build_args, check=True, text=True, cwd=root_dir)
step_end()


Expand Down
3 changes: 3 additions & 0 deletions compiler/qsc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ doctest = false
[[bin]]
name = "qsc"
bench = false
test = false

[[bin]]
name = "qsi"
bench = false
test = false

[[bin]]
name = "memtest"
bench = false
test = false

[[bench]]
name = "large"
Expand Down
30 changes: 21 additions & 9 deletions compiler/qsc/src/bin/qsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use qsc_frontend::{
use qsc_hir::hir::Package;
use qsc_partial_eval::ProgramEntry;
use qsc_passes::PackageType;
use qsc_project::{FileSystem, Manifest, StdFs};
use qsc_project::{FileSystem, StdFs};
use std::{
concat, fs,
io::{self, Read},
Expand Down Expand Up @@ -122,16 +122,28 @@ fn main() -> miette::Result<ExitCode> {

if sources.is_empty() {
let fs = StdFs;
let manifest = Manifest::load(cli.qsharp_json)?;
if let Some(manifest) = manifest {
let project = fs.load_project(&manifest)?;
let mut project_sources = project.sources;
if let Some(qsharp_json) = cli.qsharp_json {
if let Some(dir) = qsharp_json.parent() {
let project = match fs.load_project(dir, None) {
Ok(project) => project,
Err(errs) => {
for e in errs {
eprintln!("{e:?}");
}
return Ok(ExitCode::FAILURE);
}
};

sources.append(&mut project_sources);
let (mut project_sources, language_features) =
project.package_graph_sources.into_sources_temporary();

features.merge(LanguageFeatures::from_iter(
manifest.manifest.language_features,
));
sources.append(&mut project_sources);

features.merge(LanguageFeatures::from_iter(language_features));
} else {
eprintln!("{} must have a parent directory", qsharp_json.display());
return Ok(ExitCode::FAILURE);
}
}
}

Expand Down
Loading

0 comments on commit f1a6f9e

Please sign in to comment.