ket::process

Struct Process

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

Implementations§

Source§

impl Process

Source

pub fn new(configuration: Configuration) -> Self

Examples found in repository?
examples/mcx.rs (line 44)
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
fn main() -> Result<(), KetError> {
    set_log_level(4);

    let config = Configuration {
        num_qubits: 12,
        qpu: Some(QPU::new(
            // 0--1--2--3
            // |  |  |  |
            // 4--5--6--7
            // |  |  |  |
            // 8--9--A--B
            Some(vec![
                (0, 4),
                (0, 1),
                (1, 2),
                (1, 5),
                (2, 3),
                (2, 6),
                (3, 7),
                (4, 8),
                (4, 5),
                (5, 9),
                (5, 6),
                (6, 10),
                (6, 7),
                (7, 11),
                (8, 9),
                (9, 10),
                (10, 11),
            ]),
            12,
            Default::default(),
            Default::default(),
        )),
        ..Default::default()
    };

    let mut process = Process::new(config);

    let size = 6;

    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
    ctrl(&mut process, &qubits[1..], |process| {
        process.gate(QuantumGate::PauliZ, qubits[0])
    })?;

    let _ = process.sample(&qubits, 1024)?;
    process.transpile();

    println!("Instructions:");
    for line in process.instructions() {
        println!("\t{:?}", line);
    }

    println!("ISA Instructions:");
    if let Some(isa) = process.isa_instructions() {
        for line in isa {
            println!("\t{:?}", line);
        }
    }

    Ok(())
}
More examples
Hide additional examples
examples/grover.rs (line 28)
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
fn main() -> Result<(), KetError> {
    set_log_level(3);

    let config = Configuration {
        num_qubits: 12,
        qpu: Some(QPU::new(
            // 0--1--2--3
            // |  |  |  |
            // 4--5--6--7
            // |  |  |  |
            // 8--9--A--B
            Some(ket::ex_arch::GRID12.to_vec()),
            12,
            U2Gates::RzSx,
            U4Gate::CZ,
        )),
        ..Default::default()
    };

    let mut process = Process::new(config);

    let size = 8;

    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();

    for qubit in &qubits {
        process.gate(QuantumGate::Hadamard, *qubit)?;
    }

    let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;

    for _ in 0..steps {
        around(
            &mut process,
            |process| {
                for qubit in &qubits {
                    process.gate(QuantumGate::PauliX, *qubit)?;
                }
                Ok(())
            },
            |process| {
                ctrl(process, &qubits[1..], |process| {
                    process.gate(QuantumGate::PauliZ, qubits[0])
                })
            },
        )?;

        around(
            &mut process,
            |process| {
                for qubit in &qubits {
                    process.gate(QuantumGate::Hadamard, *qubit)?;
                }

                for qubit in &qubits {
                    process.gate(QuantumGate::PauliX, *qubit)?;
                }
                Ok(())
            },
            |process| {
                ctrl(process, &qubits[1..], |process| {
                    process.gate(QuantumGate::PauliZ, qubits[0])
                })
            },
        )?;
    }

    let _ = process.sample(&qubits, 1024)?;
    process.transpile();

    println!("{:#?}", process.metadata());

    Ok(())
}
Source

pub fn alloc(&mut self) -> Result<LogicalQubit>

