Skip to content

Commit

Permalink
Merge remote-tracking branch 'ibm/main' into sparse-observable/maths
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelishman committed Oct 29, 2024
2 parents 68b5c56 + e89cb47 commit 9c2983f
Show file tree
Hide file tree
Showing 28 changed files with 808 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
lcov --add-tracefile python.info --add-tracefile rust.info --output-file coveralls.info
- name: Coveralls
uses: coverallsapp/[email protected].0
uses: coverallsapp/[email protected].4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coveralls.info
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
matrix:
# Normally we test min and max version but we can't run python
# 3.9 on arm64 until actions/setup-python#808 is resolved
python-version: ["3.10", "3.12"]
python-version: ["3.10", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
Expand All @@ -44,7 +44,7 @@ jobs:
python -m pip install -U -r requirements.txt -c constraints.txt
python -m pip install -U -r requirements-dev.txt -c constraints.txt
python -m pip install -c constraints.txt -e .
if: matrix.python-version == '3.12'
if: matrix.python-version == '3.13'
- name: 'Install optionals'
run: |
python -m pip install -r requirements-optional.txt -c constraints.txt
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/wheels-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ on:
default: "default"
required: false

wheels-32bit:
wheels-32bit:
description: >-
The action to take for Tier 1 wheels.
Choose from 'default', 'build' or 'skip'.
Expand All @@ -36,23 +36,23 @@ on:
default: "default"
required: false

wheels-linux-s390x:
wheels-linux-s390x:
description: >-
The action to take for Linux s390x wheels.
Choose from 'default', 'build' or 'skip'.
type: string
default: "default"
required: false

wheels-linux-ppc64le:
wheels-linux-ppc64le:
description: >-
The action to take for Linux ppc64le wheels.
Choose from 'default', 'build' or 'skip'.
type: string
default: "default"
required: false

wheels-linux-aarch64:
wheels-linux-aarch64:
description: >-
The action to take for Linux AArch64 wheels.
Choose from 'default', 'build' or 'skip'.
Expand All @@ -77,7 +77,7 @@ on:
type: boolean
default: true
required: false


jobs:
wheels-tier-1:
Expand Down Expand Up @@ -126,7 +126,7 @@ jobs:
env:
PGO_WORK_DIR: ${{ github.workspace }}/pgo-data
PGO_OUT_PATH: ${{ github.workspace }}/merged.profdata
- uses: pypa/cibuildwheel@v2.19.2
- uses: pypa/cibuildwheel@v2.21.3
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl
Expand All @@ -151,7 +151,7 @@ jobs:
with:
components: llvm-tools-preview
- name: Build wheels
uses: pypa/cibuildwheel@v2.19.2
uses: pypa/cibuildwheel@v2.21.3
env:
CIBW_SKIP: 'pp* cp36-* cp37-* cp38-* *musllinux* *amd64 *x86_64'
- uses: actions/upload-artifact@v4
Expand All @@ -173,7 +173,7 @@ jobs:
- uses: docker/setup-qemu-action@v3
with:
platforms: all
- uses: pypa/cibuildwheel@v2.19.2
- uses: pypa/cibuildwheel@v2.21.3
env:
CIBW_ARCHS_LINUX: s390x
CIBW_TEST_SKIP: "cp*"
Expand All @@ -196,7 +196,7 @@ jobs:
- uses: docker/setup-qemu-action@v3
with:
platforms: all
- uses: pypa/cibuildwheel@v2.19.2
- uses: pypa/cibuildwheel@v2.21.3
env:
CIBW_ARCHS_LINUX: ppc64le
CIBW_TEST_SKIP: "cp*"
Expand All @@ -218,7 +218,7 @@ jobs:
- uses: docker/setup-qemu-action@v3
with:
platforms: all
- uses: pypa/cibuildwheel@v2.19.2
- uses: pypa/cibuildwheel@v2.21.3
env:
CIBW_ARCHS_LINUX: aarch64
CIBW_TEST_COMMAND: cp -r {project}/test . && QISKIT_PARALLEL=FALSE stestr --test-path test/python run --abbreviate -n test.python.compiler.test_transpiler
Expand Down
2 changes: 1 addition & 1 deletion asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dvcs": "git",
"environment_type": "virtualenv",
"show_commit_url": "http://github.com/Qiskit/qiskit/commit/",
"pythons": ["3.9", "3.10", "3.11", "3.12"],
"pythons": ["3.9", "3.10", "3.11", "3.12", "3.13"],
"benchmark_dir": "test/benchmarks",
"env_dir": ".asv/env",
"results_dir": ".asv/results"
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ parameters:
- name: "supportedPythonVersions"
displayName: "All supported versions of Python"
type: object
default: ["3.9", "3.10", "3.11", "3.12"]
default: ["3.9", "3.10", "3.11", "3.12", "3.13"]

- name: "minimumPythonVersion"
displayName: "Minimum supported version of Python"
Expand All @@ -47,7 +47,7 @@ parameters:
- name: "maximumPythonVersion"
displayName: "Maximum supported version of Python"
type: string
default: "3.12"
default: "3.13"

# These two versions of Python can be chosen somewhat arbitrarily, but we get
# slightly better coverage per PR if they're neither the maximum nor minimum
Expand Down
4 changes: 0 additions & 4 deletions constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# https://github.com/Qiskit/qiskit-terra/issues/10345 for current details.
scipy<1.11; python_version<'3.12'

# Temporary pin to avoid CI issues caused by scipy 1.14.0
# See https://github.com/Qiskit/qiskit/issues/12655 for current details.
scipy==1.13.1; python_version=='3.12'

# z3-solver from 4.12.3 onwards upped the minimum macOS API version for its
# wheels to 11.7. The Azure VM images contain pre-built CPythons, of which at
# least CPython 3.8 was compiled for an older macOS, so does not match a
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 @@ -37,6 +37,7 @@ pub mod nlayout;
pub mod optimize_1q_gates;
pub mod pauli_exp_val;
pub mod remove_diagonal_gates_before_measure;
pub mod remove_identity_equiv;
pub mod results;
pub mod sabre;
pub mod sampled_exp_val;
Expand Down
149 changes: 149 additions & 0 deletions crates/accelerate/src/remove_identity_equiv.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// 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 num_complex::Complex64;
use num_complex::ComplexFloat;
use pyo3::prelude::*;
use rustworkx_core::petgraph::stable_graph::NodeIndex;

use crate::nlayout::PhysicalQubit;
use crate::target_transpiler::Target;
use qiskit_circuit::dag_circuit::DAGCircuit;
use qiskit_circuit::operations::Operation;
use qiskit_circuit::operations::OperationRef;
use qiskit_circuit::operations::Param;
use qiskit_circuit::operations::StandardGate;
use qiskit_circuit::packed_instruction::PackedInstruction;

#[pyfunction]
#[pyo3(signature=(dag, approx_degree=Some(1.0), target=None))]
fn remove_identity_equiv(
dag: &mut DAGCircuit,
approx_degree: Option<f64>,
target: Option<&Target>,
) {
let mut remove_list: Vec<NodeIndex> = Vec::new();

let get_error_cutoff = |inst: &PackedInstruction| -> f64 {
match approx_degree {
Some(degree) => {
if degree == 1.0 {
f64::EPSILON
} else {
match target {
Some(target) => {
let qargs: Vec<PhysicalQubit> = dag
.get_qargs(inst.qubits)
.iter()
.map(|x| PhysicalQubit::new(x.0))
.collect();
let error_rate = target.get_error(inst.op.name(), qargs.as_slice());
match error_rate {
Some(err) => err * degree,
None => f64::EPSILON.max(1. - degree),
}
}
None => f64::EPSILON.max(1. - degree),
}
}
}
None => match target {
Some(target) => {
let qargs: Vec<PhysicalQubit> = dag
.get_qargs(inst.qubits)
.iter()
.map(|x| PhysicalQubit::new(x.0))
.collect();
let error_rate = target.get_error(inst.op.name(), qargs.as_slice());
match error_rate {
Some(err) => err,
None => f64::EPSILON,
}
}
None => f64::EPSILON,
},
}
};

for op_node in dag.op_nodes(false) {
let inst = dag.dag()[op_node].unwrap_operation();
match inst.op.view() {
OperationRef::Standard(gate) => {
let (dim, trace) = match gate {
StandardGate::RXGate | StandardGate::RYGate | StandardGate::RZGate => {
if let Param::Float(theta) = inst.params_view()[0] {
let trace = (theta / 2.).cos() * 2.;
(2., trace)
} else {
continue;
}
}
StandardGate::RXXGate
| StandardGate::RYYGate
| StandardGate::RZZGate
| StandardGate::RZXGate => {
if let Param::Float(theta) = inst.params_view()[0] {
let trace = (theta / 2.).cos() * 4.;
(4., trace)
} else {
continue;
}
}
_ => {
// Skip global phase gate
if gate.num_qubits() < 1 {
continue;
}
if let Some(matrix) = gate.matrix(inst.params_view()) {
let dim = matrix.shape()[0] as f64;
let trace = matrix.diag().iter().sum::<Complex64>().abs();
(dim, trace)
} else {
continue;
}
}
};
let error = get_error_cutoff(inst);
let f_pro = (trace / dim).powi(2);
let gate_fidelity = (dim * f_pro + 1.) / (dim + 1.);
if (1. - gate_fidelity).abs() < error {
remove_list.push(op_node)
}
}
OperationRef::Gate(gate) => {
// Skip global phase like gate
if gate.num_qubits() < 1 {
continue;
}
if let Some(matrix) = gate.matrix(inst.params_view()) {
let error = get_error_cutoff(inst);
let dim = matrix.shape()[0] as f64;
let trace: Complex64 = matrix.diag().iter().sum();
let f_pro = (trace / dim).abs().powi(2);
let gate_fidelity = (dim * f_pro + 1.) / (dim + 1.);
if (1. - gate_fidelity).abs() < error {
remove_list.push(op_node)
}
}
}
_ => continue,
}
}
for node in remove_list {
dag.remove_op_node(node);
}
}

pub fn remove_identity_equiv_mod(m: &Bound<PyModule>) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(remove_identity_equiv))?;
Ok(())
}
Loading

0 comments on commit 9c2983f

Please sign in to comment.