From 2770097e25e7fb5090efe0f85340f0c638f9dd71 Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 28 Sep 2024 23:58:13 +0200 Subject: Prep for first CLI visualizer --- libpsi-core/src/core/component.rs | 4 ++-- libpsi-core/src/core/gates.rs | 26 +++++++++++++------------- libpsi-core/src/core/runtime.rs | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) (limited to 'libpsi-core/src/core') diff --git a/libpsi-core/src/core/component.rs b/libpsi-core/src/core/component.rs index 09095ec..be5fbca 100644 --- a/libpsi-core/src/core/component.rs +++ b/libpsi-core/src/core/component.rs @@ -4,7 +4,7 @@ use crate::{complex, ColumnVector, Complex, Matrix, Vector, VectorMatrix}; use core::ops; pub type QuantumBit = ColumnVector>; -pub type QuantumGate = Matrix>; +pub type QuantumGate = (&'static str, Matrix>); #[macro_export] macro_rules! count { @@ -124,7 +124,7 @@ impl QuantumRegister { } pub fn apply(&self, gate: &QuantumGate) -> QuantumBit { - self.state.mul_matrix(gate).unwrap() + self.state.mul_matrix(&gate.1).unwrap() } } diff --git a/libpsi-core/src/core/gates.rs b/libpsi-core/src/core/gates.rs index e9077ad..094fec9 100644 --- a/libpsi-core/src/core/gates.rs +++ b/libpsi-core/src/core/gates.rs @@ -2,21 +2,21 @@ use crate::{complex, matrix, QuantumGate}; #[rustfmt::skip] lazy_static::lazy_static! { - pub static ref HADAMARD: QuantumGate = matrix!([complex!(1.0, 0.0), complex!( 1.0, 0.0)]; - [complex!(1.0, 0.0), complex!(-1.0, 0.0)]) * - complex!(1.0/2.0_f64.sqrt(), 0.0); + pub static ref HADAMARD: QuantumGate = ("H", matrix!([complex!(1.0, 0.0), complex!( 1.0, 0.0)]; + [complex!(1.0, 0.0), complex!(-1.0, 0.0)]) * + complex!(1.0/2.0_f64.sqrt(), 0.0)); - pub static ref PAULI_X: QuantumGate = matrix!([complex!(0.0, 0.0), complex!(1.0, 0.0)]; - [complex!(1.0, 0.0), complex!(0.0, 0.0)]); + pub static ref PAULI_X: QuantumGate = ("Pauli-X", matrix!([complex!(0.0, 0.0), complex!(1.0, 0.0)]; + [complex!(1.0, 0.0), complex!(0.0, 0.0)])); - pub static ref PAULI_Y: QuantumGate = matrix!([complex!(0.0, 0.0), complex!(0.0, -1.0)]; - [complex!(0.0, 1.0), complex!(0.0, 0.0)]); + pub static ref PAULI_Y: QuantumGate = ("Pauli-Y", matrix!([complex!(0.0, 0.0), complex!(0.0, -1.0)]; + [complex!(0.0, 1.0), complex!(0.0, 0.0)])); - pub static ref PAULI_Z: QuantumGate = matrix!([complex!(1.0, 0.0), complex!( 0.0, 0.0)]; - [complex!(0.0, 0.0), complex!(-1.0, 0.0)]); + pub static ref PAULI_Z: QuantumGate = ("Pauli-Z", matrix!([complex!(1.0, 0.0), complex!( 0.0, 0.0)]; + [complex!(0.0, 0.0), complex!(-1.0, 0.0)])); - pub static ref CNOT: QuantumGate = matrix!([complex!(1.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0)]; - [complex!(0.0, 0.0), complex!(1.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0)]; - [complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(1.0, 0.0)]; - [complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(1.0, 0.0), complex!(0.0, 0.0)]); + pub static ref CNOT: QuantumGate = ("CNOT", matrix!([complex!(1.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0)]; + [complex!(0.0, 0.0), complex!(1.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0)]; + [complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(1.0, 0.0)]; + [complex!(0.0, 0.0), complex!(0.0, 0.0), complex!(1.0, 0.0), complex!(0.0, 0.0)])); } diff --git a/libpsi-core/src/core/runtime.rs b/libpsi-core/src/core/runtime.rs index 5b0a45f..0937f3c 100644 --- a/libpsi-core/src/core/runtime.rs +++ b/libpsi-core/src/core/runtime.rs @@ -19,7 +19,7 @@ pub trait RuntimeBase { fn get_circuit(&self) -> &QuantumCircuit; } -pub trait Runtime { - fn new(circuit: QuantumCircuit) -> Self; +pub trait Runtime<'a, T: RuntimeBase = Self> { + fn new(circuit: &'a QuantumCircuit) -> Self; fn execute(&self, repeat: usize) -> Vec; } -- cgit v1.3