Examples found in repository?
examples/mcx.rs (line 48)
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
fn main() -> Result<(), KetError> {
    set_log_level(4);

    let config = Configuration {
        num_qubits: 12,
        qpu: Some(QPU::new(
            // 0--1--2--3
            // |  |  |  |
            // 4--5--6--7
            // |  |  |  |
            // 8--9--A--B
            Some(vec![
                (0, 4),
                (0, 1),
                (1, 2),
                (1, 5),
                (2, 3),
                (2, 6),
                (3, 7),
                (4, 8),
                (4, 5),
                (5, 9),
                (5, 6),
                (6, 10),
                (6, 7),
                (7, 11),
                (8, 9),
                (9, 10),
                (10, 11),
            ]),
            12,
            Default::default(),
            Default::default(),
        )),
        ..Default::default()
    };

    let mut process = Process::new(config);

    let size = 6;

    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
    ctrl(&mut process, &qubits[1..], |process| {
        process.gate(QuantumGate::PauliZ, qubits[0])
    })?;

    let _ = process.sample(&qubits, 1024)?;
    process.transpile();

    println!("Instructions:");
    for line in process.instructions() {
        println!("\t{:?}", line);
    }

    println!("ISA Instructions:");
    if let Some(isa) = process.isa_instructions() {
        for line in isa {
            println!("\t{:?}", line);
        }
    }

    Ok(())
}
More examples
Hide additional examples
examples/grover.rs (line 32)
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
fn main() -> Result<(), KetError> {
    set_log_level(3);

    let config = Configuration {
        num_qubits: 12,
        qpu: Some(QPU::new(
            // 0--1--2--3
            // |  |  |  |
            // 4--5--6--7
            // |  |  |  |
            // 8--9--A--B
            Some(ket::ex_arch::GRID12.to_vec()),
            12,
            U2Gates::RzSx,
            U4Gate::CZ,
        )),
        ..Default::default()
    };

    let mut process = Process::new(config);

    let size = 8;

    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();

    for qubit in &qubits {
        process.gate(QuantumGate::Hadamard, *qubit)?;
    }

    let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;

    for _ in 0..steps {
        around(
            &mut process,
            |process| {
                for qubit in &qubits {
                    process.gate(QuantumGate::PauliX, *qubit)?;
                }
                Ok(())
            },
            |process| {
                ctrl(process, &qubits[1..], |process| {
                    process.gate(QuantumGate::PauliZ, qubits[0])
                })
            },
        )?;

        around(
            &mut process,
            |process| {
                for qubit in &qubits {
                    process.gate(QuantumGate::Hadamard, *qubit)?;
                }

                for qubit in &qubits {
                    process.gate(QuantumGate::PauliX, *qubit)?;
                }
                Ok(())
            },
            |process| {
                ctrl(process, &qubits[1..], |process| {
                    process.gate(QuantumGate::PauliZ, qubits[0])
                })
            },
        )?;
    }

    let _ = process.sample(&qubits, 1024)?;
    process.transpile();

    println!("{:#?}", process.metadata());

    Ok(())
}
Source

pub fn gate(&mut self, gate: QuantumGate, target: LogicalQubit) -> Result<()>

