Skip to content

Circuit Editor #2238

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 185 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
185 commits
Select commit Hold shift + click to select a range
e80aec1
(circuits) add circuit_vis directory
minestarks May 9, 2024
2c4d61f
(circuits) prettier circuit_vis
minestarks May 30, 2024
883045a
(circuits) incorporate circuit_vis into build
minestarks May 9, 2024
0f84291
remove some unnecessary files
minestarks Oct 29, 2024
8a3618b
upgrade canvas dep, delete some test code
minestarks Nov 26, 2024
0da1f42
remove canvas dependency
minestarks Jan 15, 2025
b51f078
remove more unwanted dependencies, kill tests
minestarks Jan 15, 2025
3b515d2
Merge branch 'main' of https://github.com/microsoft/qsharp into mines…
minestarks Feb 5, 2025
ad5030f
remove unwanted files
minestarks Feb 5, 2025
fffdd8e
move into qsharp package
minestarks Feb 5, 2025
4de9fb5
revert build.py
minestarks Feb 5, 2025
472432b
remove the last of unnecessary changes
minestarks Feb 5, 2025
3ab1ff3
i lied, one more
minestarks Feb 5, 2025
ac831ec
more
minestarks Feb 5, 2025
0f31206
update package-lock
minestarks Feb 5, 2025
bff3dae
display circuit visual for .circ files
ScottCarda-MS Jan 8, 2025
8bf2124
mock of Q# backend for circ files and integration into Q# projects
ScottCarda-MS Jan 10, 2025
9b7e597
very basic Q# code-gen
ScottCarda-MS Jan 13, 2025
13a7d93
quick changing between qviz and custom editor
ScottCarda-MS Jan 15, 2025
8e780a0
add the custom editor
ScottCarda-MS Jan 15, 2025
f468a84
merge in from other branch
ScottCarda-MS Feb 9, 2025
5d503e3
Add Control context menu
ScottCarda-MS Feb 10, 2025
916eb3b
Remove Control context menu option
ScottCarda-MS Feb 10, 2025
d0a2a80
Add support for gate argument
ScottCarda-MS Feb 10, 2025
cef4d76
Adjoint option and some exceptions for context menu options
ScottCarda-MS Feb 10, 2025
b0f1b6b
Stop constantly trying to read from file
ScottCarda-MS Feb 11, 2025
6d59ac4
Minimize circuits before writing them to file.
ScottCarda-MS Feb 11, 2025
c05f787
updated qsharp generation. Still need to generate Result[] return values
ScottCarda-MS Feb 12, 2025
36a508d
add support for capturing and returning measurement results
ScottCarda-MS Feb 12, 2025
7ff263f
Improved the Toolbox panel UI
ScottCarda-MS Feb 12, 2025
b8ca50b
fixed document events attaching multiple times
ScottCarda-MS Feb 13, 2025
c7c62a7
fixed multiple events attaching to toolbox elements
ScottCarda-MS Feb 13, 2025
6f5fc63
I think I finally fixed the dropzone wires being too persistent
ScottCarda-MS Feb 13, 2025
5a9b896
fixed bug where multiple style nodes would get attached
ScottCarda-MS Feb 13, 2025
7f90a9f
fix bug where generated operation name used the whole path instead of…
ScottCarda-MS Feb 14, 2025
e7a20cc
fixed metadata processing bug
ScottCarda-MS Feb 14, 2025
4a8e93b
.
ScottCarda-MS Feb 14, 2025
ea1b393
Merge branch 'main' into sccarda/MergeMine
ScottCarda-MS Feb 14, 2025
ab08c78
WIP reorganizing and splitting into separate files.
ScottCarda-MS Feb 15, 2025
1eb4f47
reorg
ScottCarda-MS Feb 17, 2025
1a7fb75
little bit of cleanup
ScottCarda-MS Feb 17, 2025
b24bb4a
qviz extensions
ScottCarda-MS Feb 18, 2025
360c5ee
Change to column-based format. Working on displaying based on column …
ScottCarda-MS Feb 18, 2025
f9c63d8
WIP
ScottCarda-MS Feb 18, 2025
f395eeb
try it out with the sample .qviz
ScottCarda-MS Feb 19, 2025
26b6bca
updated Q# generation
ScottCarda-MS Feb 19, 2025
ad72f9a
Update circuit gen from qs logic to bestow column information on gates.
ScottCarda-MS Feb 19, 2025
1c6e0a4
remove commented out code
ScottCarda-MS Feb 19, 2025
e7a72b7
fix issues
ScottCarda-MS Feb 19, 2025
81b2840
Merge branch 'sccarda/MergeMine' into sccarda/formatChange
ScottCarda-MS Feb 19, 2025
8e815af
updated dropzones
ScottCarda-MS Feb 21, 2025
32babdd
added version to circuit format
ScottCarda-MS Feb 23, 2025
2161b74
move dropzones around
ScottCarda-MS Feb 23, 2025
5a4b6c0
remove dropzone borders
ScottCarda-MS Feb 23, 2025
186b43a
delete op if dragged out of circuit, and control too
ScottCarda-MS Feb 23, 2025
917bd02
fixed some issues with delete by dragging
ScottCarda-MS Feb 24, 2025
3d6aa9c
properly move measure gates
ScottCarda-MS Feb 24, 2025
1fff9a6
fix bug with zoom
ScottCarda-MS Feb 24, 2025
2580b25
Fix bug with rendering ghost control dot
ScottCarda-MS Feb 24, 2025
7b5f16e
disable zoom for editor
ScottCarda-MS Feb 24, 2025
c1f196d
update draggable logic
ScottCarda-MS Feb 24, 2025
be17942
WIP: qViz format change (#2188)
ScottCarda-MS Feb 24, 2025
8359a2f
clean up
ScottCarda-MS Feb 24, 2025
faf4f90
remove dev file
ScottCarda-MS Feb 24, 2025
36dba9b
Merge branch 'main' into sccarda/MergeMine
ScottCarda-MS Feb 24, 2025
e88caa4
provide default version for rust code
ScottCarda-MS Feb 24, 2025
fc7471f
fix edit argument input
ScottCarda-MS Feb 25, 2025
e9cb55d
Allow for empty circuits to be rendered in edit mode.
ScottCarda-MS Feb 26, 2025
83ab637
If there is no circuit in the qviz file, write an empty circuit to th…
ScottCarda-MS Feb 26, 2025
c66f625
quibt's num_children should be optional
ScottCarda-MS Feb 26, 2025
b39d728
Include ket gates in toolbox
ScottCarda-MS Feb 26, 2025
1291c24
Sample using circuit file
ScottCarda-MS Feb 27, 2025
8d21ac4
don't zoom on open for editor
ScottCarda-MS Feb 27, 2025
41c68fd
Merge branch 'main' into sccarda/MergeMine
ScottCarda-MS Mar 3, 2025
f34ca88
WIP new circuit format
ScottCarda-MS Mar 3, 2025
133fcb5
updates to the CircuitIntegration sample
ScottCarda-MS Mar 4, 2025
4009f7f
ResetX -> ResetOne in gate dictionary
ScottCarda-MS Mar 5, 2025
b6e48df
qviz -> qsc and give .qsc files icon
ScottCarda-MS Mar 5, 2025
b75abc9
moved sample out of algorithms
ScottCarda-MS Mar 5, 2025
fdca7d8
CircuitGroup
ScottCarda-MS Mar 7, 2025
859943d
circuitgroup drop name and version becomes number
ScottCarda-MS Mar 7, 2025
7477488
Component Grid
ScottCarda-MS Mar 7, 2025
ae2ecec
updates to Qubit and Register
ScottCarda-MS Mar 7, 2025
deb9acf
multiple args and drop isControlled
ScottCarda-MS Mar 8, 2025
65eb873
fixed nested if
ScottCarda-MS Mar 10, 2025
f83a325
clearifying comment
ScottCarda-MS Mar 10, 2025
2996374
separate measurements away from operations
ScottCarda-MS Mar 10, 2025
6d16628
Revert "separate measurements away from operations"
ScottCarda-MS Mar 11, 2025
0ffa43a
Operations break down into Unitary and Measurement
ScottCarda-MS Mar 11, 2025
9c2bece
camelcase for Operation kinds
ScottCarda-MS Mar 11, 2025
7222abf
Sccarda/separate measurements (#2218)
ScottCarda-MS Mar 12, 2025
b162299
Merge branch 'sccarda/MergeMine' into sccarda/updateCircuitFormat
ScottCarda-MS Mar 12, 2025
d14c099
update sample to new format
ScottCarda-MS Mar 12, 2025
2be0a45
WIP started to update the rust code with the new format
ScottCarda-MS Mar 12, 2025
65b79f9
WIP updating the Q# gen code for circuits to use the updated schema
ScottCarda-MS Mar 12, 2025
08dd923
handle circuit groups an auto-detect adj and ctl for generated ops
ScottCarda-MS Mar 12, 2025
a1e25a1
finished fixing tests
ScottCarda-MS Mar 13, 2025
2cb3d8d
updated qsharp generation tests
ScottCarda-MS Mar 13, 2025
250c8d6
fixed bug where context menu didn't respect window scroll
ScottCarda-MS Mar 13, 2025
4cca6ec
WIP drag-n-drop bug fix
ScottCarda-MS Mar 13, 2025
4e66087
Prevent move from ignoring controls and their control lines
ScottCarda-MS Mar 13, 2025
88417c0
Fixed some of the moving logic for controls
ScottCarda-MS Mar 14, 2025
f081c6c
prevent operations from moving onto existing controls/targets
ScottCarda-MS Mar 14, 2025
dfda099
Merge branch 'sccarda/MergeMine' into sccarda/updateCircuitFormat
ScottCarda-MS Mar 14, 2025
4934efb
Hopefully actually fixed measurement movement issues.
ScottCarda-MS Mar 14, 2025
578d4ad
Change Q# gen to gen ops with Qubit registers than individual qubit p…
ScottCarda-MS Mar 17, 2025
53ad470
Only rotation gates can have args (or any operation that requires par…
ScottCarda-MS Mar 19, 2025
6dba6e7
automatically prompt users for required arguments
ScottCarda-MS Mar 19, 2025
03e1b43
fix bug in sample
ScottCarda-MS Mar 19, 2025
11f23b5
generated Q# can accommodate pi character.
ScottCarda-MS Mar 19, 2025
ee080d0
pi button to argument prompt and placeholder validation
ScottCarda-MS Mar 19, 2025
819349b
Displayed args are clickable to prompt user for edit
ScottCarda-MS Mar 20, 2025
f5ae567
update the css styles to respect vscode themes
ScottCarda-MS Mar 20, 2025
ce21e5b
placeholder text for the argument input
ScottCarda-MS Mar 20, 2025
6899965
Make Ket gates match appearance to measurement gates
ScottCarda-MS Mar 21, 2025
26c9fef
move an operation if trying to add a control on top of existing opera…
ScottCarda-MS Mar 24, 2025
731044a
add a confirmation dialog if the user is about to remove a qubit with…
ScottCarda-MS Mar 24, 2025
0e81837
validate input arguments to be arithmetic expressions (no parens supp…
ScottCarda-MS Mar 24, 2025
8285902
validation logic with parentheses
ScottCarda-MS Mar 24, 2025
f027f12
Language server is activated on changes to the circuit file.
ScottCarda-MS Mar 26, 2025
85fc02f
fixed some css issues with dark high contrast theme
ScottCarda-MS Mar 26, 2025
5c2a7f7
Undo Redo logic enabled by back-and-forth communication between webvi…
ScottCarda-MS Mar 27, 2025
5f07beb
use the document version to prevent unnecessary doc update
ScottCarda-MS Mar 27, 2025
256bda2
fix a couple of style issues
ScottCarda-MS Mar 28, 2025
c172b83
Merge branch 'main' into sccarda/circuitEditor
ScottCarda-MS Apr 1, 2025
0115fa5
Export CircuitGroup and use it as the base data structure for vscode
ScottCarda-MS Apr 2, 2025
1f6833a
Allow the Circuit widget to accept Circuit json instead of CircuitGro…
ScottCarda-MS Apr 2, 2025
b7981a2
Back compat conversion for legacy schema in the widget.
ScottCarda-MS Apr 2, 2025
14cf473
fix test
ScottCarda-MS Apr 3, 2025
899afa1
small changes
ScottCarda-MS Apr 3, 2025
c98cdd6
missed one
ScottCarda-MS Apr 3, 2025
492082c
small updates and remove spacing at top of editor
ScottCarda-MS Apr 3, 2025
ff3ab62
Allow for auto-scrolling while dragging gates.
ScottCarda-MS Apr 4, 2025
d578956
Populate qsharp.json command now supports getting qsc files.
ScottCarda-MS Apr 4, 2025
aa67130
PR feedback
ScottCarda-MS Apr 4, 2025
e29dfab
resolved some of the cargo warnings
ScottCarda-MS Apr 4, 2025
97f56a9
split up large functions in rust
ScottCarda-MS Apr 7, 2025
43913f3
make "ket" gates their own category separate from unitary gates
ScottCarda-MS Apr 7, 2025
4b73198
disable updating the GUI from the text doc dynamically
ScottCarda-MS Apr 7, 2025
bb026e7
Move toolbox to the left of screen, and have the circuits scroll inde…
ScottCarda-MS Apr 8, 2025
c96320e
update short-circuit logic for writing to text document
ScottCarda-MS Apr 8, 2025
869e8b4
fixed bug where confirm dialog was not getting focus
ScottCarda-MS Apr 8, 2025
c3ef5fe
Added the SX gate
ScottCarda-MS Apr 9, 2025
85be205
Merge branch 'main' into sccarda/circuitEditor
ScottCarda-MS Apr 9, 2025
2bc6cfb
use 𝜓 instead of ket-zero for input labels
ScottCarda-MS Apr 9, 2025
c00cdd8
change decomp of SX to HSH
ScottCarda-MS Apr 9, 2025
b0b649d
fixed ket representaion in ascii circuits
ScottCarda-MS Apr 9, 2025
cf62b21
changed language id to qsharpcircuit
ScottCarda-MS Apr 9, 2025
7ad3892
dealt with ToDo's
ScottCarda-MS Apr 9, 2025
52bd5d0
Removed "Circuit" from the title
ScottCarda-MS Apr 9, 2025
56305bf
minor change
ScottCarda-MS Apr 9, 2025
4343c1c
camel_case
ScottCarda-MS Apr 9, 2025
320d16c
simplified some of the circuit builder functions
ScottCarda-MS Apr 9, 2025
8a8dfbe
updated places that referred to both .qs and .qsc files
ScottCarda-MS Apr 9, 2025
d18d0a7
Make version on circuit group mandatory
ScottCarda-MS Apr 10, 2025
e8148aa
removed redundancy
ScottCarda-MS Apr 10, 2025
56c3d48
fixed test with missing version
ScottCarda-MS Apr 10, 2025
1c4e45e
undo de-duplication of stylesheet function
ScottCarda-MS Apr 10, 2025
f34fc0a
Move the wrapping of circuit into circuit group out of wasm into npm
ScottCarda-MS Apr 10, 2025
bb8b4cf
isQsharpDocuement returns true for circuit files
ScottCarda-MS Apr 10, 2025
bbd08c7
some minor changes
ScottCarda-MS Apr 10, 2025
62aa8cd
Changed Rest to Ket for Metadata Gate Type
ScottCarda-MS Apr 10, 2025
662f329
telemetry for circuit files
ScottCarda-MS Apr 11, 2025
0d58818
Merge branch 'main' into sccarda/circuitEditor
ScottCarda-MS Apr 11, 2025
b0fd785
fix bad auto-merge
ScottCarda-MS Apr 11, 2025
32c1cb4
remove injected style node
ScottCarda-MS Apr 11, 2025
8e8c098
generalized setThemeStylesheet
ScottCarda-MS Apr 11, 2025
22a1201
unit tests for projects with circuits in them
ScottCarda-MS Apr 12, 2025
42ddd7d
Removed the extensions mechanism for extending Sqore.
ScottCarda-MS Apr 14, 2025
dd015f5
ghost opacity reduced
ScottCarda-MS Apr 14, 2025
e20d9ed
fix line endings on test case
ScottCarda-MS Apr 14, 2025
7aa7a3c
added json to circuits logic in the rust layer
ScottCarda-MS Apr 14, 2025
844f5d1
improvements to file sync
ScottCarda-MS Apr 15, 2025
c30cd6f
prevent leading radix in arg input
ScottCarda-MS Apr 15, 2025
d6a9146
added some width to the end of circuits for gates to be dragged onto
ScottCarda-MS Apr 15, 2025
9edca60
allow "pi" to be entered for arugment input
ScottCarda-MS Apr 15, 2025
0293bc8
do not focus the cancel button in confirm dialog
ScottCarda-MS Apr 15, 2025
ad88e38
ctrl-draving a control will move the operation and add a control to it
ScottCarda-MS Apr 16, 2025
7901569
Move the legacy circuit update logic to its own file outside of the u…
ScottCarda-MS Apr 16, 2025
8963035
remove debug logging from circuit editor
ScottCarda-MS Apr 16, 2025
d851081
Handle error message in vscode better
ScottCarda-MS Apr 16, 2025
408822d
changed where conversion to Q# from circuits is called to avoid expos…
ScottCarda-MS Apr 16, 2025
ba2b17a
change utils.ts to theme.ts
ScottCarda-MS Apr 17, 2025
805a632
remove "exclude_regexes"
ScottCarda-MS Apr 17, 2025
bcedd4c
rename handle to generate call methods
ScottCarda-MS Apr 17, 2025
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions compiler/qsc/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ pub enum ErrorKind {
#[error("Cycle in dependency graph")]
/// `DependencyCycle` occurs when there is a cycle in the dependency graph.
DependencyCycle,

#[error("{0}")]
/// `CircuitParse` variant represents errors that occur while parsing circuit files.
CircuitParse(String),
}

/// Compiles a package from its AST representation.
Expand Down
3 changes: 2 additions & 1 deletion compiler/qsc/src/interpret/circuit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ fn custom_intrinsic_mixed_args() {
"]]
.assert_eq(&circ.to_string());

assert_eq!(circ.operations.len(), 1);
assert_eq!(circ.component_grid.len(), 1);
assert_eq!(circ.component_grid[0].components.len(), 1);
}

#[test]
Expand Down
5 changes: 4 additions & 1 deletion compiler/qsc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ pub mod linter {
pub use qsc_doc_gen::{display, generate_docs};

pub mod circuit {
pub use qsc_circuit::{operations::*, Circuit, Operation};
pub use qsc_circuit::{
circuit_to_qsharp::circuits_to_qsharp, json_to_circuit::json_to_circuits, operations::*,
Circuit, CircuitGroup, Operation, CURRENT_VERSION,
};
}

pub mod parse {
Expand Down
57 changes: 53 additions & 4 deletions compiler/qsc/src/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// Licensed under the MIT License.

use crate::{
compile::{self, ErrorKind},
compile::{self, Error, ErrorKind},
hir::PackageId,
PackageStore, TargetCapabilityFlags,
};
use qsc_circuit::circuit_to_qsharp::circuits_to_qsharp;
use qsc_data_structures::language_features::LanguageFeatures;
use qsc_frontend::compile::SourceMap;
use qsc_passes::PackageType;
Expand Down Expand Up @@ -36,6 +37,44 @@ impl BuildableProgram {
}
}

/// Converts circuit files to Q# source code.
fn convert_circuit_sources(
sources: Vec<(Arc<str>, Arc<str>)>,
errors: &mut Vec<Error>,
) -> Vec<(Arc<str>, Arc<str>)> {
let mut processed_sources: Vec<(Arc<str>, Arc<str>)> = Vec::new();

for (name, content) in sources {
let name_path = std::path::Path::new(name.as_ref());

// Check if the file extension is "qsc"
if name_path.extension().and_then(|ext| ext.to_str()) == Some("qsc") {
let file_stem = name_path
.file_stem()
.and_then(|stem| stem.to_str())
.unwrap_or(name.as_ref());

// Convert circuit files to Q# source code
match circuits_to_qsharp(file_stem, content.as_ref()) {
Ok(transformed_content) => {
processed_sources.push((name, Arc::from(transformed_content)));
}
Err(error_message) => {
errors.push(Error::from_map(
&SourceMap::default(),
ErrorKind::CircuitParse(error_message),
));
}
}
} else {
// Leave other files unchanged
processed_sources.push((name, content));
}
}

processed_sources
}

/// Given a program config, prepare the package store by compiling all dependencies in the correct order and inserting them.
#[must_use]
pub fn prepare_package_store(
Expand All @@ -54,16 +93,16 @@ pub fn prepare_package_store(
} else {
// If there was a cycle in the dependencies, we treat the compilation as if
// there were no dependencies, and report the error upwards
dependency_errors.push(qsc_frontend::error::WithSource::from_map(
dependency_errors.push(Error::from_map(
&SourceMap::default(),
ErrorKind::DependencyCycle,
));
vec![]
};

for (package_name, package_to_compile) in ordered_packages {
let sources: Vec<(Arc<str>, Arc<str>)> =
package_to_compile.sources.into_iter().collect::<Vec<_>>();
let sources = convert_circuit_sources(package_to_compile.sources, &mut dependency_errors);

let source_map = SourceMap::new(sources, None);
let dependencies = package_to_compile
.dependencies
Expand Down Expand Up @@ -97,6 +136,16 @@ pub fn prepare_package_store(
canonical_package_identifier_to_package_id_mapping.insert(package_name, package_id);
}

// Convert circuit files in user code to generated Q#
let converted_user_code_sources =
convert_circuit_sources(user_code.sources, &mut dependency_errors);
let user_code = qsc_project::PackageInfo {
sources: converted_user_code_sources,
language_features: user_code.language_features,
dependencies: user_code.dependencies,
package_type: user_code.package_type,
};

let user_code_dependencies = user_code
.dependencies
.iter()
Expand Down
4 changes: 4 additions & 0 deletions compiler/qsc_circuit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ qsc_data_structures = { path = "../qsc_data_structures" }
qsc_frontend = { path = "../qsc_frontend" }
qsc_fir = { path = "../qsc_fir" }
qsc_hir = { path = "../qsc_hir" }
regex-lite = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
Expand All @@ -29,5 +30,8 @@ expect-test = { workspace = true }
indoc = { workspace = true }
qsc_passes = { path = "../qsc_passes" }

[lints]
workspace = true

[lib]
doctest = false
Loading
Loading