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

Invalid circuit splitting for Badger #507

Closed
lmondada opened this issue Jul 24, 2024 · 4 comments · Fixed by #510
Closed

Invalid circuit splitting for Badger #507

lmondada opened this issue Jul 24, 2024 · 4 comments · Fixed by #510
Assignees
Labels
bug Something isn't working

Comments

@lmondada
Copy link
Contributor

The following code panics with the error "all nodes must have dataflow signature". This test can be run on the bug/invalid-circ-split branch in the file tket2/tests/badger.rs.

use std::num::NonZeroUsize;

use rstest::{fixture, rstest};
use tket2::optimiser::badger::BadgerOptions;
use tket2::optimiser::{BadgerOptimiser, DefaultBadgerOptimiser};
use tket2::serialize::TKETDecode;
use tket2::Circuit;
use tket_json_rs::circuit_json::SerialCircuit;

/// A set of equivalence circuit classes (ECC)
///
/// This is the complete set of ECCs for 2-qubit circuits with up to
/// 4 gates, using the NAM gateset (CX, Rz, H).
#[fixture]
fn nam_4_2() -> DefaultBadgerOptimiser {
    BadgerOptimiser::default_with_eccs_json_file("../test_files/Nam_4_2_complete_ECC_set.json")
        .unwrap()
}

#[fixture]
fn barenco_tof_10() -> Circuit {
    let json = std::fs::read_to_string("../test_files/barenco_tof_10.json").unwrap();
    let ser: SerialCircuit = serde_json::from_str(&json).unwrap();
    ser.decode().unwrap()
}

#[rstest]
fn badger_barenco_tof_10(barenco_tof_10: Circuit, nam_4_2: DefaultBadgerOptimiser) {
    let opt_circ = nam_4_2.optimise(
        &barenco_tof_10,
        BadgerOptions {
            max_circuit_cnt: Some(0), // This will abort the optimisation immediately
            n_threads: NonZeroUsize::new(2).unwrap(),
            split_circuit: true,
            ..Default::default()
        },
    );
    assert_eq!(opt_circ, barenco_tof_10);
}
@lmondada lmondada added the bug Something isn't working label Jul 24, 2024
@aborgna-q aborgna-q self-assigned this Jul 24, 2024
@lmondada
Copy link
Contributor Author

Was introduced by #493

@lmondada
Copy link
Contributor Author

Here's an MWE, using a single Rz rotation. Could it be an issue with handling gates with float inputs? I've pushed this example to the branch bug/invalid-circ-split, with a new test case in the tket2/src/passes/chunks.rs file.

    /// Just a one-qubit circuit with Rz gate
    #[fixture]
    fn rz() -> Circuit {
        let json = r#"{"phase":"0.0","commands":[{"op":{"type":"Rz","n_qb":1,"params":["0.25"],"signature":["Q"]},"args":[["q",[0]]]}],"qubits":[["q",[1]],["q",[0]]],"bits":[],"implicit_permutation":[[["q",[0]],["q",[0]]],[["q",[1]],["q",[1]]]]}"#;
        let ser: SerialCircuit = serde_json::from_str(json).unwrap();
        ser.decode().unwrap()
    }

    #[rstest]
    fn split_rz(rz: Circuit) {
        let chunks = CircuitChunks::split_with_cost(&rz, 1, |_| 0);
        assert_eq!(chunks.len(), 1);
    }

github-merge-queue bot pushed a commit to CQCL/hugr that referenced this issue Jul 25, 2024
…flow nodes (#1350)

The signature computation for a `SiblingSubgraph` takes the union of the
nodes' extensions. This didn't contemplate non-dataflow nodes like
constants, and caused a runtime panic if one was present.

Most of the diff is adding a constant node in the tests. 

This is a fix for CQCL/tket2#507
@aborgna-q
Copy link
Collaborator

This should get fixed with the upcoming hugr 0.10 release. #508

aborgna-q added a commit to CQCL/hugr that referenced this issue Jul 25, 2024
…flow nodes (#1350)

The signature computation for a `SiblingSubgraph` takes the union of the
nodes' extensions. This didn't contemplate non-dataflow nodes like
constants, and caused a runtime panic if one was present.

Most of the diff is adding a constant node in the tests. 

This is a fix for CQCL/tket2#507
github-merge-queue bot pushed a commit that referenced this issue Jul 25, 2024
@aborgna-q
Copy link
Collaborator

This seems to be fixed now, but the original badger_barenco_tof_10 test still fails due to the circuits not matching after the badger run (some rewrites may be applied before the timeout is triggered?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants