microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/fix-2145

Branches

Tags

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

Clone

HTTPS

Download ZIP

compiler/qsc_circuit/src/builder/tests.rs

51lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use super::*;
5use expect_test::expect;
6
7#[test]
8fn exceed_max_operations() {
9 let mut builder = Builder::new(Config { max_operations: 2 });
10
11 let q = builder.qubit_allocate();
12
13 builder.x(q);
14 builder.x(q);
15 builder.x(q);
16
17 builder.qubit_release(q);
18
19 let circuit = builder.finish();
20
21 // The current behavior is to silently truncate the circuit
22 // if it exceeds the maximum allowed number of operations.
23 expect![[r#"
24 q_0 ── X ──── X ──
25 "#]]
26 .assert_eq(&circuit.to_string());
27}
28
29#[test]
30fn exceed_max_operations_deferred_measurements() {
31 let mut builder = Builder::new(Config { max_operations: 2 });
32
33 let q = builder.qubit_allocate();
34
35 builder.x(q);
36 builder.m(q);
37 builder.x(q);
38
39 builder.qubit_release(q);
40
41 let circuit = builder.finish();
42
43 // The current behavior is to silently truncate the circuit
44 // if it exceeds the maximum allowed number of operations.
45 // The second X will be dropped.
46 expect![[r#"
47 q_0 ── X ──── M ──
48 ╘═══
49 "#]]
50 .assert_eq(&circuit.to_string());
51}
52