Skip to content

Remove external parser. Fix Qiskit's failure to emit gates. #2284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 9, 2025
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
395 changes: 19 additions & 376 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ ndarray = "0.15.4"
num-bigint = "0.4"
num-complex = "0.4"
num-traits = "0.2"
oq3_source_file = "0.7.0"
oq3_syntax = "0.7.0"
oq3_parser = "0.7.0"
oq3_lexer = "0.7.0"
oq3_semantics = "0.7.0"
probability = "0.20"
indenter = "0.3"
regex-lite = "0.1"
Expand Down
3 changes: 3 additions & 0 deletions compiler/qsc/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub enum ErrorKind {
#[error("Cycle in dependency graph")]
/// `DependencyCycle` occurs when there is a cycle in the dependency graph.
DependencyCycle,

#[diagnostic(transparent)]
OpenQasm(#[from] crate::qasm::error::Error),
}

/// Compiles a package from its AST representation.
Expand Down
5 changes: 1 addition & 4 deletions compiler/qsc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,4 @@ pub mod partial_eval {
pub use qsc_partial_eval::Error;
}

pub mod qasm3 {
pub use qsc_qasm3::parse::*;
pub use qsc_qasm3::*;
}
pub mod qasm;
70 changes: 70 additions & 0 deletions compiler/qsc/src/qasm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

use std::path::Path;

use qsc_qasm3::io::SourceResolver;
pub use qsc_qasm3::CompilerConfig;
pub use qsc_qasm3::OperationSignature;
pub use qsc_qasm3::OutputSemantics;
pub use qsc_qasm3::ProgramType;
pub use qsc_qasm3::QasmCompileUnit;
pub use qsc_qasm3::QubitSemantics;
pub mod io {
pub use qsc_qasm3::io::*;
}
pub mod parser {
pub use qsc_qasm3::parser::*;
}
pub mod error {
pub use qsc_qasm3::Error;
pub use qsc_qasm3::ErrorKind;
}
pub mod completion {
pub use qsc_qasm3::parser::completion::*;
}
pub use qsc_qasm3::compile_to_qsharp_ast_with_config;
pub use qsc_qasm3::package_store_with_qasm;

#[must_use]
pub fn parse_raw_qasm_as_fragments<S, P, R>(
source: S,
path: P,
resolver: Option<&mut R>,
) -> QasmCompileUnit
where
S: AsRef<str>,
P: AsRef<Path>,
R: SourceResolver,
{
let config = CompilerConfig::new(
QubitSemantics::Qiskit,
OutputSemantics::OpenQasm,
ProgramType::Fragments,
None,
None,
);
compile_to_qsharp_ast_with_config(source, path, resolver, config)
}

#[must_use]
pub fn parse_raw_qasm_as_operation<S, P, R>(
source: S,
name: S,
path: P,
resolver: Option<&mut R>,
) -> QasmCompileUnit
where
S: AsRef<str>,
P: AsRef<Path>,
R: SourceResolver,
{
let config = CompilerConfig::new(
QubitSemantics::Qiskit,
OutputSemantics::OpenQasm,
ProgramType::Operation,
Some(name.as_ref().into()),
None,
);
compile_to_qsharp_ast_with_config(source, path, resolver, config)
}
4 changes: 0 additions & 4 deletions compiler/qsc_qasm3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ qsc_parse = { path = "../qsc_parse" }
qsc_passes = { path = "../qsc_passes" }
rustc-hash = { workspace = true }
thiserror = { workspace = true }
oq3_source_file = { workspace = true }
oq3_syntax = { workspace = true }
oq3_parser = { workspace = true }
oq3_semantics = { workspace = true }

[dev-dependencies]
difference = { workspace = true }
Expand Down
Loading