Struct Process

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

Ket quantum process.

Implementations§

Source§

impl Process

Source

pub fn alloc_aux( &mut self, num_qubits: usize, interacting_qubits: Option<&[LogicalQubit]>, ) -> Result<(Vec<LogicalQubit>, usize)>

Source

pub fn free_aux(&mut self, group_id: usize)

Source

pub fn is_diagonal_begin(&mut self)

Source

pub fn is_diagonal_end(&mut self)

Source

pub fn is_permutation_begin(&mut self)

Source

pub fn is_permutation_end(&mut self)

Source

pub fn around_begin(&mut self)

Source

pub fn around_mid(&mut self)

Source

pub fn around_undo(&mut self)

Source

pub fn around_end(&mut self)

Source§

impl Process

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§

impl Process

Source

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

Source

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

Source§

impl Process

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/grover.rs (line 79)
12fn main() -> Result<(), KetError> {
13    set_log_level(3);
14
15    let config = ExecutionTarget {
16        num_qubits: 12,
17        qpu: Some(QPU {
18            coupling_graph: Some(ket::ex_arch::GRID12.to_vec()),
19            u2_gates: U2Gates::RzSx,
20            u4_gate: U4Gate::CZ,
21        }),
22        execution_protocol: ExecutionProtocol::ManagedByTarget {
23            sample: Capability::Basic,
24            measure: Capability::Unsupported,
25            exp_value: Capability::Unsupported,
26            dump: Capability::Unsupported,
27        },
28        gradient: None,
29    };
30
31    let mut process = Process::new(config, None);
32
33    let size = 8;
34
35    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
36
37    for qubit in &qubits {
38        process.gate(QuantumGate::Hadamard, *qubit)?;
39    }
40
41    let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;
42
43    for _ in 0..steps {
44        around(
45            &mut process,
46            |process| {
47                for qubit in &qubits {
48                    process.gate(QuantumGate::PauliX, *qubit)?;
49                }
50                Ok(())
51            },
52            |process| {
53                ctrl(process, &qubits[1..], |process| {
54                    process.gate(QuantumGate::PauliZ, qubits[0])
55                })
56            },
57        )?;
58
59        around(
60            &mut process,
61            |process| {
62                for qubit in &qubits {
63                    process.gate(QuantumGate::Hadamard, *qubit)?;
64                }
65
66                for qubit in &qubits {
67                    process.gate(QuantumGate::PauliX, *qubit)?;
68                }
69                Ok(())
70            },
71            |process| {
72                ctrl(process, &qubits[1..], |process| {
73                    process.gate(QuantumGate::PauliZ, qubits[0])
74                })
75            },
76        )?;
77    }
78
79    let _ = process.sample(&qubits, 1024)?;
80
81    println!("{:#?}", process.metadata());
82
83    Ok(())
84}
Source

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

Source

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

Source§

impl Process

Source

pub fn new( execution_target: ExecutionTarget, quantum_execution: Option<QuantumExecution>, ) -> Self

