Skip to content

Commit

Permalink
Merge branch 'main' into move-equivalence
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss authored Jul 25, 2024
2 parents ba90411 + 898fdec commit 9f4bfb7
Show file tree
Hide file tree
Showing 32 changed files with 2,501 additions and 735 deletions.
2 changes: 1 addition & 1 deletion .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pull_request_rules:
actions:
backport:
branches:
- stable/1.1
- stable/1.2
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2"

[workspace.package]
version = "1.2.0"
version = "1.3.0"
edition = "2021"
rust-version = "1.70" # Keep in sync with README.md and rust-toolchain.toml.
license = "Apache-2.0"
Expand Down
1 change: 1 addition & 0 deletions crates/accelerate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub mod sampled_exp_val;
pub mod sparse_pauli_op;
pub mod stochastic_swap;
pub mod synthesis;
pub mod target_transpiler;
pub mod two_qubit_decompose;
pub mod uc_gate;
pub mod utils;
Expand Down
34 changes: 34 additions & 0 deletions crates/accelerate/src/target_transpiler/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This code is part of Qiskit.
//
// (C) Copyright IBM 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::{error::Error, fmt::Display};

/// Error thrown when operation key is not present in the Target
#[derive(Debug)]
pub struct TargetKeyError {
pub message: String,
}

impl TargetKeyError {
/// Initializes the new error
pub fn new_err(message: String) -> Self {
Self { message }
}
}

impl Display for TargetKeyError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)
}
}

impl Error for TargetKeyError {}
72 changes: 72 additions & 0 deletions crates/accelerate/src/target_transpiler/instruction_properties.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// This code is part of Qiskit.
//
// (C) Copyright IBM 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 pyo3::{prelude::*, pyclass};

/**
A representation of an ``InstructionProperties`` object.
*/
#[pyclass(
subclass,
name = "BaseInstructionProperties",
module = "qiskit._accelerate.target"
)]
#[derive(Clone, Debug)]
pub struct InstructionProperties {
#[pyo3(get, set)]
pub duration: Option<f64>,
#[pyo3(get, set)]
pub error: Option<f64>,
}

#[pymethods]
impl InstructionProperties {
/// Create a new ``BaseInstructionProperties`` object
///
/// Args:
/// duration (Option<f64>): The duration, in seconds, of the instruction on the
/// specified set of qubits
/// error (Option<f64>): The average error rate for the instruction on the specified
/// set of qubits.
/// calibration (Option<PyObject>): The pulse representation of the instruction.
#[new]
#[pyo3(signature = (duration=None, error=None))]
pub fn new(_py: Python<'_>, duration: Option<f64>, error: Option<f64>) -> Self {
Self { error, duration }
}

fn __getstate__(&self) -> PyResult<(Option<f64>, Option<f64>)> {
Ok((self.duration, self.error))
}

fn __setstate__(&mut self, _py: Python<'_>, state: (Option<f64>, Option<f64>)) -> PyResult<()> {
self.duration = state.0;
self.error = state.1;
Ok(())
}

fn __repr__(&self, _py: Python<'_>) -> String {
format!(
"InstructionProperties(duration={}, error={})",
if let Some(duration) = self.duration {
duration.to_string()
} else {
"None".to_string()
},
if let Some(error) = self.error {
error.to_string()
} else {
"None".to_string()
}
)
}
}
Loading

0 comments on commit 9f4bfb7

Please sign in to comment.