pub struct Process { /* private fields */ }
Implementations§
Source§impl Process
impl Process
Sourcepub fn new(configuration: Configuration) -> Self
pub fn new(configuration: Configuration) -> Self
Examples found in repository?
examples/qft.rs (line 53)
36fn main() -> Result<(), KetError> {
37 let config = Configuration {
38 num_qubits: 12,
39 qpu: Some(QPU::new(
40 // 0--1--2--3
41 // | | | |
42 // 4--5--6--7
43 // | | | |
44 // 8--9--A--B
45 Some(ket::ex_arch::GRID12.to_vec()),
46 12,
47 U2Gates::RzSx,
48 U4Gate::CX,
49 )),
50 ..Default::default()
51 };
52
53 let mut process = Process::new(config);
54
55 let size = 12;
56 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
57
58 qft(&mut process, &qubits, true)?;
59
60 process.transpile();
61
62 println!("{:#?}", process.metadata());
63
64 Ok(())
65}
More examples
examples/mcx.rs (line 44)
7fn main() -> Result<(), KetError> {
8 set_log_level(4);
9
10 let config = Configuration {
11 num_qubits: 12,
12 qpu: Some(QPU::new(
13 // 0--1--2--3
14 // | | | |
15 // 4--5--6--7
16 // | | | |
17 // 8--9--A--B
18 Some(vec![
19 (0, 4),
20 (0, 1),
21 (1, 2),
22 (1, 5),
23 (2, 3),
24 (2, 6),
25 (3, 7),
26 (4, 8),
27 (4, 5),
28 (5, 9),
29 (5, 6),
30 (6, 10),
31 (6, 7),
32 (7, 11),
33 (8, 9),
34 (9, 10),
35 (10, 11),
36 ]),
37 12,
38 Default::default(),
39 Default::default(),
40 )),
41 ..Default::default()
42 };
43
44 let mut process = Process::new(config);
45
46 let size = 6;
47
48 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
49 ctrl(&mut process, &qubits[1..], |process| {
50 process.gate(QuantumGate::PauliZ, qubits[0])
51 })?;
52
53 let _ = process.sample(&qubits, 1024)?;
54 process.transpile();
55
56 println!("Instructions:");
57 for line in process.instructions() {
58 println!("\t{:?}", line);
59 }
60
61 println!("ISA Instructions:");
62 if let Some(isa) = process.isa_instructions() {
63 for line in isa {
64 println!("\t{:?}", line);
65 }
66 }
67
68 Ok(())
69}
examples/grover.rs (line 28)
9fn main() -> Result<(), KetError> {
10 set_log_level(3);
11
12 let config = Configuration {
13 num_qubits: 12,
14 qpu: Some(QPU::new(
15 // 0--1--2--3
16 // | | | |
17 // 4--5--6--7
18 // | | | |
19 // 8--9--A--B
20 Some(ket::ex_arch::GRID12.to_vec()),
21 12,
22 U2Gates::RzSx,
23 U4Gate::CZ,
24 )),
25 ..Default::default()
26 };
27
28 let mut process = Process::new(config);
29
30 let size = 8;
31
32 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
33
34 for qubit in &qubits {
35 process.gate(QuantumGate::Hadamard, *qubit)?;
36 }
37
38 let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;
39
40 for _ in 0..steps {
41 around(
42 &mut process,
43 |process| {
44 for qubit in &qubits {
45 process.gate(QuantumGate::PauliX, *qubit)?;
46 }
47 Ok(())
48 },
49 |process| {
50 ctrl(process, &qubits[1..], |process| {
51 process.gate(QuantumGate::PauliZ, qubits[0])
52 })
53 },
54 )?;
55
56 around(
57 &mut process,
58 |process| {
59 for qubit in &qubits {
60 process.gate(QuantumGate::Hadamard, *qubit)?;
61 }
62
63 for qubit in &qubits {
64 process.gate(QuantumGate::PauliX, *qubit)?;
65 }
66 Ok(())
67 },
68 |process| {
69 ctrl(process, &qubits[1..], |process| {
70 process.gate(QuantumGate::PauliZ, qubits[0])
71 })
72 },
73 )?;
74 }
75
76 let _ = process.sample(&qubits, 1024)?;
77 process.transpile();
78
79 println!("{:#?}", process.metadata());
80
81 Ok(())
82}
Sourcepub fn alloc(&mut self) -> Result<LogicalQubit>
pub fn alloc(&mut self) -> Result<LogicalQubit>
Examples found in repository?
examples/qft.rs (line 56)
36fn main() -> Result<(), KetError> {
37 let config = Configuration {
38 num_qubits: 12,
39 qpu: Some(QPU::new(
40 // 0--1--2--3
41 // | | | |
42 // 4--5--6--7
43 // | | | |
44 // 8--9--A--B
45 Some(ket::ex_arch::GRID12.to_vec()),
46 12,
47 U2Gates::RzSx,
48 U4Gate::CX,
49 )),
50 ..Default::default()
51 };
52
53 let mut process = Process::new(config);
54
55 let size = 12;
56 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
57
58 qft(&mut process, &qubits, true)?;
59
60 process.transpile();
61
62 println!("{:#?}", process.metadata());
63
64 Ok(())
65}
More examples
examples/mcx.rs (line 48)
7fn main() -> Result<(), KetError> {
8 set_log_level(4);
9
10 let config = Configuration {
11 num_qubits: 12,
12 qpu: Some(QPU::new(
13 // 0--1--2--3
14 // | | | |
15 // 4--5--6--7
16 // | | | |
17 // 8--9--A--B
18 Some(vec![
19 (0, 4),
20 (0, 1),
21 (1, 2),
22 (1, 5),
23 (2, 3),
24 (2, 6),
25 (3, 7),
26 (4, 8),
27 (4, 5),
28 (5, 9),
29 (5, 6),
30 (6, 10),
31 (6, 7),
32 (7, 11),
33 (8, 9),
34 (9, 10),
35 (10, 11),
36 ]),
37 12,
38 Default::default(),
39 Default::default(),
40 )),
41 ..Default::default()
42 };
43
44 let mut process = Process::new(config);
45
46 let size = 6;
47
48 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
49 ctrl(&mut process, &qubits[1..], |process| {
50 process.gate(QuantumGate::PauliZ, qubits[0])
51 })?;
52
53 let _ = process.sample(&qubits, 1024)?;
54 process.transpile();
55
56 println!("Instructions:");
57 for line in process.instructions() {
58 println!("\t{:?}", line);
59 }
60
61 println!("ISA Instructions:");
62 if let Some(isa) = process.isa_instructions() {
63 for line in isa {
64 println!("\t{:?}", line);
65 }
66 }
67
68 Ok(())
69}
examples/grover.rs (line 32)
9fn main() -> Result<(), KetError> {
10 set_log_level(3);
11
12 let config = Configuration {
13 num_qubits: 12,
14 qpu: Some(QPU::new(
15 // 0--1--2--3
16 // | | | |
17 // 4--5--6--7
18 // | | | |
19 // 8--9--A--B
20 Some(ket::ex_arch::GRID12.to_vec()),
21 12,
22 U2Gates::RzSx,
23 U4Gate::CZ,
24 )),
25 ..Default::default()
26 };
27
28 let mut process = Process::new(config);
29
30 let size = 8;
31
32 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
33
34 for qubit in &qubits {
35 process.gate(QuantumGate::Hadamard, *qubit)?;
36 }
37
38 let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;
39
40 for _ in 0..steps {
41 around(
42 &mut process,
43 |process| {
44 for qubit in &qubits {
45 process.gate(QuantumGate::PauliX, *qubit)?;
46 }
47 Ok(())
48 },
49 |process| {
50 ctrl(process, &qubits[1..], |process| {
51 process.gate(QuantumGate::PauliZ, qubits[0])
52 })
53 },
54 )?;
55
56 around(
57 &mut process,
58 |process| {
59 for qubit in &qubits {
60 process.gate(QuantumGate::Hadamard, *qubit)?;
61 }
62
63 for qubit in &qubits {
64 process.gate(QuantumGate::PauliX, *qubit)?;
65 }
66 Ok(())
67 },
68 |process| {
69 ctrl(process, &qubits[1..], |process| {
70 process.gate(QuantumGate::PauliZ, qubits[0])
71 })
72 },
73 )?;
74 }
75
76 let _ = process.sample(&qubits, 1024)?;
77 process.transpile();
78
79 println!("{:#?}", process.metadata());
80
81 Ok(())
82}
Sourcepub fn gate(&mut self, gate: QuantumGate, target: LogicalQubit) -> Result<()>
pub fn gate(&mut self, gate: QuantumGate, target: LogicalQubit) -> Result<()>
Examples found in repository?
examples/qft.rs (line 11)
9fn qft(process: &mut Process, qubits: &[LogicalQubit], do_swap: bool) -> Result<(), KetError> {
10 if qubits.len() == 1 {
11 return process.gate(QuantumGate::Hadamard, qubits[0]);
12 }
13
14 let init = &qubits[..qubits.len() - 1];
15 let last = qubits[qubits.len() - 1];
16 process.gate(QuantumGate::Hadamard, last)?;
17 for (i, c) in init.iter().enumerate() {
18 c1gate(
19 process,
20 QuantumGate::Phase(PI / 2.0_f64.powi(i as i32 + 1)),
21 *c,
22 last,
23 )?;
24 }
25 qft(process, init, false)?;
26
27 if do_swap {
28 for i in 0..qubits.len() / 2 {
29 swap(process, qubits[i], qubits[qubits.len() - i - 1])?;
30 }
31 }
32
33 Ok(())
34}
More examples
examples/mcx.rs (line 50)
7fn main() -> Result<(), KetError> {
8 set_log_level(4);
9
10 let config = Configuration {
11 num_qubits: 12,
12 qpu: Some(QPU::new(
13 // 0--1--2--3
14 // | | | |
15 // 4--5--6--7
16 // | | | |
17 // 8--9--A--B
18 Some(vec![
19 (0, 4),
20 (0, 1),
21 (1, 2),
22 (1, 5),
23 (2, 3),
24 (2, 6),
25 (3, 7),
26 (4, 8),
27 (4, 5),
28 (5, 9),
29 (5, 6),
30 (6, 10),
31 (6, 7),
32 (7, 11),
33 (8, 9),
34 (9, 10),
35 (10, 11),
36 ]),
37 12,
38 Default::default(),
39 Default::default(),
40 )),
41 ..Default::default()
42 };
43
44 let mut process = Process::new(config);
45
46 let size = 6;
47
48 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
49 ctrl(&mut process, &qubits[1..], |process| {
50 process.gate(QuantumGate::PauliZ, qubits[0])
51 })?;
52
53 let _ = process.sample(&qubits, 1024)?;
54 process.transpile();
55
56 println!("Instructions:");
57 for line in process.instructions() {
58 println!("\t{:?}", line);
59 }
60
61 println!("ISA Instructions:");
62 if let Some(isa) = process.isa_instructions() {
63 for line in isa {
64 println!("\t{:?}", line);
65 }
66 }
67
68 Ok(())
69}
examples/grover.rs (line 35)
9fn main() -> Result<(), KetError> {
10 set_log_level(3);
11
12 let config = Configuration {
13 num_qubits: 12,
14 qpu: Some(QPU::new(
15 // 0--1--2--3
16 // | | | |
17 // 4--5--6--7
18 // | | | |
19 // 8--9--A--B
20 Some(ket::ex_arch::GRID12.to_vec()),
21 12,
22 U2Gates::RzSx,
23 U4Gate::CZ,
24 )),
25 ..Default::default()
26 };
27
28 let mut process = Process::new(config);
29
30 let size = 8;
31
32 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
33
34 for qubit in &qubits {
35 process.gate(QuantumGate::Hadamard, *qubit)?;
36 }
37
38 let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;
39
40 for _ in 0..steps {
41 around(
42 &mut process,
43 |process| {
44 for qubit in &qubits {
45 process.gate(QuantumGate::PauliX, *qubit)?;
46 }
47 Ok(())
48 },
49 |process| {
50 ctrl(process, &qubits[1..], |process| {
51 process.gate(QuantumGate::PauliZ, qubits[0])
52 })
53 },
54 )?;
55
56 around(
57 &mut process,
58 |process| {
59 for qubit in &qubits {
60 process.gate(QuantumGate::Hadamard, *qubit)?;
61 }
62
63 for qubit in &qubits {
64 process.gate(QuantumGate::PauliX, *qubit)?;
65 }
66 Ok(())
67 },
68 |process| {
69 ctrl(process, &qubits[1..], |process| {
70 process.gate(QuantumGate::PauliZ, qubits[0])
71 })
72 },
73 )?;
74 }
75
76 let _ = process.sample(&qubits, 1024)?;
77 process.transpile();
78
79 println!("{:#?}", process.metadata());
80
81 Ok(())
82}
pub fn global_phase(&mut self, angle: f64) -> Result<()>
pub fn measure(&mut self, qubits: &[LogicalQubit]) -> Result<usize>
Sourcepub fn sample(&mut self, qubits: &[LogicalQubit], shots: usize) -> Result<usize>
pub fn sample(&mut self, qubits: &[LogicalQubit], shots: usize) -> Result<usize>
Examples found in repository?
examples/mcx.rs (line 53)
7fn main() -> Result<(), KetError> {
8 set_log_level(4);
9
10 let config = Configuration {
11 num_qubits: 12,
12 qpu: Some(QPU::new(
13 // 0--1--2--3
14 // | | | |
15 // 4--5--6--7
16 // | | | |
17 // 8--9--A--B
18 Some(vec![
19 (0, 4),
20 (0, 1),
21 (1, 2),
22 (1, 5),
23 (2, 3),
24 (2, 6),
25 (3, 7),
26 (4, 8),
27 (4, 5),
28 (5, 9),
29 (5, 6),
30 (6, 10),
31 (6, 7),
32 (7, 11),
33 (8, 9),
34 (9, 10),
35 (10, 11),
36 ]),
37 12,
38 Default::default(),
39 Default::default(),
40 )),
41 ..Default::default()
42 };
43
44 let mut process = Process::new(config);
45
46 let size = 6;
47
48 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
49 ctrl(&mut process, &qubits[1..], |process| {
50 process.gate(QuantumGate::PauliZ, qubits[0])
51 })?;
52
53 let _ = process.sample(&qubits, 1024)?;
54 process.transpile();
55
56 println!("Instructions:");
57 for line in process.instructions() {
58 println!("\t{:?}", line);
59 }
60
61 println!("ISA Instructions:");
62 if let Some(isa) = process.isa_instructions() {
63 for line in isa {
64 println!("\t{:?}", line);
65 }
66 }
67
68 Ok(())
69}
More examples
examples/grover.rs (line 76)
9fn main() -> Result<(), KetError> {
10 set_log_level(3);
11
12 let config = Configuration {
13 num_qubits: 12,
14 qpu: Some(QPU::new(
15 // 0--1--2--3
16 // | | | |
17 // 4--5--6--7
18 // | | | |
19 // 8--9--A--B
20 Some(ket::ex_arch::GRID12.to_vec()),
21 12,
22 U2Gates::RzSx,
23 U4Gate::CZ,
24 )),
25 ..Default::default()
26 };
27
28 let mut process = Process::new(config);
29
30 let size = 8;
31
32 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
33
34 for qubit in &qubits {
35 process.gate(QuantumGate::Hadamard, *qubit)?;
36 }
37
38 let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;
39
40 for _ in 0..steps {
41 around(
42 &mut process,
43 |process| {
44 for qubit in &qubits {
45 process.gate(QuantumGate::PauliX, *qubit)?;
46 }
47 Ok(())
48 },
49 |process| {
50 ctrl(process, &qubits[1..], |process| {
51 process.gate(QuantumGate::PauliZ, qubits[0])
52 })
53 },
54 )?;
55
56 around(
57 &mut process,
58 |process| {
59 for qubit in &qubits {
60 process.gate(QuantumGate::Hadamard, *qubit)?;
61 }
62
63 for qubit in &qubits {
64 process.gate(QuantumGate::PauliX, *qubit)?;
65 }
66 Ok(())
67 },
68 |process| {
69 ctrl(process, &qubits[1..], |process| {
70 process.gate(QuantumGate::PauliZ, qubits[0])
71 })
72 },
73 )?;
74 }
75
76 let _ = process.sample(&qubits, 1024)?;
77 process.transpile();
78
79 println!("{:#?}", process.metadata());
80
81 Ok(())
82}
pub fn exp_value( &mut self, hamiltonian: Hamiltonian<LogicalQubit>, ) -> Result<usize>
pub fn dump(&mut self, qubits: &[LogicalQubit]) -> Result<usize>
Sourcepub fn transpile(&mut self)
pub fn transpile(&mut self)
Examples found in repository?
examples/qft.rs (line 60)
36fn main() -> Result<(), KetError> {
37 let config = Configuration {
38 num_qubits: 12,
39 qpu: Some(QPU::new(
40 // 0--1--2--3
41 // | | | |
42 // 4--5--6--7
43 // | | | |
44 // 8--9--A--B
45 Some(ket::ex_arch::GRID12.to_vec()),
46 12,
47 U2Gates::RzSx,
48 U4Gate::CX,
49 )),
50 ..Default::default()
51 };
52
53 let mut process = Process::new(config);
54
55 let size = 12;
56 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
57
58 qft(&mut process, &qubits, true)?;
59
60 process.transpile();
61
62 println!("{:#?}", process.metadata());
63
64 Ok(())
65}
More examples
examples/mcx.rs (line 54)
7fn main() -> Result<(), KetError> {
8 set_log_level(4);
9
10 let config = Configuration {
11 num_qubits: 12,
12 qpu: Some(QPU::new(
13 // 0--1--2--3
14 // | | | |
15 // 4--5--6--7
16 // | | | |
17 // 8--9--A--B
18 Some(vec![
19 (0, 4),
20 (0, 1),
21 (1, 2),
22 (1, 5),
23 (2, 3),
24 (2, 6),
25 (3, 7),
26 (4, 8),
27 (4, 5),
28 (5, 9),
29 (5, 6),
30 (6, 10),
31 (6, 7),
32 (7, 11),
33 (8, 9),
34 (9, 10),
35 (10, 11),
36 ]),
37 12,
38 Default::default(),
39 Default::default(),
40 )),
41 ..Default::default()
42 };
43
44 let mut process = Process::new(config);
45
46 let size = 6;
47
48 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
49 ctrl(&mut process, &qubits[1..], |process| {
50 process.gate(QuantumGate::PauliZ, qubits[0])
51 })?;
52
53 let _ = process.sample(&qubits, 1024)?;
54 process.transpile();
55
56 println!("Instructions:");
57 for line in process.instructions() {
58 println!("\t{:?}", line);
59 }
60
61 println!("ISA Instructions:");
62 if let Some(isa) = process.isa_instructions() {
63 for line in isa {
64 println!("\t{:?}", line);
65 }
66 }
67
68 Ok(())
69}
examples/grover.rs (line 77)
9fn main() -> Result<(), KetError> {
10 set_log_level(3);
11
12 let config = Configuration {
13 num_qubits: 12,
14 qpu: Some(QPU::new(
15 // 0--1--2--3
16 // | | | |
17 // 4--5--6--7
18 // | | | |
19 // 8--9--A--B
20 Some(ket::ex_arch::GRID12.to_vec()),
21 12,
22 U2Gates::RzSx,
23 U4Gate::CZ,
24 )),
25 ..Default::default()
26 };
27
28 let mut process = Process::new(config);
29
30 let size = 8;
31
32 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
33
34 for qubit in &qubits {
35 process.gate(QuantumGate::Hadamard, *qubit)?;
36 }
37
38 let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;
39
40 for _ in 0..steps {
41 around(
42 &mut process,
43 |process| {
44 for qubit in &qubits {
45 process.gate(QuantumGate::PauliX, *qubit)?;
46 }
47 Ok(())
48 },
49 |process| {
50 ctrl(process, &qubits[1..], |process| {
51 process.gate(QuantumGate::PauliZ, qubits[0])
52 })
53 },
54 )?;
55
56 around(
57 &mut process,
58 |process| {
59 for qubit in &qubits {
60 process.gate(QuantumGate::Hadamard, *qubit)?;
61 }
62
63 for qubit in &qubits {
64 process.gate(QuantumGate::PauliX, *qubit)?;
65 }
66 Ok(())
67 },
68 |process| {
69 ctrl(process, &qubits[1..], |process| {
70 process.gate(QuantumGate::PauliZ, qubits[0])
71 })
72 },
73 )?;
74 }
75
76 let _ = process.sample(&qubits, 1024)?;
77 process.transpile();
78
79 println!("{:#?}", process.metadata());
80
81 Ok(())
82}
pub fn execute(&mut self) -> Result<()>
pub fn get_measure(&self, index: usize) -> Option<u64>
pub fn get_sample(&self, index: usize) -> Option<&Sample>
pub fn get_exp_value(&self, index: usize) -> Option<f64>
pub fn get_dump(&self, index: usize) -> Option<&DumpData>
pub fn ctrl_push(&mut self, qubits: &[LogicalQubit]) -> Result<()>
pub fn ctrl_pop(&mut self) -> Result<()>
pub fn adj_begin(&mut self) -> Result<()>
pub fn adj_end(&mut self) -> Result<()>
pub fn ctrl_begin(&mut self) -> Result<()>
pub fn ctrl_end(&mut self) -> Result<()>
Sourcepub fn instructions(&self) -> &[Instruction<LogicalQubit>]
pub fn instructions(&self) -> &[Instruction<LogicalQubit>]
Examples found in repository?
examples/mcx.rs (line 57)
7fn main() -> Result<(), KetError> {
8 set_log_level(4);
9
10 let config = Configuration {
11 num_qubits: 12,
12 qpu: Some(QPU::new(
13 // 0--1--2--3
14 // | | | |
15 // 4--5--6--7
16 // | | | |
17 // 8--9--A--B
18 Some(vec![
19 (0, 4),
20 (0, 1),
21 (1, 2),
22 (1, 5),
23 (2, 3),
24 (2, 6),
25 (3, 7),
26 (4, 8),
27 (4, 5),
28 (5, 9),
29 (5, 6),
30 (6, 10),
31 (6, 7),
32 (7, 11),
33 (8, 9),
34 (9, 10),
35 (10, 11),
36 ]),
37 12,
38 Default::default(),
39 Default::default(),
40 )),
41 ..Default::default()
42 };
43
44 let mut process = Process::new(config);
45
46 let size = 6;
47
48 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
49 ctrl(&mut process, &qubits[1..], |process| {
50 process.gate(QuantumGate::PauliZ, qubits[0])
51 })?;
52
53 let _ = process.sample(&qubits, 1024)?;
54 process.transpile();
55
56 println!("Instructions:");
57 for line in process.instructions() {
58 println!("\t{:?}", line);
59 }
60
61 println!("ISA Instructions:");
62 if let Some(isa) = process.isa_instructions() {
63 for line in isa {
64 println!("\t{:?}", line);
65 }
66 }
67
68 Ok(())
69}
pub fn instructions_json(&self) -> String
Sourcepub fn isa_instructions(&self) -> Option<&[Instruction<PhysicalQubit>]>
pub fn isa_instructions(&self) -> Option<&[Instruction<PhysicalQubit>]>
Examples found in repository?
examples/mcx.rs (line 62)
7fn main() -> Result<(), KetError> {
8 set_log_level(4);
9
10 let config = Configuration {
11 num_qubits: 12,
12 qpu: Some(QPU::new(
13 // 0--1--2--3
14 // | | | |
15 // 4--5--6--7
16 // | | | |
17 // 8--9--A--B
18 Some(vec![
19 (0, 4),
20 (0, 1),
21 (1, 2),
22 (1, 5),
23 (2, 3),
24 (2, 6),
25 (3, 7),
26 (4, 8),
27 (4, 5),
28 (5, 9),
29 (5, 6),
30 (6, 10),
31 (6, 7),
32 (7, 11),
33 (8, 9),
34 (9, 10),
35 (10, 11),
36 ]),
37 12,
38 Default::default(),
39 Default::default(),
40 )),
41 ..Default::default()
42 };
43
44 let mut process = Process::new(config);
45
46 let size = 6;
47
48 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
49 ctrl(&mut process, &qubits[1..], |process| {
50 process.gate(QuantumGate::PauliZ, qubits[0])
51 })?;
52
53 let _ = process.sample(&qubits, 1024)?;
54 process.transpile();
55
56 println!("Instructions:");
57 for line in process.instructions() {
58 println!("\t{:?}", line);
59 }
60
61 println!("ISA Instructions:");
62 if let Some(isa) = process.isa_instructions() {
63 for line in isa {
64 println!("\t{:?}", line);
65 }
66 }
67
68 Ok(())
69}
pub fn isa_instructions_json(&self) -> String
Sourcepub fn metadata(&self) -> Metadata
pub fn metadata(&self) -> Metadata
Examples found in repository?
examples/qft.rs (line 62)
36fn main() -> Result<(), KetError> {
37 let config = Configuration {
38 num_qubits: 12,
39 qpu: Some(QPU::new(
40 // 0--1--2--3
41 // | | | |
42 // 4--5--6--7
43 // | | | |
44 // 8--9--A--B
45 Some(ket::ex_arch::GRID12.to_vec()),
46 12,
47 U2Gates::RzSx,
48 U4Gate::CX,
49 )),
50 ..Default::default()
51 };
52
53 let mut process = Process::new(config);
54
55 let size = 12;
56 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
57
58 qft(&mut process, &qubits, true)?;
59
60 process.transpile();
61
62 println!("{:#?}", process.metadata());
63
64 Ok(())
65}
More examples
examples/grover.rs (line 79)
9fn main() -> Result<(), KetError> {
10 set_log_level(3);
11
12 let config = Configuration {
13 num_qubits: 12,
14 qpu: Some(QPU::new(
15 // 0--1--2--3
16 // | | | |
17 // 4--5--6--7
18 // | | | |
19 // 8--9--A--B
20 Some(ket::ex_arch::GRID12.to_vec()),
21 12,
22 U2Gates::RzSx,
23 U4Gate::CZ,
24 )),
25 ..Default::default()
26 };
27
28 let mut process = Process::new(config);
29
30 let size = 8;
31
32 let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
33
34 for qubit in &qubits {
35 process.gate(QuantumGate::Hadamard, *qubit)?;
36 }
37
38 let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;
39
40 for _ in 0..steps {
41 around(
42 &mut process,
43 |process| {
44 for qubit in &qubits {
45 process.gate(QuantumGate::PauliX, *qubit)?;
46 }
47 Ok(())
48 },
49 |process| {
50 ctrl(process, &qubits[1..], |process| {
51 process.gate(QuantumGate::PauliZ, qubits[0])
52 })
53 },
54 )?;
55
56 around(
57 &mut process,
58 |process| {
59 for qubit in &qubits {
60 process.gate(QuantumGate::Hadamard, *qubit)?;
61 }
62
63 for qubit in &qubits {
64 process.gate(QuantumGate::PauliX, *qubit)?;
65 }
66 Ok(())
67 },
68 |process| {
69 ctrl(process, &qubits[1..], |process| {
70 process.gate(QuantumGate::PauliZ, qubits[0])
71 })
72 },
73 )?;
74 }
75
76 let _ = process.sample(&qubits, 1024)?;
77 process.transpile();
78
79 println!("{:#?}", process.metadata());
80
81 Ok(())
82}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Process
impl !RefUnwindSafe for Process
impl !Send for Process
impl !Sync for Process
impl Unpin for Process
impl !UnwindSafe for Process
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more