Skip to content

Commit a3fdfe3

Browse files
swernlibillti
andauthored
Merge feature widgets, webview updates (#892)
Adds qsharp_widgets, updates to extension webviews Co-authored-by: Bill Ticehurst <[email protected]> --------- Co-authored-by: Bill Ticehurst <[email protected]>
1 parent 7dd3899 commit a3fdfe3

File tree

90 files changed

+12034
-691
lines changed

Some content is hidden

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

90 files changed

+12034
-691
lines changed

.ado/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
displayName: Install Prereqs and set version
125125
126126
- script: |
127-
python ./build.py --jupyterlab --no-check
127+
python ./build.py --jupyterlab --widgets --no-check
128128
displayName: Build JupyterLab Package
129129
130130
- script: |

.eslintrc.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
"/jupyterlab/qsharp-jupyterlab/labextension",
1515
"/vscode/out/",
1616
"/vscode/test/out/",
17+
"/widgets/src/qsharp_widgets/static/",
1718
],
1819
env: {
1920
browser: true,

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/target
2+
/widgets/dist/
3+
/widgets/src/qsharp_widgets/static/
24
node_modules/
35
__pycache__/
6+
.venv/
47
.DS_Store
58
.vscode/*
69
.vscode-test-web/

Cargo.lock

+43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ criterion = { version = "0.5", default-features = false }
3434
enum-iterator = "1.4"
3535
env_logger = "0.10.0"
3636
expect-test = "1.4"
37+
fasteval = "0.2"
3738
getrandom = { version = "0.2" }
3839
indoc = "2.0"
3940
js-sys = "0.3"
@@ -44,6 +45,7 @@ thiserror = "1.0"
4445
num-bigint = "0.4"
4546
num-complex = "0.4"
4647
num-traits = "0.2"
48+
probability = "0.20"
4749
indenter = "0.3"
4850
regex-lite = "0.1"
4951
rustc-hash = "1.1.0"

build.py

+23
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"--cli", action="store_true", help="Build the command-line compiler"
2828
)
2929
parser.add_argument("--pip", action="store_true", help="Build the pip wheel")
30+
parser.add_argument("--widgets", action="store_true", help="Build the Python widgets")
3031
parser.add_argument("--wasm", action="store_true", help="Build the WebAssembly files")
3132
parser.add_argument("--npm", action="store_true", help="Build the npm package")
3233
parser.add_argument("--play", action="store_true", help="Build the web playground")
@@ -77,6 +78,7 @@
7778
build_all = (
7879
not args.cli
7980
and not args.pip
81+
and not args.widgets
8082
and not args.wasm
8183
and not args.samples
8284
and not args.npm
@@ -86,6 +88,7 @@
8688
)
8789
build_cli = build_all or args.cli
8890
build_pip = build_all or args.pip
91+
build_widgets = build_all or args.widgets
8992
build_wasm = build_all or args.wasm
9093
build_samples = build_all or args.samples
9194
build_npm = build_all or args.npm
@@ -110,6 +113,7 @@
110113
npm_src = os.path.join(root_dir, "npm")
111114
play_src = os.path.join(root_dir, "playground")
112115
pip_src = os.path.join(root_dir, "pip")
116+
widgets_src = os.path.join(root_dir, "widgets")
113117
wheels_dir = os.path.join(root_dir, "target", "wheels")
114118
vscode_src = os.path.join(root_dir, "vscode")
115119
jupyterlab_src = os.path.join(root_dir, "jupyterlab")
@@ -274,6 +278,25 @@ def step_end():
274278
print("Could not import PyQIR, skipping tests")
275279
step_end()
276280

281+
if build_widgets:
282+
step_start("Building the Python widgets")
283+
284+
python_cmd = "python.exe" if platform.system() == "Windows" else "python"
285+
286+
widgets_build_args = [
287+
python_cmd,
288+
"-m",
289+
"pip",
290+
"wheel",
291+
"--no-deps",
292+
"--wheel-dir",
293+
wheels_dir,
294+
widgets_src,
295+
]
296+
subprocess.run(widgets_build_args, check=True, text=True, cwd=widgets_src)
297+
298+
step_end()
299+
277300
if build_wasm:
278301
step_start("Building the wasm crate")
279302
# wasm-pack can't build for web and node in the same build, so need to run twice.

compiler/qsc/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ qsc_fir = { path = "../qsc_fir" }
2525
qsc_hir = { path = "../qsc_hir" }
2626
qsc_passes = { path = "../qsc_passes" }
2727
qsc_project = { path = "../qsc_project", features = ["fs"] }
28+
rand = { workspace = true }
2829
rustc-hash = { workspace = true }
2930
thiserror = { workspace = true }
31+
probability = { workspace = true }
32+
regex-lite = { workspace = true }
33+
serde = { workspace = true, features = ["derive", "rc"] }
34+
serde_json = { workspace = true }
35+
fasteval = { workspace = true }
3036

3137
[dev-dependencies]
3238
criterion = { workspace = true, features = ["cargo_bench_support"] }

compiler/qsc/src/interpret/stateful.rs

+32
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ mod tests;
77
#[cfg(test)]
88
mod stepping_tests;
99

10+
pub mod re;
11+
1012
use super::debug::format_call_stack;
1113
use crate::{
1214
error::{self, WithStack},
@@ -248,6 +250,36 @@ impl Interpreter {
248250
})
249251
}
250252

253+
/// Executes the entry expression until the end of execution, using the given simulator backend
254+
/// and a new instance of the environment.
255+
pub fn eval_entry_with_sim(
256+
&mut self,
257+
sim: &mut impl Backend<ResultType = impl Into<val::Result>>,
258+
receiver: &mut impl Receiver,
259+
) -> Result<Value, Vec<Error>> {
260+
let expr = self.get_entry_expr()?;
261+
let globals = Lookup {
262+
fir_store: &self.fir_store,
263+
};
264+
265+
eval_expr(
266+
&mut self.state,
267+
expr,
268+
&globals,
269+
&mut Env::with_empty_scope(),
270+
sim,
271+
receiver,
272+
)
273+
.map_err(|(error, call_stack)| {
274+
eval_error(
275+
self.compiler.package_store(),
276+
&self.fir_store,
277+
call_stack,
278+
error,
279+
)
280+
})
281+
}
282+
251283
fn get_entry_expr(&self) -> Result<ExprId, Vec<Error>> {
252284
let unit = self
253285
.fir_store
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
mod counts;
5+
mod estimates;
6+
7+
pub use estimates::estimate_physical_resources_from_json;
8+
9+
use crate::interpret::{
10+
stateful::{self, Interpreter},
11+
GenericReceiver,
12+
};
13+
use counts::LogicalCounter;
14+
use estimates::estimate_physical_resources;
15+
use miette::Diagnostic;
16+
use thiserror::Error;
17+
18+
#[derive(Debug)]
19+
pub struct LogicalResources {
20+
pub num_qubits: usize,
21+
pub t_count: usize,
22+
pub rotation_count: usize,
23+
pub rotation_depth: usize,
24+
pub ccz_count: usize,
25+
pub measurement_count: usize,
26+
}
27+
28+
#[derive(Debug, Diagnostic, Error)]
29+
#[error(transparent)]
30+
#[diagnostic(transparent)]
31+
pub enum Error {
32+
Interpreter(stateful::Error),
33+
Estimation(estimates::Error),
34+
}
35+
36+
pub fn estimate_entry(interpreter: &mut Interpreter, params: &str) -> Result<String, Vec<Error>> {
37+
let mut counter = LogicalCounter::default();
38+
let mut stdout = std::io::sink();
39+
let mut out = GenericReceiver::new(&mut stdout);
40+
interpreter
41+
.eval_entry_with_sim(&mut counter, &mut out)
42+
.map_err(|e| e.into_iter().map(Error::Interpreter).collect::<Vec<_>>())?;
43+
estimate_physical_resources(&counter.logical_resources(), params)
44+
.map_err(|e| vec![Error::Estimation(e)])
45+
}
46+
47+
pub fn estimate_expr(
48+
interpreter: &mut Interpreter,
49+
expr: &str,
50+
params: &str,
51+
) -> Result<String, Vec<Error>> {
52+
let mut counter = LogicalCounter::default();
53+
let mut stdout = std::io::sink();
54+
let mut out = GenericReceiver::new(&mut stdout);
55+
interpreter
56+
.run_with_sim(&mut counter, &mut out, expr, 1)
57+
.map_err(|e| e.into_iter().map(Error::Interpreter).collect::<Vec<_>>())?;
58+
estimate_physical_resources(&counter.logical_resources(), params)
59+
.map_err(|e| vec![Error::Estimation(e)])
60+
}

0 commit comments

Comments
 (0)