Closed kevinhartman closed 2 months ago
One or more of the following people are relevant to this code:
@Qiskit/terra-core
@kevinhartman
@mtreinish
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
crates/circuit/src/packed_instruction.rs | 2 | 3 | 66.67% | ||
crates/circuit/src/dag_node.rs | 5 | 7 | 71.43% | ||
crates/circuit/src/circuit_instruction.rs | 54 | 108 | 50.0% | ||
<!-- | Total: | 107 | 164 | 65.24% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
crates/circuit/src/dag_circuit.rs | 1 | 88.54% | ||
crates/qasm2/src/expr.rs | 1 | 94.02% | ||
qiskit/transpiler/passes/synthesis/unitary_synthesis.py | 2 | 88.26% | ||
crates/qasm2/src/lex.rs | 4 | 92.23% | ||
crates/qasm2/src/parse.rs | 6 | 97.61% | ||
qiskit/synthesis/two_qubit/xx_decompose/decomposer.py | 7 | 90.91% | ||
<!-- | Total: | 21 | --> |
Totals | |
---|---|
Change from base Build 10834414649: | -0.02% |
Covered Lines: | 73365 |
Relevant Lines: | 82535 |
Summary
The primary motivation here is to encapsulate the hairy logic of managing memory for extra attributes. By moving the
Option<Box<_>>
into theExtraInstructionAttributes
struct itself, clients are no longer burdened with the responsibility of checking if theOption
contains a value, unwrapping it etc.; the semantics of that aren't relevant to clients likeDAGCircuit
andCircuitData
. Instead, theExtraInstructionAttributes
acts as a container for optional attributes, and can easily drop theBox
internally if all attributes are cleared.A give-away that this pattern could be helpful was
ExtraInstructionAttributes::new
's return type, which was previouslyOption<Self>
.Details and comments
The size of
ExtraInstructionAttributes
(now held by value by instructions) should be the same size as the oldOption<Box<ExtraInstructionAttributes>>
, so this should not have memory implications regarding the size of instructions.Note that
ExtraAttrs
is completely private to thecircuit_instruction
module, i.e. it's only an implementation detail and in no way part of the interface.