Examples found in repository?
examples/mcx.rs (line 50)
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
fn main() -> Result<(), KetError> {
    set_log_level(4);

    let config = Configuration {
        num_qubits: 12,
        qpu: Some(QPU::new(
            // 0--1--2--3
            // |  |  |  |
            // 4--5--6--7
            // |  |  |  |
            // 8--9--A--B
            Some(vec![
                (0, 4),
                (0, 1),
                (1, 2),
                (1, 5),
                (2, 3),
                (2, 6),
                (3, 7),
                (4, 8),
                (4, 5),
                (5, 9),
                (5, 6),
                (6, 10),
                (6, 7),
                (7, 11),
                (8, 9),
                (9, 10),
                (10, 11),
            ]),
            12,
            Default::default(),
            Default::default(),
        )),
        ..Default::default()
    };

    let mut process = Process::new(config);

    let size = 6;

    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
    ctrl(&mut process, &qubits[1..], |process| {
        process.gate(QuantumGate::PauliZ, qubits[0])
    })?;

    let _ = process.sample(&qubits, 1024)?;
    process.transpile();

    println!("Instructions:");
    for line in process.instructions() {
        println!("\t{:?}", line);
    }

    println!("ISA Instructions:");
    if let Some(isa) = process.isa_instructions() {
        for line in isa {
            println!("\t{:?}", line);
        }
    }

    Ok(())
}
More examples
Hide additional examples
examples/grover.rs (line 35)
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
fn main() -> Result<(), KetError> {
    set_log_level(3);

    let config = Configuration {
        num_qubits: 12,
        qpu: Some(QPU::new(
            // 0--1--2--3
            // |  |  |  |
            // 4--5--6--7
            // |  |  |  |
            // 8--9--A--B
            Some(ket::ex_arch::GRID12.to_vec()),
            12,
            U2Gates::RzSx,
            U4Gate::CZ,
        )),
        ..Default::default()
    };

    let mut process = Process::new(config);

    let size = 8;

    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();

    for qubit in &qubits {
        process.gate(QuantumGate::Hadamard, *qubit)?;
    }

    let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;

    for _ in 0..steps {
        around(
            &mut process,
            |process| {
                for qubit in &qubits {
                    process.gate(QuantumGate::PauliX, *qubit)?;
                }
                Ok(())
            },
            |process| {
                ctrl(process, &qubits[1..], |process| {
                    process.gate(QuantumGate::PauliZ, qubits[0])
                })
            },
        )?;

        around(
            &mut process,
            |process| {
                for qubit in &qubits {
                    process.gate(QuantumGate::Hadamard, *qubit)?;
                }

                for qubit in &qubits {
                    process.gate(QuantumGate::PauliX, *qubit)?;
                }
                Ok(())
            },
            |process| {
                ctrl(process, &qubits[1..], |process| {
                    process.gate(QuantumGate::PauliZ, qubits[0])
                })
            },
        )?;
    }

    let _ = process.sample(&qubits, 1024)?;
    process.transpile();

    println!("{:#?}", process.metadata());

    Ok(())
}
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)
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
fn main() -> Result<(), KetError> {
    set_log_level(4);

    let config = Configuration {
        num_qubits: 12,
        qpu: Some(QPU::new(
            // 0--1--2--3
            // |  |  |  |
            // 4--5--6--7
            // |  |  |  |
            // 8--9--A--B
            Some(vec![
                (0, 4),
                (0, 1),
                (1, 2),
                (1, 5),
                (2, 3),
                (2, 6),
                (3, 7),
                (4, 8),
                (4, 5),
                (5, 9),
                (5, 6),
                (6, 10),
                (6, 7),
                (7, 11),
                (8, 9),
                (9, 10),
                (10, 11),
            ]),
            12,
            Default::default(),
            Default::default(),
        )),
        ..Default::default()
    };

    let mut process = Process::new(config);

    let size = 6;

    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
    ctrl(&mut process, &qubits[1..], |process| {
        process.gate(QuantumGate::PauliZ, qubits[0])
    })?;

    let _ = process.sample(&qubits, 1024)?;
    process.transpile();

    println!("Instructions:");
    for line in process.instructions() {
        println!("\t{:?}", line);
    }

    println!("ISA Instructions:");
    if let Some(isa) = process.isa_instructions() {
        for line in isa {
            println!("\t{:?}", line);
        }
    }

    Ok(())
}
More examples
Hide additional examples
examples/grover.rs (line 76)
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
fn main() -> Result<(), KetError> {
    set_log_level(3);

    let config = Configuration {
        num_qubits: 12,
        qpu: Some(QPU::new(
            // 0--1--2--3
            // |  |  |  |
            // 4--5--6--7
            // |  |  |  |
            // 8--9--A--B
            Some(ket::ex_arch::GRID12.to_vec()),
            12,
            U2Gates::RzSx,
            U4Gate::CZ,
        )),
        ..Default::default()
    };

    let mut process = Process::new(config);

    let size = 8;

    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();

    for qubit in &qubits {
        process.gate(QuantumGate::Hadamard, *qubit)?;
    }

    let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;

    for _ in 0..steps {
        around(
            &mut process,
            |process| {
                for qubit in &qubits {
                    process.gate(QuantumGate::PauliX, *qubit)?;
                }
                Ok(())
            },
            |process| {
                ctrl(process, &qubits[1..], |process| {
                    process.gate(QuantumGate::PauliZ, qubits[0])
                })
            },
        )?;

        around(
            &mut process,
            |process| {
                for qubit in &qubits {
                    process.gate(QuantumGate::Hadamard, *qubit)?;
                }

                for qubit in &qubits {
                    process.gate(QuantumGate::PauliX, *qubit)?;
                }
                Ok(())
            },
            |process| {
                ctrl(process, &qubits[1..], |process| {
                    process.gate(QuantumGate::PauliZ, qubits[0])
                })
            },
        )?;
    }

    let _ = process.sample(&qubits, 1024)?;
    process.transpile();

    println!("{:#?}", process.metadata());

    Ok(())
}
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/mcx.rs (line 54)
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
fn main() -> Result<(), KetError> {
    set_log_level(4);

    let config = Configuration {
        num_qubits: 12,
        qpu: Some(QPU::new(
            // 0--1--2--3
            // |  |  |  |
            // 4--5--6--7
            // |  |  |  |
            // 8--9--A--B
            Some(vec![
                (0, 4),
                (0, 1),
                (1, 2),
                (1, 5),
                (2, 3),
                (2, 6),
                (3, 7),
                (4, 8),
                (4, 5),
                (5, 9),
                (5, 6),
                (6, 10),
                (6, 7),
                (7, 11),
                (8, 9),
                (9, 10),
                (10, 11),
            ]),
            12,
            Default::default(),
            Default::default(),
        )),
        ..Default::default()
    };

    let mut process = Process::new(config);

    let size = 6;

    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
    ctrl(&mut process, &qubits[1..], |process| {
        process.gate(QuantumGate::PauliZ, qubits[0])
    })?;

    let _ = process.sample(&qubits, 1024)?;
    process.transpile();

    println!("Instructions:");
    for line in process.instructions() {
        println!("\t{:?}", line);
    }

    println!("ISA Instructions:");
    if let Some(isa) = process.isa_instructions() {
        for line in isa {
            println!("\t{:?}", line);
        }
    }

    Ok(())
}
More examples
Hide additional examples
examples/grover.rs (line 77)
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
fn main() -> Result<(), KetError> {
    set_log_level(3);

    let config = Configuration {
        num_qubits: 12,
        qpu: Some(QPU::new(
            // 0--1--2--3
            // |  |  |  |
            // 4--5--6--7
            // |  |  |  |
            // 8--9--A--B
            Some(ket::ex_arch::GRID12.to_vec()),
            12,
            U2Gates::RzSx,
            U4Gate::CZ,
        )),
        ..Default::default()
    };

    let mut process = Process::new(config);

    let size = 8;

    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();

    for qubit in &qubits {
        process.gate(QuantumGate::Hadamard, *qubit)?;
    }

    let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;

    for _ in 0..steps {
        around(
            &mut process,
            |process| {
                for qubit in &qubits {
                    process.gate(QuantumGate::PauliX, *qubit)?;
                }
                Ok(())
            },
            |process| {
                ctrl(process, &qubits[1..], |process| {
                    process.gate(QuantumGate::PauliZ, qubits[0])
                })
            },
        )?;

        around(
            &mut process,
            |process| {
                for qubit in &qubits {
                    process.gate(QuantumGate::Hadamard, *qubit)?;
                }

                for qubit in &qubits {
                    process.gate(QuantumGate::PauliX, *qubit)?;
                }
                Ok(())
            },
            |process| {
                ctrl(process, &qubits[1..], |process| {
                    process.gate(QuantumGate::PauliZ, qubits[0])
                })
            },
        )?;
    }

    let _ = process.sample(&qubits, 1024)?;
    process.transpile();

    println!("{:#?}", process.metadata());

    Ok(())
}
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)
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
fn main() -> Result<(), KetError> {
    set_log_level(4);

    let config = Configuration {
        num_qubits: 12,
        qpu: Some(QPU::new(
            // 0--1--2--3
            // |  |  |  |
            // 4--5--6--7
            // |  |  |  |
            // 8--9--A--B
            Some(vec![
                (0, 4),
                (0, 1),
                (1, 2),
                (1, 5),
                (2, 3),
                (2, 6),
                (3, 7),
                (4, 8),
                (4, 5),
                (5, 9),
                (5, 6),
                (6, 10),
                (6, 7),
                (7, 11),
                (8, 9),
                (9, 10),
                (10, 11),
            ]),
            12,
            Default::default(),
            Default::default(),
        )),
        ..Default::default()
    };

    let mut process = Process::new(config);

    let size = 6;

    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
    ctrl(&mut process, &qubits[1..], |process| {
        process.gate(QuantumGate::PauliZ, qubits[0])
    })?;

    let _ = process.sample(&qubits, 1024)?;
    process.transpile();

    println!("Instructions:");
    for line in process.instructions() {
        println!("\t{:?}", line);
    }

    println!("ISA Instructions:");
    if let Some(isa) = process.isa_instructions() {
        for line in isa {
            println!("\t{:?}", line);
        }
    }

    Ok(())
}
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)
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
fn main() -> Result<(), KetError> {
    set_log_level(4);

    let config = Configuration {
        num_qubits: 12,
        qpu: Some(QPU::new(
            // 0--1--2--3
            // |  |  |  |
            // 4--5--6--7
            // |  |  |  |
            // 8--9--A--B
            Some(vec![
                (0, 4),
                (0, 1),
                (1, 2),
                (1, 5),
                (2, 3),
                (2, 6),
                (3, 7),
                (4, 8),
                (4, 5),
                (5, 9),
                (5, 6),
                (6, 10),
                (6, 7),
                (7, 11),
                (8, 9),
                (9, 10),
                (10, 11),
            ]),
            12,
            Default::default(),
            Default::default(),
        )),
        ..Default::default()
    };

    let mut process = Process::new(config);

    let size = 6;

    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
    ctrl(&mut process, &qubits[1..], |process| {
        process.gate(QuantumGate::PauliZ, qubits[0])
    })?;

    let _ = process.sample(&qubits, 1024)?;
    process.transpile();

    println!("Instructions:");
    for line in process.instructions() {
        println!("\t{:?}", line);
    }

    println!("ISA Instructions:");
    if let Some(isa) = process.isa_instructions() {
        for line in isa {
            println!("\t{:?}", line);
        }
    }

    Ok(())
}
Source

