Skip to content

Commit

Permalink
Oxidize QuantumCircuit._data and intern CircuitInstruction args (#…
Browse files Browse the repository at this point in the history
…10827)

* Initial commit.

* Fix bugs with slicing impl.

* Fix sort, remove dead code.

* Use custom cfg flag for debug.

* Run fmt.

* Add todo.

* Revert utils change, not needed anymore.

* Use CircuitData in compose.

* Revert test stub.

* Remove once_cell. Not needed anymore.

* Run format.

* Fix lint issues.

* Use PyTuple in ElementType.

* Use native list and dict types for lookup tables.

* Implement __traverse__ and __clear__.

* Take iterable for extend. Preallocate.

* Fix insertion indexing behavior.

* Fix typo.

* Avoid possible hash collisions in InternContext.

* Use () instead of None for default iterable.

* Resolve copy share intern context TODO.

* Use () instead of empty list in stubed lists.

* Use u32 for IndexType.

* Resolve TODO in if_else.py.

* Fix Rust lint issues.

* Add unit testing for InternContext.

* Remove print logging.

* Fix bug introduced during print removal.

* Add helper methods for getting the context in CircuitData.

* Fix issue with BlueprintCircuit.

* Workaround for CircuitInstruction operation mutability.

Fix lint.

* Revert "Workaround for CircuitInstruction operation mutability."

This reverts commit 21f3e51.

* Add _add_ref to InstructionSet.

Allows in-place update of CircuitInstruction.operation
within a CircuitData.

* Exclude CircuitData::intern_context from GC clear.

* Fix lint.

* Avoid copy into list.

* Override __deepcopy__.

* Override __copy__ to avoid pulling CircuitData into a list.

* Implement copy for CircuitData.

* Port CircuitInstruction to Rust.

* Use Rust CircuitInstruction.

* Optimize circuit_to_instruction.py

* Use freelist for CircuitInstruction class.

* Remove use count, fix extend, InternContext internal.

Previously CircuitData::extend would construct CircuitInstruction instances
in memory for the entire iterable. Now, a GILPool is created for
each iteration of the loop to ensure each instance is dropped
before the next one is created. At most 3 CircuitInstruction
instances are now created during the construction and transpilation
of a QuantumVolume circuit in my testing.

Use count tracking is now removed from InternContext.

InternContext is now no longer exposed through the Python API.

* Revert to using old extraction for now until we move bits inside CircuitData.

* Fix issue with deletion.

* Performance optimization overhaul.

- Switched to native types for qubits, clbits, qubit_indices,
clbit_indices.
- Tweaks to ensure that only 1-3 CircuitInstruction instances
  are ever alive at the same time (e.g. in CircuitData.extend).
- Use py_ext helpers to avoid unnecessary deallocations in PyO3.
- Move pickling for CircuitData from QC to CircuitData itself.
- Add CircuitData.reserve to preallocate space during copy
  scenarios.

* Fix lint.

* Attempt to move docstring for CircuitInstruction.

* Add missing py_ext module file.

* Use full struct for InternedInstruction.

* Remove __copy__ from QuantumCircuit.

* Improve bit key wrapper name.

* Remove opt TODO comment. Will be done in new PR.

* Clean up GC cycle breaking.

* Add separate method convert_py_index_clamped.

* Implement __eq__ instead of __richcmp__.

* Avoid 'use'ing SliceOrInt enum.

* Port slice conversion to pure Rust.

* Clean up InternContext.

* Change import order in quantumcircuitdata.py.

* Use .zip method on iter().

* Rename get_or_cache to intern_instruction.

* Improve error handling.

* Add documentation comments for Rust types.

* Move reserve method.

* Add tests for bit key error.

* Localize BlueprintCircuit workaround.

* Slice refactoring, fixes, tests.

* Fix setitem slice regression, clean up slice testing.

* Use Python docstring form for pymethods.

* Don't use underscore in BitAsKey type name.

* Add release note.

* Add upgrade note.

* Add error messages for exceeded qubits and clbits.

* Use BitType instead of u32.

* Improve code comments for extend.

* Improve readability with PackedInstruction.

InternedInstruction is renamed to PackedInstruction to
make it clearer that the code deals in terms of some
form of a packed instruction, and that interning of
the instruction's qubits and clbits is just an
implementation detail of that.

* Fix reserve issue.

* Use usize for pointer type.

* Use copied instead of cloned on Option.

* Use .is() instead of IDs.

* Convert tuples to list in legacy format.

* Remove redundant parens.

* Add crate comment for py_ext.

* Make CircuitData::qubits and CircuitData::clbits ephemeral.
  • Loading branch information
kevinhartman committed Nov 20, 2023
1 parent 45efe66 commit f3857f1
Show file tree
Hide file tree
Showing 17 changed files with 1,387 additions and 198 deletions.
2 changes: 2 additions & 0 deletions crates/accelerate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod euler_one_qubit_decomposer;
mod nlayout;
mod optimize_1q_gates;
mod pauli_exp_val;
mod quantum_circuit;
mod results;
mod sabre_layout;
mod sabre_swap;
Expand Down Expand Up @@ -52,6 +53,7 @@ fn _accelerate(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pymodule!(sabre_swap::sabre_swap))?;
m.add_wrapped(wrap_pymodule!(pauli_exp_val::pauli_expval))?;
m.add_wrapped(wrap_pymodule!(dense_layout::dense_layout))?;
m.add_wrapped(wrap_pymodule!(quantum_circuit::quantum_circuit))?;
m.add_wrapped(wrap_pymodule!(error_map::error_map))?;
m.add_wrapped(wrap_pymodule!(sparse_pauli_op::sparse_pauli_op))?;
m.add_wrapped(wrap_pymodule!(results::results))?;
Expand Down

0 comments on commit f3857f1

Please sign in to comment.