Struct QPU

Source
pub struct QPU {
    pub u2_gates: U2Gates,
    pub u4_gate: U4Gate,
    /* private fields */
}

Fields§

§u2_gates: U2Gates§u4_gate: U4Gate

Implementations§

Source§

impl QPU

Source

pub fn new( coupling_graph: Option<Vec<(usize, usize)>>, num_qubits: usize, u2_gates: U2Gates, u4_gate: U4Gate, ) -> Self

Examples found in repository?
examples/qft.rs (lines 39-49)
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 (lines 12-40)
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 (lines 14-24)
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 QPU

Source§

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

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

impl Default for QPU

Source§

fn default() -> QPU

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

Auto Trait Implementations§

§

impl Freeze for QPU

§

impl RefUnwindSafe for QPU

§

impl Send for QPU

§

impl Sync for QPU

§

impl Unpin for QPU

§

impl UnwindSafe for QPU

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.