Skip to content

Commit

Permalink
Merge branch 'microsoft:main' into MigrateNonlocalGames-1596-task2-GH…
Browse files Browse the repository at this point in the history
…Z-quantum
  • Loading branch information
ggridin authored Jan 7, 2025
2 parents ace43c7 + 1a930f6 commit 1a3cece
Show file tree
Hide file tree
Showing 518 changed files with 5,946 additions and 3,091 deletions.
8 changes: 3 additions & 5 deletions .ado/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ parameters:
default:
- name: linux_x86_64
poolName: 'Azure-Pipelines-DevTools-EO'
imageName: 'ubuntu-20.04'
imageName: 'ubuntu-22.04'
os: linux
arch: x86_64
additionalTargets: wasm32-unknown-unknown
- name: linux_aarch64
poolName: 'Azure-Pipelines-DevTools-EO'
imageName: 'ubuntu-20.04'
imageName: 'ubuntu-22.04'
os: linux
arch: aarch64
additionalRustTargets: aarch64-unknown-linux-gnu wasm32-unknown-unknown
Expand Down Expand Up @@ -299,7 +299,7 @@ extends:
python -m pip install auditwheel patchelf
ls target/wheels
ls target/wheels/*.whl | xargs auditwheel show
ls target/wheels/*.whl | xargs auditwheel repair --wheel-dir ./target/wheels/ --plat manylinux_2_31_x86_64
ls target/wheels/*.whl | xargs auditwheel repair --wheel-dir ./target/wheels/ --plat manylinux_2_35_x86_64
rm target/wheels/*-linux_x86_64.whl
ls target/wheels
displayName: Run auditwheel for Linux Wheels
Expand All @@ -313,10 +313,8 @@ extends:
condition: and(eq(variables['Agent.OS'], 'Linux'), eq(variables['arch'], 'aarch64'))
- script: |
chmod +x ./docker/linux-aarch64/build.sh
chmod +x ./docker/linux-aarch64/run.sh
./docker/linux-aarch64/build.sh
./docker/linux-aarch64/run.sh
displayName: Run auditwheel and python tests for Linux aarch64 Wheels
condition: and(eq(variables['Agent.OS'], 'Linux'), eq(variables['arch'], 'aarch64'))
Expand Down
5 changes: 3 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ log = "0.4"
miette = { version = "7.2", features = ["fancy-no-syscall"] }
thiserror = "1.0"
nalgebra = { version = "0.33" }
ndarray = "0.15.4"
num-bigint = "0.4"
num-complex = "0.4"
num-traits = "0.2"
Expand All @@ -77,7 +78,7 @@ wasm-bindgen-futures = "0.4"
rand = "0.8"
serde_json = "1.0"
pyo3 = "0.22"
quantum-sparse-sim = { git = "https://github.com/qir-alliance/qir-runner", tag = "v0.7.4" }
quantum-sparse-sim = { git = "https://github.com/qir-alliance/qir-runner", rev = "562e2c11ad685dd01bfc1ae975e00d4133615995" }
async-trait = "0.1"
tokio = { version = "1.35", features = ["macros", "rt"] }

Expand Down
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def run_ci_historic_benchmark():
"ipykernel",
"nbconvert",
"pandas",
"qiskit>=1.2.2,<2.0.0",
"qiskit>=1.3.0,<2.0.0",
]
subprocess.run(pip_install_args, check=True, text=True, cwd=root_dir, env=pip_env)

Expand Down
98 changes: 97 additions & 1 deletion compiler/qsc/src/interpret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ mod package_tests;
#[cfg(test)]
mod tests;

use std::rc::Rc;

pub use qsc_eval::{
debug::Frame,
noise::PauliNoise,
Expand All @@ -21,6 +23,7 @@ pub use qsc_eval::{
val::Value,
StepAction, StepResult,
};
use qsc_hir::{global, ty};
use qsc_linter::{HirLint, Lint, LintKind, LintLevel};
use qsc_lowerer::{map_fir_package_to_hir, map_hir_package_to_fir};
use qsc_partial_eval::ProgramEntry;
Expand Down Expand Up @@ -315,6 +318,72 @@ impl Interpreter {
})
}

/// Given a package ID, returns all the global items in the package.
/// Note this does not currently include re-exports.
fn package_globals(&self, package_id: PackageId) -> Vec<(Vec<Rc<str>>, Rc<str>, Value)> {
let mut exported_items = Vec::new();
let package = &self
.compiler
.package_store()
.get(map_fir_package_to_hir(package_id))
.expect("package should exist in the package store")
.package;
for global in global::iter_package(Some(map_fir_package_to_hir(package_id)), package) {
if let global::Kind::Term(term) = global.kind {
let store_item_id = fir::StoreItemId {
package: package_id,
item: fir::LocalItemId::from(usize::from(term.id.item)),
};
exported_items.push((
global.namespace,
global.name,
Value::Global(store_item_id, FunctorApp::default()),
));
}
}
exported_items
}

/// Get the global callables defined in the user source passed into initialization of the interpreter as `Value` instances.
pub fn user_globals(&self) -> Vec<(Vec<Rc<str>>, Rc<str>, Value)> {
self.package_globals(self.source_package)
}

/// Get the global callables defined in the open package being interpreted as `Value` instances, which will include any items
/// defined by calls to `eval_fragments` and the like.
pub fn source_globals(&self) -> Vec<(Vec<Rc<str>>, Rc<str>, Value)> {
self.package_globals(self.package)
}

/// Get the input and output types of a given value representing a global item.
/// # Panics
/// Panics if the item is not callable or a type that can be invoked as a callable.
pub fn global_tys(&self, item_id: &Value) -> Option<(ty::Ty, ty::Ty)> {
let Value::Global(item_id, _) = item_id else {
panic!("value is not a global callable");
};
let package_id = map_fir_package_to_hir(item_id.package);
let unit = self
.compiler
.package_store()
.get(package_id)
.expect("package should exist in the package store");
let item = unit
.package
.items
.get(qsc_hir::hir::LocalItemId::from(usize::from(item_id.item)))?;
match &item.kind {
qsc_hir::hir::ItemKind::Callable(decl) => {
Some((decl.input.ty.clone(), decl.output.clone()))
}
qsc_hir::hir::ItemKind::Ty(_, udt) => {
// We don't handle UDTs, so we return an error type that prevents later code from processing this item.
Some((udt.get_pure_ty(), ty::Ty::Err))
}
_ => panic!("item is not callable"),
}
}

pub fn set_quantum_seed(&mut self, seed: Option<u64>) {
self.quantum_seed = seed;
self.sim.set_seed(seed);
Expand Down Expand Up @@ -467,6 +536,33 @@ impl Interpreter {
)
}

/// Invokes the given callable with the given arguments using the current environment, simlator, and compilation.
pub fn invoke(
&mut self,
receiver: &mut impl Receiver,
callable: Value,
args: Value,
) -> InterpretResult {
qsc_eval::invoke(
self.package,
self.classical_seed,
&self.fir_store,
&mut self.env,
&mut self.sim,
receiver,
callable,
args,
)
.map_err(|(error, call_stack)| {
eval_error(
self.compiler.package_store(),
&self.fir_store,
call_stack,
error,
)
})
}

/// Runs the given entry expression on a new instance of the environment and simulator,
/// but using the current compilation.
pub fn run(
Expand Down Expand Up @@ -1033,7 +1129,7 @@ impl<'a> BreakpointCollector<'a> {
.expect("Couldn't find source file")
}

fn add_stmt(&mut self, stmt: &qsc_fir::fir::Stmt) {
fn add_stmt(&mut self, stmt: &fir::Stmt) {
let source: &Source = self.get_source(stmt.span.lo);
if source.offset == self.offset {
let span = stmt.span - source.offset;
Expand Down
Loading

0 comments on commit 1a3cece

Please sign in to comment.