1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! QASM3 meta program representation and parsing.
//!
//! This module contains structures and enums for representing QASM3 programs as well as a parser.
//! The structures and enums are designed to be convertible to QASM3 string.
//!
//! # Example
//!
//! ```rust
//! use qurust::qasm3::ir;
//! use qurust::qasm3::ir::AsQasmStr;
//!
//! // Generate a random bit program:
//! // ```
//! // OPENQASM 3.0;
//! //
//! // gate h q {
//! // U(pi / 2, 0, pi) q;
//! // gphase(pi / -4);
//! // }
//! //
//! // qubit q;
//! // h q;
//! // bit c = measure q;
//!
//! fn random_bit_program() -> String {
//! ir::Program::new(
//! Some(ir::Version::new("3.0".to_string())),
//! vec![
//! ir::Gate::newt(
//! ir::Identifier::new("h".to_string()),
//! vec![],
//! vec![ir::Identifier::new("q".to_string())],
//! ir::Scope::newt(vec![
//! ir::GateCall::newt(
//! vec![],
//! ir::Identifier::new("U".to_string()),
//! vec![
//! ir::BinaryOperation::newt(
//! ir::BinaryOperator::Div,
//! ir::Identifier::newt("pi".to_string()),
//! ir::Literal::DecimalInteger(2).into(),
//! ),
//! ir::Literal::DecimalInteger(0).into(),
//! ir::Identifier::newt("pi".to_string()),
//! ],
//! None,
//! vec![ir::Identifier::newt("q".to_string())],
//! ),
//! ir::GateCall::newt(
//! vec![],
//! ir::Identifier::new("gphase".to_string()),
//! vec![ir::BinaryOperation::newt(
//! ir::BinaryOperator::Div,
//! ir::Identifier::newt("pi".to_string()),
//! ir::Literal::DecimalInteger(-4).into(),
//! )],
//! None,
//! vec![],
//! ),
//! ]),
//! ),
//! ir::QuantumDeclaration::newt(
//! ir::Qubit::newt(None),
//! ir::Identifier::new("q".to_string()),
//! ),
//! ir::GateCall::newt(
//! vec![],
//! ir::Identifier::new("h".to_string()),
//! vec![],
//! None,
//! vec![ir::Identifier::newt("q".to_string())],
//! ),
//! ir::ClassicalDeclaration::newt(
//! ir::Scalar::Bit(None).into(),
//! ir::Identifier::newt("c".to_string()),
//! Some(ir::Measure::newt(ir::Identifier::newt("q".to_string()))),
//! ),
//! ],
//! ).as_qasm_str()
//! }
//! ```