Examples found in repository?
examples/qft.rs (line 57)
40fn main() -> Result<(), KetError> {
41    let config = ExecutionTarget {
42        num_qubits: 12,
43        qpu: Some(QPU {
44            coupling_graph: Some(ket::ex_arch::GRID12.to_vec()),
45            u2_gates: U2Gates::RzSx,
46            u4_gate: U4Gate::CZ,
47        }),
48        execution_protocol: ExecutionProtocol::ManagedByTarget {
49            sample: Capability::Basic,
50            measure: Capability::Unsupported,
51            exp_value: Capability::Unsupported,
52            dump: Capability::Unsupported,
53        },
54        gradient: None,
55    };
56
57    let mut process = Process::new(config, None);
58
59    let size = 12;
60    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
61
62    qft(&mut process, &qubits, true)?;
63
64    println!("{:#?}", process.metadata());
65
66    Ok(())
67}
More examples
Hide additional examples
examples/grover.rs (line 31)
12fn main() -> Result<(), KetError> {
13    set_log_level(3);
14
15    let config = ExecutionTarget {
16        num_qubits: 12,
17        qpu: Some(QPU {
18            coupling_graph: Some(ket::ex_arch::GRID12.to_vec()),
19            u2_gates: U2Gates::RzSx,
20            u4_gate: U4Gate::CZ,
21        }),
22        execution_protocol: ExecutionProtocol::ManagedByTarget {
23            sample: Capability::Basic,
24            measure: Capability::Unsupported,
25            exp_value: Capability::Unsupported,
26            dump: Capability::Unsupported,
27        },
28        gradient: None,
29    };
30
31    let mut process = Process::new(config, None);
32
33    let size = 8;
34
35    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
36
37    for qubit in &qubits {
38        process.gate(QuantumGate::Hadamard, *qubit)?;
39    }
40
41    let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;
42
43    for _ in 0..steps {
44        around(
45            &mut process,
46            |process| {
47                for qubit in &qubits {
48                    process.gate(QuantumGate::PauliX, *qubit)?;
49                }
50                Ok(())
51            },
52            |process| {
53                ctrl(process, &qubits[1..], |process| {
54                    process.gate(QuantumGate::PauliZ, qubits[0])
55                })
56            },
57        )?;
58
59        around(
60            &mut process,
61            |process| {
62                for qubit in &qubits {
63                    process.gate(QuantumGate::Hadamard, *qubit)?;
64                }
65
66                for qubit in &qubits {
67                    process.gate(QuantumGate::PauliX, *qubit)?;
68                }
69                Ok(())
70            },
71            |process| {
72                ctrl(process, &qubits[1..], |process| {
73                    process.gate(QuantumGate::PauliZ, qubits[0])
74                })
75            },
76        )?;
77    }
78
79    let _ = process.sample(&qubits, 1024)?;
80
81    println!("{:#?}", process.metadata());
82
83    Ok(())
84}
Source

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

Examples found in repository?
examples/qft.rs (line 60)
40fn main() -> Result<(), KetError> {
41    let config = ExecutionTarget {
42        num_qubits: 12,
43        qpu: Some(QPU {
44            coupling_graph: Some(ket::ex_arch::GRID12.to_vec()),
45            u2_gates: U2Gates::RzSx,
46            u4_gate: U4Gate::CZ,
47        }),
48        execution_protocol: ExecutionProtocol::ManagedByTarget {
49            sample: Capability::Basic,
50            measure: Capability::Unsupported,
51            exp_value: Capability::Unsupported,
52            dump: Capability::Unsupported,
53        },
54        gradient: None,
55    };
56
57    let mut process = Process::new(config, None);
58
59    let size = 12;
60    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
61
62    qft(&mut process, &qubits, true)?;
63
64    println!("{:#?}", process.metadata());
65
66    Ok(())
67}
More examples
Hide additional examples
examples/grover.rs (line 35)
12fn main() -> Result<(), KetError> {
13    set_log_level(3);
14
15    let config = ExecutionTarget {
16        num_qubits: 12,
17        qpu: Some(QPU {
18            coupling_graph: Some(ket::ex_arch::GRID12.to_vec()),
19            u2_gates: U2Gates::RzSx,
20            u4_gate: U4Gate::CZ,
21        }),
22        execution_protocol: ExecutionProtocol::ManagedByTarget {
23            sample: Capability::Basic,
24            measure: Capability::Unsupported,
25            exp_value: Capability::Unsupported,
26            dump: Capability::Unsupported,
27        },
28        gradient: None,
29    };
30
31    let mut process = Process::new(config, None);
32
33    let size = 8;
34
35    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
36
37    for qubit in &qubits {
38        process.gate(QuantumGate::Hadamard, *qubit)?;
39    }
40
41    let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;
42
43    for _ in 0..steps {
44        around(
45            &mut process,
46            |process| {
47                for qubit in &qubits {
48                    process.gate(QuantumGate::PauliX, *qubit)?;
49                }
50                Ok(())
51            },
52            |process| {
53                ctrl(process, &qubits[1..], |process| {
54                    process.gate(QuantumGate::PauliZ, qubits[0])
55                })
56            },
57        )?;
58
59        around(
60            &mut process,
61            |process| {
62                for qubit in &qubits {
63                    process.gate(QuantumGate::Hadamard, *qubit)?;
64                }
65
66                for qubit in &qubits {
67                    process.gate(QuantumGate::PauliX, *qubit)?;
68                }
69                Ok(())
70            },
71            |process| {
72                ctrl(process, &qubits[1..], |process| {
73                    process.gate(QuantumGate::PauliZ, qubits[0])
74                })
75            },
76        )?;
77    }
78
79    let _ = process.sample(&qubits, 1024)?;
80
81    println!("{:#?}", process.metadata());
82
83    Ok(())
84}
Source