pub fn isa_instructions_json(&self) -> String

Source

pub fn metadata(&self) -> Metadata

Examples found in repository?
examples/grover.rs (line 79)
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
fn main() -> Result<(), KetError> {
    set_log_level(3);

    let config = Configuration {
        num_qubits: 12,
        qpu: Some(QPU::new(
            // 0--1--2--3
            // |  |  |  |
            // 4--5--6--7
            // |  |  |  |
            // 8--9--A--B
            Some(ket::ex_arch::GRID12.to_vec()),
            12,
            U2Gates::RzSx,
            U4Gate::CZ,
        )),
        ..Default::default()
    };

    let mut process = Process::new(config);

    let size = 8;

    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();

    for qubit in &qubits {
        process.gate(QuantumGate::Hadamard, *qubit)?;
    }

    let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;

    for _ in 0..steps {
        around(
            &mut process,
            |process| {
                for qubit in &qubits {
                    process.gate(QuantumGate::PauliX, *qubit)?;
                }
                Ok(())
            },
            |process| {
                ctrl(process, &qubits[1..], |process| {
                    process.gate(QuantumGate::PauliZ, qubits[0])
                })
            },
        )?;

        around(
            &mut process,
            |process| {
                for qubit in &qubits {
                    process.gate(QuantumGate::Hadamard, *qubit)?;
                }

                for qubit in &qubits {
                    process.gate(QuantumGate::PauliX, *qubit)?;
                }
                Ok(())
            },
            |process| {
                ctrl(process, &qubits[1..], |process| {
                    process.gate(QuantumGate::PauliZ, qubits[0])
                })
            },
        )?;
    }

    let _ = process.sample(&qubits, 1024)?;
    process.transpile();

    println!("{:#?}", process.metadata());

    Ok(())
}

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.