Skip to content

Commit 2fe6296

Browse files
Adds a python integration test for circuits (#2433)
Also fixes a small capitalization inconsistency in the context menu for circuit editor.
1 parent d07dba0 commit 2fe6296

File tree

3 files changed

+74
-5
lines changed

3 files changed

+74
-5
lines changed

npm/qsharp/ux/circuit-vis/contextMenu.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ const addContextMenuToHostElem = (
7878
circuitEvents.renderFn();
7979
});
8080

81-
const addControlOption = _createContextMenuItem("Add control", () => {
81+
const addControlOption = _createContextMenuItem("Add Control", () => {
8282
if (selectedOperation.kind !== "unitary") return;
8383
circuitEvents._startAddingControl(selectedOperation, selectedLocation);
8484
});
8585

8686
let removeControlOption: HTMLDivElement | undefined;
8787
if (selectedOperation.controls && selectedOperation.controls.length > 0) {
88-
removeControlOption = _createContextMenuItem("Remove control", () => {
88+
removeControlOption = _createContextMenuItem("Remove Control", () => {
8989
circuitEvents._startRemovingControl(selectedOperation);
9090
});
9191
contextMenu.appendChild(removeControlOption);

pip/tests/circuit.qsc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"version": 1,
3+
"circuits": [
4+
{
5+
"qubits": [
6+
{
7+
"id": 0,
8+
"numResults": 1
9+
}
10+
],
11+
"componentGrid": [
12+
{
13+
"components": [
14+
{
15+
"kind": "measurement",
16+
"gate": "Measure",
17+
"qubits": [
18+
{
19+
"qubit": 0
20+
}
21+
],
22+
"results": [
23+
{
24+
"qubit": 0,
25+
"result": 0
26+
}
27+
]
28+
}
29+
]
30+
}
31+
]
32+
}
33+
]
34+
}

pip/tests/test_project.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ def test_github_dependency(qsharp) -> None:
7474
assert result == 12
7575

7676

77+
def test_circuit(qsharp) -> None:
78+
qsharp.init(project_root="/circuit")
79+
result = qsharp.eval("Test.TestCircuit()")
80+
assert result == qsharp.Result.Zero
81+
82+
83+
with open(
84+
os.path.join(os.path.dirname(__file__), "circuit.qsc"), "r", encoding="utf-8"
85+
) as f:
86+
circuit_qsc_contents = f.read()
87+
7788
memfs = {
7889
"": {
7990
"good": {
@@ -141,19 +152,43 @@ def test_github_dependency(qsharp) -> None:
141152
}
142153
}""",
143154
},
155+
"circuit": {
156+
"src": {
157+
"test.qs": "namespace Test {"
158+
" import circuit.circuit;"
159+
" operation TestCircuit() : Result {"
160+
" use qs = Qubit[2];"
161+
" let result = circuit(qs);"
162+
" ResetAll(qs);"
163+
" result"
164+
" }"
165+
"}",
166+
"circuit.qsc": circuit_qsc_contents,
167+
},
168+
"qsharp.json": "{}",
169+
},
144170
}
145171
}
146172

147173

148174
def fetch_github_test(owner: str, repo: str, ref: str, path: str):
149-
if owner == "test-owner" and repo == "test-repo" and ref == "12345" and path == "/qsharp.json":
175+
if (
176+
owner == "test-owner"
177+
and repo == "test-repo"
178+
and ref == "12345"
179+
and path == "/qsharp.json"
180+
):
150181
return """{ "files" : ["src/test.qs"] }"""
151-
if owner == "test-owner" and repo == "test-repo" and ref == "12345" and path == "/src/test.qs":
182+
if (
183+
owner == "test-owner"
184+
and repo == "test-repo"
185+
and ref == "12345"
186+
and path == "/src/test.qs"
187+
):
152188
return "namespace Test { operation ReturnsTwelve() : Int { 12 } export ReturnsTwelve;}"
153189
raise Exception(f"Unexpected fetch_github call: {owner}, {repo}, {ref}, {path}")
154190

155191

156-
157192
def read_file_memfs(path):
158193
global memfs
159194
item = memfs

0 commit comments

Comments
 (0)