pub fn approximated_decomposition_begin(&mut self)

Source

pub fn approximated_decomposition_end(&mut self)

Source

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

Examples found in repository?
examples/qft.rs (line 15)
13fn qft(process: &mut Process, qubits: &[LogicalQubit], do_swap: bool) -> Result<(), KetError> {
14    if qubits.len() == 1 {
15        return process.gate(QuantumGate::Hadamard, qubits[0]);
16    }
17
18    let init = &qubits[..qubits.len() - 1];
19    let last = qubits[qubits.len() - 1];
20    process.gate(QuantumGate::Hadamard, last)?;
21    for (i, c) in init.iter().enumerate() {
22        c1gate(
23            process,
24            QuantumGate::Phase((PI / 2.0_f64.powi(i as i32 + 1)).into()),
25            *c,
26            last,
27        )?;
28    }
29    qft(process, init, false)?;
30
31    if do_swap {
32        for i in 0..qubits.len() / 2 {
33            swap(process, qubits[i], qubits[qubits.len() - i - 1])?;
34        }
35    }
36
37    Ok(())
38}
More examples
Hide additional examples
examples/grover.rs (line 38)
12fn main() -> Result<(), KetError> {
13    set_log_level(3);
14
15    let config = ExecutionTarget {
16        num_qubits: 12,
17        qpu: Some(QPU {
18            coupling_graph: Some(ket::ex_arch::GRID12.to_vec()),
19            u2_gates: U2Gates::RzSx,
20            u4_gate: U4Gate::CZ,
21        }),
22        execution_protocol: ExecutionProtocol::ManagedByTarget {
23            sample: Capability::Basic,
24            measure: Capability::Unsupported,
25            exp_value: Capability::Unsupported,
26            dump: Capability::Unsupported,
27        },
28        gradient: None,
29    };
30
31    let mut process = Process::new(config, None);
32
33    let size = 8;
34
35    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
36
37    for qubit in &qubits {
38        process.gate(QuantumGate::Hadamard, *qubit)?;
39    }
40
41    let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;
42
43    for _ in 0..steps {
44        around(
45            &mut process,
46            |process| {
47                for qubit in &qubits {
48                    process.gate(QuantumGate::PauliX, *qubit)?;
49                }
50                Ok(())
51            },
52            |process| {
53                ctrl(process, &qubits[1..], |process| {
54                    process.gate(QuantumGate::PauliZ, qubits[0])
55                })
56            },
57        )?;
58
59        around(
60            &mut process,
61            |process| {
62                for qubit in &qubits {
63                    process.gate(QuantumGate::Hadamard, *qubit)?;
64                }
65
66                for qubit in &qubits {
67                    process.gate(QuantumGate::PauliX, *qubit)?;
68                }
69                Ok(())
70            },
71            |process| {
72                ctrl(process, &qubits[1..], |process| {
73                    process.gate(QuantumGate::PauliZ, qubits[0])
74                })
75            },
76        )?;
77    }
78
79    let _ = process.sample(&qubits, 1024)?;
80
81    println!("{:#?}", process.metadata());
82
83    Ok(())
84}
Source

