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

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

Merged
merged 4 commits into from
Aug 26, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Aug 26, 2024

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

  • SmallVec cannot be used as we cannot predict the maximum length
  • arrays (&[Qubit]) turned out to be a bit restrictive as the length must be known at compile-time (but maybe there's some trick to use this in the signature but pass vectors or something?)

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](https://mergify.com).

* ``CircuitData::from_packed_operations``

* missing import

* remove redundant `to_vec`

(cherry picked from commit b1e7ffe)
@qiskit-bot
Copy link
Collaborator

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:

  • @Qiskit/terra-core
  • @kevinhartman
  • @mtreinish

@github-actions github-actions bot added Changelog: None Do not include in changelog Rust This PR or issue is related to Rust code in the repository mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels Aug 26, 2024
@github-actions github-actions bot added this to the 1.3 beta milestone Aug 26, 2024
@ElePT ElePT changed the title Allow CircuitData construction from PackedOperations (backport #12943) Allow CircuitData construction from PackedOperations and with_capacity(backport #12943 + part of #12809) Aug 26, 2024
@coveralls
Copy link

coveralls commented Aug 26, 2024

Pull Request Test Coverage Report for Build 10561424816

Details

  • 0 of 73 (0.0%) changed or added relevant lines in 1 file are covered.
  • 27 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.1%) to 89.72%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/circuit/src/circuit_data.rs 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%
Totals Coverage Status
Change from base Build 10526731985: -0.1%
Covered Lines: 66804
Relevant Lines: 74458

💛 - Coveralls

@mtreinish mtreinish modified the milestones: 1.3 beta, 1.2.1 Aug 26, 2024
@ElePT ElePT added this pull request to the merge queue Aug 26, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 26, 2024
@mtreinish mtreinish added this pull request to the merge queue Aug 26, 2024
Merged via the queue into stable/1.2 with commit c30740b Aug 26, 2024
17 checks passed
@mergify mergify bot deleted the mergify/bp/stable/1.2/pr-12943 branch August 26, 2024 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants