Skip to content

Commit

Permalink
Minor fix for beta.2 (#356)
Browse files Browse the repository at this point in the history
* Minor fix for beta.2

* Added additional unittests

* Update devices.rs

* Fixing linting for circuitdag

* clippy linting

* further clippy linting

* Modifications added to add_to_front() as well

Co-authored-by: kbarkhqs <[email protected]>
Co-authored-by: mlodi-hqs <[email protected]>
  • Loading branch information
3 people authored Sep 14, 2022
1 parent 8f67e27 commit 9f363b2
Show file tree
Hide file tree
Showing 24 changed files with 256 additions and 154 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This changelog track changes to the qoqo project starting at version v0.5.0

## 1.1.0-beta.1

* Allowed creating PragmaSetStateVector from float or integer numpy arrays.

## 1.1.0-alpha.1

* Added `InputBit` to set bit in a (readout) bit register to a value.
Expand Down
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 qoqo-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "qoqo-macros"
version = "1.1.0-beta.1"
version = "1.1.0-beta.2"
authors = ["HQS Quantum Simulations <[email protected]>"]
license = "Apache-2.0"
readme = "../README.md"
Expand Down
19 changes: 19 additions & 0 deletions qoqo-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,21 @@ pub fn devicewrapper(
GenericDeviceWrapper{ internal: self.internal.to_generic_device()}
}

/// Turns Device into GenericDevice
///
/// Can be used as a generic interface for devices when a boxed dyn trait object cannot be used
/// (for example when the interface needs to be serialized)
///
/// Returns:
/// GenericDevice: The device in generic representation
///
/// Note:
/// GenericDevice uses nested HashMaps to represent the most general device connectivity.
/// The memory usage will be inefficient for devices with large qubit numbers.
fn to_generic_device(&self) -> GenericDeviceWrapper {
GenericDeviceWrapper{ internal: self.internal.to_generic_device()}
}

/// Returns a copy of the device (copy here produces a deepcopy).
///
/// Returns:
Expand Down Expand Up @@ -848,6 +863,10 @@ pub fn devicewrapper(
})
}

fn __repr__(&self) -> String{
format!("{:?}", self.internal)
}


/// Return the __richcmp__ magic method to perform rich comparison operations on mixed system.
///
Expand Down
6 changes: 3 additions & 3 deletions qoqo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "qoqo"
version = "1.1.0-beta.1"
version = "1.1.0-beta.2"
authors = ["HQS Quantum Simulations <[email protected]>"]
license = "Apache-2.0"
homepage = "https://github.com/HQSquantumsimulations/qoqo"
Expand Down Expand Up @@ -32,8 +32,8 @@ num-complex = "0.4"
thiserror = "1.0"
qoqo_calculator = { version="1.1" }
qoqo_calculator_pyo3 = {version="1.1", default-features=false}
qoqo-macros = {version="1.1.0-beta.1", path="../qoqo-macros"}
roqoqo = {version="1.1.0-beta.1", path="../roqoqo", features=["serialize", "overrotate"]}
qoqo-macros = {version="1.1.0-beta.2", path="../qoqo-macros"}
roqoqo = {version="1.1.0-beta.2", path="../roqoqo", features=["serialize", "overrotate"]}
numpy = "0.17"
bincode = "1.3"
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion qoqo/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "qoqo"
version = "1.1.0-beta.1"
version = "1.1.0-beta.2"
dependencies = [
'numpy',
'qoqo_calculator_pyo3>=1.1.0',
Expand Down
10 changes: 5 additions & 5 deletions qoqo/qoqo/DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -8777,7 +8777,7 @@ LICENSE:


====================================================
qoqo 1.1.0-beta.1
qoqo 1.1.0-beta.2
https://github.com/HQSquantumsimulations/qoqo
by HQS Quantum Simulations <[email protected]>
Quantum computing circuit toolkit. Python interface of roqoqo
Expand Down Expand Up @@ -8989,7 +8989,7 @@ LICENSE:


====================================================
qoqo-macros 1.1.0-beta.1
qoqo-macros 1.1.0-beta.2
by HQS Quantum Simulations <[email protected]>
Macros for the qoqo crate
License: Apache-2.0
Expand Down Expand Up @@ -11075,7 +11075,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


====================================================
roqoqo 1.1.0-beta.1
roqoqo 1.1.0-beta.2
https://github.com/HQSquantumsimulations/qoqo
by HQS Quantum Simulations <[email protected]>
Rust Quantum Computing Toolkit by HQS
Expand Down Expand Up @@ -11287,7 +11287,7 @@ LICENSE:


====================================================
roqoqo-derive 1.1.0-beta.1
roqoqo-derive 1.1.0-beta.2
by HQS Quantum Simulations <[email protected]>
Macros for the roqoqo crate
License: Apache-2.0
Expand Down Expand Up @@ -11498,7 +11498,7 @@ LICENSE:


====================================================
roqoqo-test 1.1.0-beta.1
roqoqo-test 1.1.0-beta.2
https://github.com/HQSquantumsimulations/qoqo
by HQS Quantum Simulations <[email protected]>
Testing helper functions for roqoqo toolkit
Expand Down
20 changes: 6 additions & 14 deletions qoqo/src/circuitdag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,17 @@ impl CircuitDagWrapper {
current_front_layer: Vec<usize>,
to_be_executed: usize,
) -> PyResult<Vec<usize>> {
Ok(self
.internal
self.internal
.new_front_layer(
already_executed.as_slice(),
current_front_layer.as_slice(),
&to_be_executed,
)
.map_err(|_| {
PyValueError::new_err(format!(
"The Operation to be executed is not in the current front layer."
))
})?)
PyValueError::new_err(
"The Operation to be executed is not in the current front layer.".to_string(),
)
})
}

