-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add serverless guide with function template example: hamiltonian simu… #2300
Conversation
…lation (#2276) The very rough outline is intact, including the code, but I still need to write/revise some prose between the cells. Right now this example uses the `mergedeep` package to merge the user's estimator options with the function's default. If we need to remove this dependency, then I will modify the program so that if a user passes estimator options, they completely replace the function's default. Closes #2242. --------- Co-authored-by: Jen Glick <[email protected]> Co-authored-by: Rebecca Dimock <[email protected]> Co-authored-by: Rebecca Dimock <[email protected]>
One or more of the following people are relevant to this code: |
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
This will close #2242 when it is merged. |
I opened #2302 since I don't have permission to push to this repository. |
I am not able to push directly to the branch in #2300, so I opened this instead.
I recommend we rename the file something more human-readable, like |
Co-authored-by: abbycross <[email protected]>
@frankharkins, @garrison, @jenglick I'd recommend adding two things:
import traceback
import signal
from qiskit_serverless import save_result
class FunctionTemplate:
def signal_handler(self, signum, frame):
"""Handle termination signals."""
signame = signal.Signals(signum).name
logger.info("Received %s signal, shutting down...", signame)
for job in self._jobs:
try:
job.cancel()
except Exception as exc:
# The cancel will give a RuntimeInvalidStateError if the job has already
# finished, but it's more efficient to always cancel than to check for status first.
if not isinstance(exc, RuntimeInvalidStateError):
logger.error("Unable to cancel Qiskit Runtime job %s", job.job_id())
self._session.close()
class Runner:
def run(self, arguments: dict) -> dict:
try:
func = FunctionTemplate(**arguments)
signal.signal(signal.SIGTERM, func.signal_handler)
return func.run()
except Exception:
save_result(traceback.format_exc())
raise
# job.result()
{
'twoqubit_depth': ...,
'metadata': {
'hamiltonian': ...,
'backend_name': ...,
...
}
} |
This is a great idea.
@pandasa123, It's not entirely clear to me how to integrate this code snippet with the function. How are the two classes to be used? But also: I wonder if it might be better for serverless to expose an abstraction that does this, rather than people needing to copy and paste a snippet of code like this. |
…#2504) I originally wanted to be able to validate that this is the same as the code displayed above. I had planned to do this using a cell with a `%%writefile` directive, like is above in this file. Given this, I could have asserted that the two files are equivalent. Unfortunately I don't think it is possible to use Jupyter directives like this within an HTML block in a notebook.
Follow-up to #2504. --------- Co-authored-by: Eric Arellano <[email protected]>
Continuation of #2276