Struct Process

Source
pub struct Process { /* private fields */ }

Implementations§

Source§

impl Process

Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

pub fn global_phase(&mut self, angle: f64) -> Result<()>

Source

pub fn measure(&mut self, qubits: &[LogicalQubit]) -> Result<usize>

Source

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
Hide additional 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}
Source

pub fn exp_value( &mut self, hamiltonian: Hamiltonian<LogicalQubit>, ) -> Result<usize>

Source

pub fn dump(&mut self, qubits: &[LogicalQubit]) -> Result<usize>

Source

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
Hide additional 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}
Source

pub fn execute(&mut self) -> Result<()>

Source

pub fn get_measure(&self, index: usize) -> Option<u64>

Source

pub fn get_sample(&self, index: usize) -> Option<&Sample>

Source

pub fn get_exp_value(&self, index: usize) -> Option<f64>

Source

pub fn get_dump(&self, index: usize) -> Option<&DumpData>

Source

pub fn ctrl_push(&mut self, qubits: &[LogicalQubit]) -> Result<()>

Source

pub fn ctrl_pop(&mut self) -> Result<()>

Source

pub fn adj_begin(&mut self) -> Result<()>

Source

pub fn adj_end(&mut self) -> Result<()>

Source

pub fn ctrl_begin(&mut self) -> Result<()>

Source

pub fn ctrl_end(&mut self) -> Result<()>

Source

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}
Source

pub fn instructions_json(&self) -> String

Source

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}
Source

pub fn isa_instructions_json(&self) -> String

Source

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
Hide additional 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§

Source§

impl Debug for Process

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Process

Source§

fn default() -> Process

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.