Skip to content

Commit

Permalink
Initial: Create Bits, Qubits, and Clbits
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss committed Dec 10, 2024
1 parent 17648eb commit 76d8758
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions crates/circuit/src/bits.rs
Original file line number Diff line number Diff line change
@@ -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}
1 change: 1 addition & 0 deletions crates/circuit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 76d8758

Please sign in to comment.