pub fn global_phase(&mut self, angle: f64) -> 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 instructions(&self) -> &[Instruction<LogicalQubit>]

Source

pub fn instructions_json(&self) -> String

Source

pub fn isa_instructions(&self) -> Option<&[Instruction<PhysicalQubit>]>

Source

pub fn isa_instructions_json(&self) -> String

Source

pub fn metadata(&self) -> Metadata

Examples found in repository?
examples/qft.rs (line 64)
40fn main() -> Result<(), KetError> {
41    let config = ExecutionTarget {
42        num_qubits: 12,
43        qpu: Some(QPU {
44            coupling_graph: Some(ket::ex_arch::GRID12.to_vec()),
45            u2_gates: U2Gates::RzSx,
46            u4_gate: U4Gate::CZ,
47        }),
48        execution_protocol: ExecutionProtocol::ManagedByTarget {
49            sample: Capability::Basic,
50            measure: Capability::Unsupported,
51            exp_value: Capability::Unsupported,
52            dump: Capability::Unsupported,
53        },
54        gradient: None,
55    };
56
57    let mut process = Process::new(config, None);
58
59    let size = 12;
60    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
61
62    qft(&mut process, &qubits, true)?;
63
64    println!("{:#?}", process.metadata());
65
66    Ok(())
67}
More examples
Hide additional examples
examples/grover.rs (line 81)
12fn main() -> Result<(), KetError> {
13    set_log_level(3);
14
15    let config = ExecutionTarget {
16        num_qubits: 12,
17        qpu: Some(QPU {
18            coupling_graph: Some(ket::ex_arch::GRID12.to_vec()),
19            u2_gates: U2Gates::RzSx,
20            u4_gate: U4Gate::CZ,
21        }),
22        execution_protocol: ExecutionProtocol::ManagedByTarget {
23            sample: Capability::Basic,
24            measure: Capability::Unsupported,
25            exp_value: Capability::Unsupported,
26            dump: Capability::Unsupported,
27        },
28        gradient: None,
29    };
30
31    let mut process = Process::new(config, None);
32
33    let size = 8;
34
35    let qubits: Vec<_> = (0..size).map(|_| process.alloc().unwrap()).collect();
36
37    for qubit in &qubits {
38        process.gate(QuantumGate::Hadamard, *qubit)?;
39    }
40
41    let steps = ((FRAC_PI_4) * f64::sqrt((1 << size) as f64)) as i64;
42
43    for _ in 0..steps {
44        around(
45            &mut process,
46            |process| {
47                for qubit in &qubits {
48                    process.gate(QuantumGate::PauliX, *qubit)?;
49                }
50                Ok(())
51            },
52            |process| {
53                ctrl(process, &qubits[1..], |process| {
54                    process.gate(QuantumGate::PauliZ, qubits[0])
55                })
56            },
57        )?;
58
59        around(
60            &mut process,
61            |process| {
62                for qubit in &qubits {
63                    process.gate(QuantumGate::Hadamard, *qubit)?;
64                }
65
66                for qubit in &qubits {
67                    process.gate(QuantumGate::PauliX, *qubit)?;
68                }
69                Ok(())
70            },
71            |process| {
72                ctrl(process, &qubits[1..], |process| {
73                    process.gate(QuantumGate::PauliZ, qubits[0])
74                })
75            },
76        )?;
77    }
78
79    let _ = process.sample(&qubits, 1024)?;
80
81    println!("{:#?}", process.metadata());
82
83    Ok(())
84}
Source

pub fn parameter(&mut self, param: f64) -> Result<usize>

Source

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

Source

pub fn save_sim_state(&self) -> Vec<u8>

Source

pub fn load_sim_state(&mut self, data: &[u8])

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V