Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.11k stars 2.34k forks source link

Allow `CircuitData` construction from `PackedOperation`s and `with_capacity`(backport #12943 + part of #12809) #13038

Closed mergify[bot] closed 1 month ago

mergify[bot] commented 1 month ago

Summary

As the title says πŸ™‚ This allows to construct more general circuits than using just CircuitData::from_standard_gates, including e.g. barriers.

Details and comments

This is essentially a copy of CircuitData::from_standard_gates. Qubits and Clbits are now Vec, because

I didn't yet add a test since it's essentially a copy of the standard gates constructor, and this will be used a bunch by the circuit library refactor. But we could add some cfg test that maybe checks this gives the same circuit data as using the standard gates construct -- though not sure how difficult that comparison is πŸ™‚

Example usage:

let n = 50;  // number of qubits
let h_layer = (0..n).map(|i| (
    StandardGate::HGate.into(),  // PackedOperation
    smallvec![],  //  params
    vec![Qubit(i)],  // qubit
    vec![], // clbit
);
let barrier = (  // barrier on all qubits
    PyInstruction { /* define barrier by calling Python ... */ },
    smallvec![],
    (0..n).map(|i| Qubit(i)).collect(),  // all qubits
    vec![], 
);

let data = CircuitData::from_packed_operations(h_layer.chain(barrier));


This is an automatic backport of pull request #12943 done by Mergify.

qiskit-bot commented 1 month ago

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

coveralls commented 1 month ago

Pull Request Test Coverage Report for Build 10561424816

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/circuit/src/circuit_data.rs 0 73 0.0%
<!-- Total: 0 73 0.0% -->
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.02%
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 2 88.39%
crates/qasm2/src/lex.rs 6 91.73%
crates/qasm2/src/parse.rs 18 96.69%
<!-- Total: 27 -->
Totals Coverage Status
Change from base Build 10526731985: -0.1%
Covered Lines: 66804
Relevant Lines: 74458

πŸ’› - Coveralls