microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
billti/num2-sim

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/resource_estimator/src/lib.rs

80lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! A Q# backend to compute logical overheads to compute the overhead based on
5//! the PSSPC layout method.
6
7// This crate uses lots of converstions between floating point numbers and integers, so this helps
8// avoid many needed allow statements. Comment out individual lines to see where they are needed.
9#![allow(
10 clippy::cast_possible_truncation,
11 clippy::cast_sign_loss,
12 clippy::cast_precision_loss,
13 clippy::cast_lossless
14)]
15
16pub mod counts;
17/// Provides traits to define a fault-tolerant quantum computing architecture
18/// and functions to perform resource estimation on such architectures.
19pub mod estimates;
20/// Models a fault-tolerant quantum computing architecture based on
21/// customizaable gate-based and Majorana qubits, planar codes, and T-factories.
22pub mod system;
23
24pub use system::estimate_physical_resources_from_json;
25
26use counts::LogicalCounter;
27use miette::Diagnostic;
28use qsc::interpret::{self, GenericReceiver, Interpreter, Value};
29use system::estimate_physical_resources;
30use thiserror::Error;
31
32#[derive(Debug, Diagnostic, Error)]
33#[error(transparent)]
34#[diagnostic(transparent)]
35pub enum Error {
36 Interpreter(interpret::Error),
37 Estimation(system::Error),
38}
39
40pub fn estimate_entry(interpreter: &mut Interpreter, params: &str) -> Result<String, Vec<Error>> {
41 let mut counter = LogicalCounter::default();
42 let mut stdout = std::io::sink();
43 let mut out = GenericReceiver::new(&mut stdout);
44 interpreter
45 .eval_entry_with_sim(&mut counter, &mut out)
46 .map_err(|e| e.into_iter().map(Error::Interpreter).collect::<Vec<_>>())?;
47 estimate_physical_resources(counter.logical_resources(), params)
48 .map_err(|e| vec![Error::Estimation(e)])
49}
50
51pub fn estimate_expr(
52 interpreter: &mut Interpreter,
53 expr: &str,
54 params: &str,
55) -> Result<String, Vec<Error>> {
56 let mut counter = LogicalCounter::default();
57 let mut stdout = std::io::sink();
58 let mut out = GenericReceiver::new(&mut stdout);
59 interpreter
60 .run_with_sim(&mut counter, &mut out, Some(expr))
61 .map_err(|e| e.into_iter().map(Error::Interpreter).collect::<Vec<_>>())?;
62 estimate_physical_resources(counter.logical_resources(), params)
63 .map_err(|e| vec![Error::Estimation(e)])
64}
65
66pub fn estimate_call(
67 interpreter: &mut Interpreter,
68 callable: Value,
69 args: Value,
70 params: &str,
71) -> Result<String, Vec<Error>> {
72 let mut counter = LogicalCounter::default();
73 let mut stdout = std::io::sink();
74 let mut out = GenericReceiver::new(&mut stdout);
75 interpreter
76 .invoke_with_sim(&mut counter, &mut out, callable, args)
77 .map_err(|e| e.into_iter().map(Error::Interpreter).collect::<Vec<_>>())?;
78 estimate_physical_resources(counter.logical_resources(), params)
79 .map_err(|e| vec![Error::Estimation(e)])
80}
81