/// Returns an iterator over the possible parallel blocks in circuit that can be executed simultaneously
Expand Down Expand Up @@ -339,14 +338,7 @@ impl CircuitDagWrapper {
/// Returns the list of the successors of a given node in the CircuitDag.
///
pub fn successors(&self, node: usize) -> Vec<usize> {
let mut iter = self.internal.successors(node);
let mut vec: Vec<usize> = Vec::new();

while let Some(nxt) = iter.next() {
vec.push(nxt.index())
}

vec
self.internal.successors(node).map(|n| n.index()).collect()
}

/// Returns the list of nodes of commuting operations in CircuitDag.
Expand Down
24 changes: 23 additions & 1 deletion qoqo/src/operations/pragma_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,32 @@ impl PragmaSetStateVectorWrapper {
fn new(statevector: Py<PyAny>) -> PyResult<Self> {
let try_cast: PyResult<Array1<Complex64>> =
Python::with_gil(|py| -> PyResult<Array1<Complex64>> {
let extracted = PyReadonlyArray1::extract(statevector.as_ref(py))?;
let extracted: PyReadonlyArray1<Complex64> = statevector.as_ref(py).extract()?;
let statevec: Array1<Complex64> = extracted.to_owned_array();
Ok(statevec)
});
let try_cast = try_cast.or_else(|_| {
Python::with_gil(|py| -> PyResult<Array1<Complex64>> {
let extracted: PyReadonlyArray1<f64> = statevector.as_ref(py).extract()?;
let statevec: Array1<f64> = extracted.to_owned_array();
let statevec: Array1<Complex64> = statevec
.into_iter()
.map(|f| Complex64::new(f, 0.0))
.collect();
Ok(statevec)
})
});
let try_cast = try_cast.or_else(|_| {
Python::with_gil(|py| -> PyResult<Array1<Complex64>> {
let extracted: PyReadonlyArray1<isize> = statevector.as_ref(py).extract()?;
let statevec: Array1<isize> = extracted.to_owned_array();
let statevec: Array1<Complex64> = statevec
.into_iter()
.map(|f| Complex64::new(f as f64, 0.0))
.collect();
Ok(statevec)
})
});
match try_cast {
Ok(array) => Ok(Self {
internal: PragmaSetStateVector::new(array),
Expand Down
16 changes: 6 additions & 10 deletions qoqo/tests/integration/circuitdag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,11 @@ fn test_copy() {
let empty_dag_copy = empty_dag.call_method0("__copy__").unwrap();

let full_dag_comparison =
bool::extract(dag_copy.call_method1("__eq__", (&(*dag),)).unwrap()).unwrap();
bool::extract(dag_copy.call_method1("__eq__", (dag,)).unwrap()).unwrap();
assert!(full_dag_comparison);

let empty_dag_comparison = bool::extract(
empty_dag_copy
.call_method1("__eq__", (&(*empty_dag),))
.unwrap(),
)
.unwrap();
let empty_dag_comparison =
bool::extract(empty_dag_copy.call_method1("__eq__", (empty_dag,)).unwrap()).unwrap();
assert!(empty_dag_comparison);
})
}
Expand Down Expand Up @@ -487,7 +483,7 @@ fn test_parallel_blocks() {
let par_bl = dag.call_method0("parallel_blocks").unwrap();

let vec0 = par_bl.get_item(0).unwrap();
for el in vec0.call0() {
if let Ok(el) = vec0.call0() {
let helper1 = bool::extract(
el.get_item(0)
.unwrap()
Expand All @@ -506,7 +502,7 @@ fn test_parallel_blocks() {
}

let vec1 = par_bl.get_item(1).unwrap();
for el in vec1.call0() {
if let Ok(el) = vec1.call0() {
let helper1 = bool::extract(
el.get_item(0)
.unwrap()
Expand All @@ -525,7 +521,7 @@ fn test_parallel_blocks() {
}

let vec2 = par_bl.get_item(2).unwrap();
for el in vec2.call0() {
if let Ok(el) = vec2.call0() {
let helper1 = bool::extract(
el.get_item(0)
.unwrap()
Expand Down
Loading

0 comments on commit 9f363b2

Please sign in to comment.