Skip to content

Add QuantumProgram and related classes - #396

Open
SamFerracin wants to merge 24 commits into
mainfrom
programs
Open

Add QuantumProgram and related classes#396
SamFerracin wants to merge 24 commits into
mainfrom
programs

Conversation

@SamFerracin

Copy link
Copy Markdown
Collaborator

Summary

This PR:

  • Adds a version of QuantumProgram and related classes copy-pasted from qiskit-ibm-runtime
  • Adds all the tests currently present for those classes
  • Improves the description samplomatic/quantum_program/__init__.py
  • Adds the module to the public documentation

Closes #395

@SamFerracin
SamFerracin marked this pull request as draft August 10, 2026 18:46
@SamFerracin SamFerracin changed the title Add QuantumProgram and related classes [WIP] Add QuantumProgram and related classes Aug 10, 2026
Comment thread samplomatic/quantum_program/quantum_program_result.py Outdated

@ihincks ihincks left a comment

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.

Thanks @SamFerracin. The main reason for moving this here is to support an ecosystem of tools that treats the concept of a QuantumProgram in a way that is agnostic to the implementation behind it, whether it be IBM hardware, a simulator, or some other provider. Then other packages can depend on this concept without having to depend on qiskit-ibm-runtime.

However, this PR currently brings over some concepts that I would have guessed were specifically related to IBM Quantum Compute: SchedulerTiming, StretchValues, ChunkTimings. This is related to your comment about the drawer.

So then my question is: do you view these things as fundametally part of the concept of a QuantumProgram which all tools should be able to assume exist, or did you bring them over for the convenience of qiskit-ibm-runtime not having to specialize them?

@SamFerracin

Copy link
Copy Markdown
Collaborator Author

However, this PR currently brings over some concepts that I would have guessed were specifically related to IBM Quantum Compute: SchedulerTiming, StretchValues, ChunkTimings.

That is a fair point. Let me think about the implications of not bringing them over, and I'll update the PR.

I guess the alternative would be to simply bring over QuantumProgramResult(s)--which will be needed for type hinting, for example--with a generic metadata field?

@ihincks

ihincks commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

What I was getting at by specializations was specifically this pattern:

from samplomatic import QuantumProgramResult

class IBMQuantumProgramResult(QuantumProgramResult):
    def scheduler_timings(self) -> SchedulerTimings:
        ....

    ....

Anything that wants to write generically against QuantumProgram/Result can do so, and IBMQuantumProgramResult will work just as well as QuantumProgramResult for them, assuming IBMQuantumProgramResult takes subtype polymorphism seriously and doesn't get tempted by shenanigans. Additionally, any user of IBMQuantumProgramResult gets access to IBM specific goodies. It also gives a mechanism for simulator returns to be different than hardware returns.

Comment on lines +258 to +261
# Semantic role indicating how execution results may be post-processed by runtime clients.
# Reserved system values include 'sampler-v2' and 'estimator-v2', and are subject to change
# without notice. Third party clients should not set or depend on this value.
self._semantic_role: str | None = None

@SamFerracin SamFerracin Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

On a similar note, I'll remove semantic roles and meas level as well

Comment thread samplomatic/quantum_program/quantum_program.py Outdated
Comment thread samplomatic/quantum_program/datatree.py Outdated
Comment thread samplomatic/quantum_program/datatree.py Outdated
@SamFerracin SamFerracin changed the title [WIP] Add QuantumProgram and related classes Add QuantumProgram and related classes Aug 21, 2026
@SamFerracin
SamFerracin marked this pull request as ready for review August 21, 2026 13:12

@ihincks ihincks left a comment

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.

Thanks @SamFerracin.

Could we please import the quantum_program module in the the main samplomatic init file, too? For now, though, I would not pull any objects into the main namespace.

return f"{self.__class__.__name__}({self._result}, metadata={self.metadata})"


class QuantumProgramResult:

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.

Do you plan on subclassing this in qiskit-ibm-runtime? Right now it adds the sugar for timing information.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I plan on subclassing and adding the sugar in runtime, see this diff. Which should match what we discussed, but lmk if I misinterpreted

def __init__(
self,
data: Sequence[dict[str, np.ndarray] | QuantumProgramItemResult],
metadata: Any = None,

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.

Docstring claims a dictionary. Although, depending on how the previous question goes, we might consider removing this, and the one in the item class.

Suggested change
metadata: Any = None,
metadata: dict[str, Any] | None = None,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed: cacf02f

Although, depending on how the previous question goes, we might consider removing this, and the one in the item class.

I see.. Yeah, I am not against that.. Metadata is a concept that's general enough to live in Samplomatic. At the same time, if it's type-hinted as Any, perhaps it doesn't buy anything and it can just leave in the subclass

@@ -0,0 +1,11 @@
# This code is a Qiskit project.

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.

We should probably add some tests for the result class, too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@SamFerracin

Copy link
Copy Markdown
Collaborator Author

@ihincks added to the init: 73a83e0

Comment thread changelog.d/396.added.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add QuantumProgram and related classes

3 participants