Skip to content
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

Basic Circuit Editor for .qsc files #2187

Open
wants to merge 78 commits into
base: main
Choose a base branch
from
Open

Conversation

ScottCarda-MS
Copy link
Contributor

@ScottCarda-MS ScottCarda-MS commented Feb 18, 2025

This PR adds a custom editor view in the VS Code extension for files with the .qsc extension. The editor makes use of the same library code that is used to draw circuit diagrams elsewhere in the VS Code extension. The editor provides basic drag-and-drop editing of circuits with a simple gate set, including the ability to have controlled gates, and gates with arguments.
The circuit files are included in Q# projects and can be called into from Q# as if they were Q# operations. This is done by generating Q# files for circuit files when compiling.

@ScottCarda-MS ScottCarda-MS changed the title WIP Circuit Editor Basic Circuit Editor for .qviz files Feb 24, 2025
@ScottCarda-MS ScottCarda-MS marked this pull request as ready for review February 25, 2025 00:42
gate: "|0〉",
targets: [{ qId: 0, type: RegisterType.Qubit }],
},
ResetX: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think |1> is ResetX. 0 and 1 are in the Z basis. I would have thought ResetX maps to |+>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good point. ResetX does mean something else. I've renamed this to ResetOne.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I realized last night I was wrong here. If a qubit starts in the |0> state, then applying an X does indeed put it into the |1> state. Applying an H puts it into what is commonly called the |+> state which is along the X basis of measurement, which I was getting confused with. Sorry!

"displayName": "Quantum Circuit",
"selector": [
{
"filenamePattern": "*.qviz"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should decide if this is the file extension we want to ship with.

Also, you should add a file icon for whatever extension we add (search on "icon" in this file for existing icons).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to .qsc extension as per discussion. I set the icon to the same as the .qs files. I think we should come up with a unique icon for the circuits in the near future though.

@ScottCarda-MS ScottCarda-MS changed the title Basic Circuit Editor for .qviz files Basic Circuit Editor for .qsc files Mar 5, 2025
/** Array of qubit resources. */
qubits: Qubit[];
operations: Operation[];
operations: Operation[][];
Copy link
Member

@minestarks minestarks Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I dislike array-of-array as a type... for one, multi-dimensional arrays are just annoying to code against. But also, there's usually an intermediate type in there you're hiding, that deserves its own type for clarity.

What does an Operation[] represent? A column, I assume? You can wrap that it its own object:

interface Column { 
    operations: Operation[];
}

This also makes the type more future-proof in case you ever want to add a new property to the column itself (like, what if columns could have annotations? I don't know, just making stuff up)

And then this property here can become

    columns: Column[];

Now when I read the type, it's easier to understand what Operation[] is, rather than try to keep in my head what each layer of the two-dimensional array corresponds to.

@@ -52,15 +71,17 @@ export interface Operation {
/** Formatted gate arguments to be displayed. */
displayArgs?: string;
/** Nested operations within this operation. */
children?: Operation[];
children?: Operation[][];
/** Number of columns to span. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider saying in the comment what the default is if this property is omitted. 1?

/** Whether gate is an adjoint operation. */
isAdjoint: boolean;
isAdjoint?: boolean;
/** Control registers the gate acts on. */
controls?: Register[];
/** Target registers the gate acts on. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, can you put targets at the top below the other required properties? This is the most important property buried beneath all the optional ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants