Skip to content

Commit

Permalink
Merge remote-tracking branch 'ibm/main' into qasm2/phase-conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelishman committed Sep 28, 2023
2 parents 37bdef2 + daf3f4e commit 8688a82
Show file tree
Hide file tree
Showing 190 changed files with 3,099 additions and 2,403 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Backport metadata

# Mergify manages the opening of the backport PR, this workflow is just to extend its behaviour to
# do useful things like copying across the tagged labels and milestone from the base PR.

on:
pull_request:
types:
- opened
branches:
- 'stable/*'

jobs:
copy_metadata:
name: Copy metadata from base PR
runs-on: ubuntu-latest
if: github.repository == 'Qiskit/qiskit' && github.actor == 'mergify[bot]'

permissions:
pull-requests: write

steps:
- name: Copy metadata
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
# Split Mergify's ref name (e.g. 'mergify/bp/stable/0.25/pr-10828') on the final '-' to
# get the number of the PR that triggered Mergify.
IFS='-' read -ra split <<< "${{ github.event.pull_request.head.ref }}"
base_pr=${split[-1]}
gh pr --repo "${{ github.repository }}" view "$base_pr" --json labels,milestone > base_pr.json
add_labels="$(jq --raw-output '[.labels[].name] - ["stable backport potential"] | join(",")' base_pr.json)"
echo "New labels: '$add_labels'"
milestone="$(jq --raw-output '.milestone.title // ""' base_pr.json )"
echo "Milestone: '$milestone'"
echo "Targetting current PR '${{ github.event.number }}'"
# The GitHub API is sometimes weird about empty values - the REST API certainly treats
# "add-label" with an empty input not as a no-op but as a clear of all labels.
if [[ -n "$add_labels" && -n "$milestone" ]]; then
gh pr --repo "${{ github.repository }}" edit "${{ github.event.number }}" --add-label "$add_labels" --milestone "$milestone"
elif [[ -n "$add_labels" ]]; then
gh pr --repo "${{ github.repository }}" edit "${{ github.event.number }}" --add-label "$add_labels"
elif [[ -n "$milestone" ]]; then
gh pr --repo "${{ github.repository }}" edit "${{ github.event.number }}" --milestone "$milestone"
fi
10 changes: 5 additions & 5 deletions .github/workflows/docs_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
latest_tag: ${{ steps.latest_tag.outputs.latest_tag }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# We need to fetch the whole history so 'reno' can do its job and we can inspect tags.
fetch-depth: 0
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
path: qiskit

Expand Down Expand Up @@ -206,7 +206,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
path: 'qiskit'

Expand All @@ -215,9 +215,9 @@ jobs:
name: qiskit-translatables
path: 'deploy'

- name: Decrypt SSH secret key
- name: Deploy translations
id: ssh_key
run: tools/deploy_translatable_strings.sh
run: qiskit/tools/deploy_translatable_strings.sh
env:
encrypted_deploy_po_branch_key: ${{ secrets.ENCRYPTED_DEPLOY_PO_BRANCH_KEY }}
encrypted_deploy_po_branch_iv: ${{ secrets.ENCRYPTED_DEPLOY_PO_BRANCH_IV }}
40 changes: 6 additions & 34 deletions Cargo.lock

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

Binary file added circuit.qpy
Binary file not shown.
2 changes: 1 addition & 1 deletion crates/accelerate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ default = ["extension-module"]
extension-module = ["pyo3/extension-module"]

[dependencies]
rayon = "1.7"
rayon = "1.8"
numpy = "0.19.0"
rand = "0.8"
rand_pcg = "0.3"
Expand Down
46 changes: 39 additions & 7 deletions crates/accelerate/src/sabre_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// that they have been altered from the originals.
#![allow(clippy::too_many_arguments)]

use hashbrown::HashSet;
use ndarray::prelude::*;
use numpy::{IntoPyArray, PyArray, PyReadonlyArray2};
use pyo3::prelude::*;
Expand All @@ -28,6 +29,7 @@ use crate::sabre_swap::swap_map::SwapMap;
use crate::sabre_swap::{build_swap_map_inner, Heuristic, NodeBlockResults, SabreResult};

#[pyfunction]
#[pyo3(signature = (dag, neighbor_table, distance_matrix, heuristic, max_iterations, num_swap_trials, num_random_trials, seed=None, partial_layouts=vec![]))]
pub fn sabre_layout_and_routing(
py: Python,
dag: &SabreDAG,
Expand All @@ -36,20 +38,24 @@ pub fn sabre_layout_and_routing(
heuristic: &Heuristic,
max_iterations: usize,
num_swap_trials: usize,
num_layout_trials: usize,
num_random_trials: usize,
seed: Option<u64>,
mut partial_layouts: Vec<Vec<Option<u32>>>,
) -> (NLayout, PyObject, (SwapMap, PyObject, NodeBlockResults)) {
let run_in_parallel = getenv_use_multiple_threads();
let mut starting_layouts: Vec<Vec<Option<u32>>> =
(0..num_random_trials).map(|_| vec![]).collect();
starting_layouts.append(&mut partial_layouts);
let outer_rng = match seed {
Some(seed) => Pcg64Mcg::seed_from_u64(seed),
None => Pcg64Mcg::from_entropy(),
};
let seed_vec: Vec<u64> = outer_rng
.sample_iter(&rand::distributions::Standard)
.take(num_layout_trials)
.take(starting_layouts.len())
.collect();
let dist = distance_matrix.as_array();
let res = if run_in_parallel && num_layout_trials > 1 {
let res = if run_in_parallel && starting_layouts.len() > 1 {
seed_vec
.into_par_iter()
.enumerate()
Expand All @@ -65,6 +71,7 @@ pub fn sabre_layout_and_routing(
max_iterations,
num_swap_trials,
run_in_parallel,
&starting_layouts[index],
),
)
})
Expand All @@ -79,7 +86,8 @@ pub fn sabre_layout_and_routing(
} else {
seed_vec
.into_iter()
.map(|seed_trial| {
.enumerate()
.map(|(index, seed_trial)| {
layout_trial(
dag,
neighbor_table,
Expand All @@ -89,6 +97,7 @@ pub fn sabre_layout_and_routing(
max_iterations,
num_swap_trials,
run_in_parallel,
&starting_layouts[index],
)
})
.min_by_key(|(_, _, result)| result.map.map.values().map(|x| x.len()).sum::<usize>())
Expand All @@ -114,15 +123,38 @@ fn layout_trial(
max_iterations: usize,
num_swap_trials: usize,
run_swap_in_parallel: bool,
starting_layout: &[Option<u32>],
) -> (NLayout, Vec<PhysicalQubit>, SabreResult) {
let num_physical_qubits: u32 = distance_matrix.shape()[0].try_into().unwrap();
let mut rng = Pcg64Mcg::seed_from_u64(seed);

// Pick a random initial layout including a full ancilla allocation.
let mut initial_layout = {
let mut physical_qubits: Vec<PhysicalQubit> =
(0..num_physical_qubits).map(PhysicalQubit::new).collect();
physical_qubits.shuffle(&mut rng);
let physical_qubits: Vec<PhysicalQubit> = if !starting_layout.is_empty() {
let used_bits: HashSet<u32> = starting_layout
.iter()
.filter_map(|x| x.as_ref())
.copied()
.collect();
let mut free_bits: Vec<u32> = (0..num_physical_qubits)
.filter(|x| !used_bits.contains(x))
.collect();
free_bits.shuffle(&mut rng);
(0..num_physical_qubits)
.map(|x| {
let bit_index = match starting_layout.get(x as usize) {
Some(phys) => phys.unwrap_or_else(|| free_bits.pop().unwrap()),
None => free_bits.pop().unwrap(),
};
PhysicalQubit::new(bit_index)
})
.collect()
} else {
let mut physical_qubits: Vec<PhysicalQubit> =
(0..num_physical_qubits).map(PhysicalQubit::new).collect();
physical_qubits.shuffle(&mut rng);
physical_qubits
};
NLayout::from_virtual_to_physical(physical_qubits).unwrap()
};

Expand Down
Loading

0 comments on commit 8688a82

Please sign in to comment.