Skip to content

Feat adjust measure#198

Open
MathieuG-Colibri wants to merge 17 commits into
devfrom
feat-adjust-measure
Open

Feat adjust measure#198
MathieuG-Colibri wants to merge 17 commits into
devfrom
feat-adjust-measure

Conversation

@MathieuG-Colibri
Copy link
Copy Markdown
Collaborator

@MathieuG-Colibri MathieuG-Colibri commented May 17, 2026

Updated the way to treat expectation measures.

If the measure doesn't cover the whole registry we pad the pauli string with Identities, or is not ordered (instead of swap gates reorganize the matrix or pauli string).

Isn't necessary for braket with optimize_measure set at true (does the pauli grouping).

@MathieuG-Colibri MathieuG-Colibri self-assigned this May 17, 2026
@github-actions github-actions Bot added the enhancement New feature or request label May 17, 2026
@MathieuG-Colibri MathieuG-Colibri changed the base branch from main to dev May 18, 2026 13:17
Comment thread mpqp/execution/providers/ibm.py Outdated
Comment thread mpqp/execution/runner.py Outdated
Comment thread mpqp/tools/circuit.py Outdated
Comment thread mpqp/tools/maths.py Outdated
Comment on lines 480 to 485
@@ -484,47 +481,8 @@ def _check_targets_order(self):
"""Ensures target qubits are ordered and contiguous, rearranging them if
necessary (private)."""

if len(self.targets) == 0:
self._pre_measure: list[Gate] = []
return

if self.nb_qubits != self.observables[0].nb_qubits:
raise NumberQubitsError(
f"Target size {self.nb_qubits} doesn't match observable size "
f"{self.observables[0].nb_qubits}."
)

self.rearranged_targets = list(self.targets)
self._pre_measure: list[Gate] = []
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this function still needed ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 59fd820
Removed rearranged_targets, it was only used by the old swap path. Also removed pre_measure since Measure.pre_measure already returns [ ]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you didn't mixed things up, I was talking about the function @MathieuG-Colibri removed in 4dfbb16

Comment thread mpqp/execution/providers/aws.py Outdated
]
for circuit in pre_measure:
for instr in circuit.instructions:
instr.targets[0] = job.measure.targets[instr.targets[0]]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you changing just the first target ? the logic looks a bit dodgy here

Copy link
Copy Markdown
Collaborator

@MoHermes MoHermes May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, instr.targets[0] was originally used because find_qubitwise_rotations(...) return single qubit instructions., so each generated instruction has one target. But yeah, this assumption is not obvious, so I agree it looks fragile

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 9ddb86b

Comment thread mpqp/core/instruction/measurement/expectation_value.py Outdated
Comment thread tests/core/instruction/gates/test_custom_gate.py Outdated
Comment thread mpqp/execution/providers/aws.py Outdated
]
for circuit in pre_measure:
for instr in circuit.instructions:
instr.targets[0] = job.measure.targets[instr.targets[0]]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why targets[0] ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 9ddb86b

Comment thread mpqp/tools/maths.py Outdated
Comment thread mpqp/tools/maths.py Outdated
Comment thread mpqp/tools/circuit.py
)

for i in range(nb_qubits):
qcircuit.add(rng.choice(gates)(i))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we have a function for that ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants