Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Target and InstructionProperties representations to rust #12292

Merged
merged 161 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 145 commits
Commits
Show all changes
161 commits
Select commit Hold shift + click to select a range
5c86791
Initial: Add `Target` class to `_accelerate`
raynelfss Apr 4, 2024
1d50653
Fix: Remove empty property check
raynelfss Apr 4, 2024
7135d72
Merge branch 'Qiskit:main' into move-target
raynelfss Apr 4, 2024
7d0982e
Merge branch 'Qiskit:main' into move-target
raynelfss Apr 5, 2024
ecc4668
Add: Instructions property
raynelfss Apr 5, 2024
506b1bd
Chore: comments and deprecated methods
raynelfss Apr 5, 2024
f8064bf
Chore: Remove redundant code
raynelfss Apr 5, 2024
e4e53ce
Add: `InstructionProperties` class and type checkers
raynelfss Apr 5, 2024
b15e762
Merge branch 'Qiskit:main' into move-target
raynelfss Apr 6, 2024
3d82845
Add: Setter and Getter for calibration in `InstructionProperty`
raynelfss Apr 6, 2024
fa2baab
Add: `update_instruction_properties` to Target.
raynelfss Apr 6, 2024
90b7081
Add: Update_from_instruction_schedule_map
raynelfss Apr 8, 2024
a65bf82
Add: Complete `update_from_instruction_schedule_map1
raynelfss Apr 8, 2024
c00ab10
Add: instruction_schedule_map property.
raynelfss Apr 8, 2024
10cec4f
Fix: Key issue in `update_from_instruction_schedule_map`
raynelfss Apr 9, 2024
12cccca
Fix: Use PyResult Value for void functon
raynelfss Apr 10, 2024
c3d79ff
Add: Python wrapping for Target
raynelfss Apr 10, 2024
5e2d100
Merge branch 'Qiskit:main' into move-target
raynelfss Apr 10, 2024
be6bf15
Add: `qargs` property
raynelfss Apr 10, 2024
28e2e01
Add: `qargs_for_operation_name` function.
raynelfss Apr 10, 2024
1f9bdbf
Add: durations method for Target
raynelfss Apr 10, 2024
dd7e115
Add: InstructionProperties wrapper in python
raynelfss Apr 11, 2024
f58fb09
Fix: InstructionProperties could not receive calibrations
raynelfss Apr 11, 2024
04bca9f
Add: more methods to Target in `target.rs`
raynelfss Apr 12, 2024
bc089cc
Fix: missing return value in `operations_for_args`
raynelfss Apr 12, 2024
6fc8679
Fix: Bad compatibility with InstructionProperties
raynelfss Apr 12, 2024
3fec978
Add: `operation_names_for_qargs` to Target
raynelfss Apr 12, 2024
01d146a
Merge branch 'Qiskit:main' into move-target
raynelfss Apr 12, 2024
020493d
Add: instruction_supported method to rust and python:
raynelfss Apr 13, 2024
abe88cf
Add: changes to add_instruction function to increase functionality.
raynelfss Apr 13, 2024
94cbb85
Fix: Backwards compatibility with `add_instruction`
raynelfss Apr 13, 2024
3063856
Fix: Gate Map behavior didn't match #11422
raynelfss Apr 15, 2024
7006e88
Add: `has_calibration` method to Target
raynelfss Apr 15, 2024
24a2fac
Add: `get_calibraton` method to Target
raynelfss Apr 15, 2024
2da6774
Add: `instruction_properties` method to Target
raynelfss Apr 15, 2024
1fae1d7
Add: `build_coupling_map` and helper methods
raynelfss Apr 16, 2024
644089f
Add: `get_non_global_operation_names` to Target.
raynelfss Apr 17, 2024
5d2ba5a
Add: Missing properties
raynelfss Apr 17, 2024
2f5063e
Add: `from_configuration` classmethod to Target.
raynelfss Apr 17, 2024
fc3b07e
Add: Magic methods to Rust and Python
raynelfss Apr 17, 2024
c345397
Fix: Bugs when fetching qargs or operations
raynelfss Apr 18, 2024
4b5a16d
Chore: Prepare for Draft PR
raynelfss Apr 18, 2024
22d1d05
Merge branch 'main' into move-target
raynelfss Apr 18, 2024
4b7aed3
Fix: target not being recognized as a module
raynelfss Apr 18, 2024
d71e527
Fix: Change HashMap to IndexMap
raynelfss Apr 19, 2024
25c0595
Fix: Move InstructionProperties fully to Rust
raynelfss Apr 19, 2024
d97c13b
Merge branch 'Qiskit:main' into move-target
raynelfss Apr 19, 2024
8e141d9
Fix: Make Target inherit from Rust
raynelfss Apr 19, 2024
ba74a04
Fix: Recognize None in `operation_for_qargs`.
raynelfss Apr 19, 2024
331ab42
Fix: Make InstructionProperties subclassable.
raynelfss Apr 21, 2024
db05c90
Merge branch 'Qiskit:main' into move-target
raynelfss Apr 21, 2024
d2ea839
Fix: errors in `instruction_properties` and others:
raynelfss Apr 21, 2024
949bd4f
Merge branch 'Qiskit:main' into move-target
raynelfss Apr 22, 2024
5c0adb3
Fix: call `isclass` from rust, instead of passing it from Python.
raynelfss Apr 22, 2024
fcc7727
Fix: Move `update_from_instruction_schedule_map` to rust.
raynelfss Apr 23, 2024
b2ce752
Fix: Move `durations` to rust.
raynelfss Apr 23, 2024
9e30296
Fix: Move `timing_constraints` to rust
raynelfss Apr 23, 2024
b637a7f
Fix: Move operations_from_name fully to rust
raynelfss Apr 23, 2024
98e2c65
Fix: `instruction_supported` method:
raynelfss Apr 23, 2024
b5c396e
Fix: errors in `from_configuration` class method.
raynelfss Apr 23, 2024
879bcc2
Merge branch 'Qiskit:main' into move-target
raynelfss Apr 23, 2024
94a1b53
Fix: Import `InstructionScheduleMap` directly instead of passing.
raynelfss Apr 24, 2024
f189528
Docs: Add docstrings to rust functions
raynelfss Apr 25, 2024
37fbf90
Add: Make `Target` and `InstructionProperties` pickleable.
raynelfss Apr 25, 2024
d2e2338
Fix: Wrong calibration assignment in __setstate__
raynelfss Apr 25, 2024
f34ff4b
Refactor: HashableVec is now Qarg
raynelfss Apr 29, 2024
05ac76a
Add: `get` function to target.
raynelfss Apr 29, 2024
89c7dea
Fix: Remove unnecessary Optional values in gate_map.
raynelfss Apr 30, 2024
7d59c6a
Refactor: `calibration` is for `InstructionProperties`
raynelfss May 1, 2024
340cf9c
Merge branch 'main' into move-target
raynelfss May 2, 2024
ee6407b
Fix: Temporary speedup for `gate_map` access
raynelfss May 2, 2024
a9b2119
Fix: Incorrect extractions for `InstructionProperties`
raynelfss May 3, 2024
14f80be
Merge branch 'main' into move-target
raynelfss May 3, 2024
3d87163
Fix: Hide all private attributes in `Target`
raynelfss May 5, 2024
83fd1c1
Add: New representation of gate_map using new pyclasses:
raynelfss May 6, 2024
ff3e797
Merge branch 'main' into move-target
raynelfss May 6, 2024
b953605
Add: Use custom datatypes to return values to Python.
raynelfss May 6, 2024
5dabaaf
Fix: Extend `InstructionProperties` to be subclassable using `__init__:
raynelfss May 7, 2024
1d98941
Refactor: Split target into its own module
raynelfss May 7, 2024
09cd63d
Fix: Rest of failing tests in Target
raynelfss May 8, 2024
defb0c9
Add: New GateMap Structure
raynelfss May 9, 2024
ab6c00f
Fix: Make new subclasses pickleable
raynelfss May 10, 2024
2ba35a2
Fix: Remove redundant lookup in Target (#12373)
raynelfss May 10, 2024
71873ab
Merge branch 'main' into move-target
raynelfss May 10, 2024
a4e2025
Format: `mod.rs` qubit_comparison to one line.
raynelfss May 10, 2024
183bb5e
Add: `GateMapKeys` object in GateMap:
raynelfss May 10, 2024
2e80be4
Add: __sub__ method to GateMapKeys
raynelfss May 10, 2024
92b787d
Fix: Modify `GateMap` to store values in Python heap.
raynelfss May 10, 2024
9702ddc
Fix: Remove duplicate import of `IndexSet::into_iter` in `GateMap`.
raynelfss May 12, 2024
2d46d87
Fix:: Adapt to target changes (#12288)
raynelfss May 12, 2024
97d9341
Merge branch 'main' into move-target
raynelfss May 12, 2024
9df0586
Fix: Incorrect creation of parameters in `update_from_instruction_sch…
raynelfss May 13, 2024
2575431
Fix: More failing tests
raynelfss May 13, 2024
37070b2
Add: Macro rules for qargs and other sequences.
raynelfss May 14, 2024
7bfb9cd
Docs: Add necessary docstrings to all new rust functions.
raynelfss May 15, 2024
d434f02
Merge branch 'main' into move-target
raynelfss May 15, 2024
ada4738
Merge branch 'main' into move-target
raynelfss May 15, 2024
a957406
Merge branch 'main' into move-target
raynelfss May 16, 2024
a3fcd78
Fix: Use `GILOneCell` and remove `Qargs`
raynelfss May 20, 2024
aeefdab
Merge branch 'main' into move-target
raynelfss May 20, 2024
bf1fa67
Fix: Cast `Qargs` to `Tuple` in specific situations
raynelfss May 22, 2024
ae55a38
Merge branch 'main' into move-target
raynelfss May 22, 2024
6e2742d
Merge branch 'main' into move-target
raynelfss May 23, 2024
1e0f9c0
Add: Make `Target` Representable in Rust
raynelfss May 28, 2024
52dbec0
Refactor: Remove previour changes to unrelated files.
raynelfss May 28, 2024
31cc1f1
Add: rust native functions to target
raynelfss May 29, 2024
05ddc79
Merge branch 'main' into move-target
raynelfss May 29, 2024
d5f635f
Fix: Remove all unnecessary python method calls.
raynelfss May 29, 2024
7a0d267
Format: Fix lint
raynelfss May 29, 2024
ee914aa
Merge branch 'main' into move-target
raynelfss May 29, 2024
aadfeaa
Fix: Wrong return value for `BaseTarget.qargs`
raynelfss May 30, 2024
9f582ad
Add: Temporary Instruction representation in rust.
raynelfss Jun 3, 2024
76d1b11
Add: Native representation of coupling graph
raynelfss Jun 3, 2024
22229f0
Merge branch 'main' into move-target
raynelfss Jun 3, 2024
f4318d2
Fix: Wrong attribute extraction for `GateRep`
raynelfss Jun 3, 2024
b4b438e
Remove: `CouplingGraph` rust native representation.
raynelfss Jun 3, 2024
27febcc
Format: Remove stray whitespace
raynelfss Jun 3, 2024
cdf762e
Add: `get_non_global_op_names` as a rust native function
raynelfss Jun 3, 2024
29c34ce
Merge branch 'Qiskit:main' into move-target
raynelfss Jun 4, 2024
cf8fa99
Fix: Use Ahash for Hashing
raynelfss Jun 10, 2024
c0d9b7b
Merge branch 'main' into move-target
raynelfss Jun 10, 2024
ed97436
Format: new changes to `lib.rs`
raynelfss Jun 11, 2024
0c671dd
Merge branch 'main' into move-target
raynelfss Jun 11, 2024
8e42b49
Format: Adapt to new lint rules
raynelfss Jun 11, 2024
03da436
Merge branch 'main' into move-target
raynelfss Jun 13, 2024
0fd4316
Merge branch 'main' into move-target
raynelfss Jun 13, 2024
529128a
Fix: Use new gates infrastructure (#12459)
raynelfss Jun 14, 2024
d760332
Merge branch 'main' into move-target
raynelfss Jun 14, 2024
a359071
Format: Fix rust formatting
raynelfss Jun 14, 2024
3406c8b
Add: rust-native method to obtain Operstion objects.
raynelfss Jun 14, 2024
934b825
Add: Comparison methods for `Param`
raynelfss Jun 14, 2024
00ce1cb
FIx: Add display methods for `Params`
raynelfss Jun 15, 2024
752e058
Format: Fix lint test
raynelfss Jun 17, 2024
7192f7b
Merge branch 'main' into move-target
raynelfss Jun 20, 2024
d347e7b
Format: Wrong merge conflict solve
raynelfss Jun 20, 2024
8b3b3ad
Merge branch 'main' into move-target
raynelfss Jun 26, 2024
ce4ff6b
Merge branch 'main' into move-target
raynelfss Jun 26, 2024
90b7b1e
Merge branch 'main' into move-target
raynelfss Jun 26, 2024
f03dc15
Merge branch 'main' into move-target
raynelfss Jul 1, 2024
71bc4c5
Fix: Improve rust methods to use iterators.
raynelfss Jul 1, 2024
4277339
Merge branch 'main' into move-target
raynelfss Jul 1, 2024
3b64cf6
Format: Remove extra blankspace
raynelfss Jul 1, 2024
88f4020
Fix: Remove `text_signature`, use `signature` instead.
raynelfss Jul 2, 2024
98eaa45
Fix: Rectify the behavior of `qargs`
raynelfss Jul 2, 2024
7b14c36
Merge branch 'main' into move-target
raynelfss Jul 2, 2024
1a61ebb
Merge branch 'main' into move-target
raynelfss Jul 5, 2024
79752ee
Fix: Corrections from Matthew's review
raynelfss Jul 7, 2024
7c9cd9d
Merge branch 'main' into move-target
raynelfss Jul 8, 2024
9e1e111
Merge branch 'Qiskit:main' into move-target
raynelfss Jul 9, 2024
4f24322
Implement a nullable dict-like structure for IndexMap (#2)
raynelfss Jul 10, 2024
b0506d5
Merge branch 'main' into move-target
raynelfss Jul 10, 2024
adc0231
Merge branch 'Qiskit:main' into move-target
raynelfss Jul 11, 2024
69cbc4e
Fix: Use `Mapping` as the metaclass for `Target`
raynelfss Jul 15, 2024
743c55a
Merge branch 'main' into move-target
raynelfss Jul 15, 2024
54734f0
Fix: Make `Target` crate-private.
raynelfss Jul 16, 2024
d5392ea
Merge branch 'main' into move-target
raynelfss Jul 16, 2024
367d711
Fix: Comments from Matthew's review
raynelfss Jul 23, 2024
e7296ba
Merge branch 'main' into move-target
raynelfss Jul 23, 2024
f6e8189
Merge branch 'main' into move-target
raynelfss Jul 23, 2024
96bd389
Merge branch 'main' into move-target
raynelfss Jul 24, 2024
70eafce
Fix: Adapt to #12730
raynelfss Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// 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<'_>) -> PyResult<String> {
let mut output = "InstructionProperties(".to_owned();
if let Some(duration) = self.duration {
output.push_str("duration=");
output.push_str(duration.to_string().as_str());
output.push_str(", ");
} else {
output.push_str("duration=None, ");
}

if let Some(error) = self.error {
output.push_str("error=");
output.push_str(error.to_string().as_str());
output.push_str(", ");
} else {
output.push_str("error=None, ");
}
raynelfss marked this conversation as resolved.
Show resolved Hide resolved
Ok(output)
}
}
Loading
Loading