Add QuantumProgram and related classes - #396
Conversation
QuantumProgram and related classesQuantumProgram and related classes
ihincks
left a comment
There was a problem hiding this comment.
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?
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 |
|
What I was getting at by specializations was specifically this pattern: 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. |
| # 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 |
There was a problem hiding this comment.
On a similar note, I'll remove semantic roles and meas level as well
Co-authored-by: joshuasn <53916441+joshuasn@users.noreply.github.com>
QuantumProgram and related classesQuantumProgram and related classes
ihincks
left a comment
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Do you plan on subclassing this in qiskit-ibm-runtime? Right now it adds the sugar for timing information.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Docstring claims a dictionary. Although, depending on how the previous question goes, we might consider removing this, and the one in the item class.
| metadata: Any = None, | |
| metadata: dict[str, Any] | None = None, |
There was a problem hiding this comment.
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. | |||
There was a problem hiding this comment.
We should probably add some tests for the result class, too.
Summary
This PR:
QuantumProgramand related classes copy-pasted from qiskit-ibm-runtimesamplomatic/quantum_program/__init__.pyCloses #395