From 76d8758b0499c32c3fc5d77e4247eb29b35a8cbe Mon Sep 17 00:00:00 2001 From: Raynel Sanchez Date: Tue, 10 Dec 2024 15:46:01 -0500 Subject: [PATCH] Initial: Create `Bits`, `Qubits`, and `Clbits` --- crates/circuit/src/bits.rs | 46 ++++++++++++++++++++++++++++++++++++++ crates/circuit/src/lib.rs | 1 + 2 files changed, 47 insertions(+) create mode 100644 crates/circuit/src/bits.rs diff --git a/crates/circuit/src/bits.rs b/crates/circuit/src/bits.rs new file mode 100644 index 000000000000..39bd3a91b32b --- /dev/null +++ b/crates/circuit/src/bits.rs @@ -0,0 +1,46 @@ +// This code is part of Qiskit. +// +// (C) Copyright IBM 2023, 2024 +// +// This code is licensed under the Apache License, Version 2.0. You may +// obtain a copy of this license in the LICENSE.txt file in the root directory +// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +// +// Any modifications or derivative works of this code must retain this +// copyright notice, and modified files need to carry a notice indicating +// that they have been altered from the originals. + +use std::ops::{Deref, DerefMut}; + +use pyo3::prelude::*; + +/// Opaque struct representing a bit instance which can be stored in any circuit or register. +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct Bit { + // This is an opaque type, so it doesn't store anything but an alias. +} + +macro_rules! create_bit { + ($name:ident) => { + #[pyclass] + #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] + pub struct $name(Bit); + + impl Deref for $name { + type Target = Bit; + + fn deref(&self) -> &Self::Target { + &self.0 + } + } + + impl DerefMut for $name { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } + } + }; +} + +create_bit!{Qubit} +create_bit!{Clbit} \ No newline at end of file diff --git a/crates/circuit/src/lib.rs b/crates/circuit/src/lib.rs index a4064d44b917..a65cd24612d2 100644 --- a/crates/circuit/src/lib.rs +++ b/crates/circuit/src/lib.rs @@ -10,6 +10,7 @@ // copyright notice, and modified files need to carry a notice indicating // that they have been altered from the originals. +pub mod bits; pub mod bit_data; pub mod circuit_data; pub mod circuit_instruction;