Skip to content

Conversation

swernli
Copy link
Collaborator

@swernli swernli commented Nov 20, 2024

This adds some convenience accessors for getting dumps, messages, and matrices as separate entries from an invocation of qsharp.run and qsharp.eval. Previously, the only way to get a state dump from a run was the awkward:

state = qsharp.StateDump(qsharp.run("DumpMachine()", shots=1, save_events=True)[0]["events"][0].state_dump())

This change preserves the existings "events" entry in the saved output, which has everything intermingled in the order from each shot, but also introduces dumps, messages, and matrices that will keep just the ordered output of that type. This makes the above pattern slightly better (and more discoverable):

state = qsharp.run("DumpMachine()", shots=1, save_events=True)[0]["dumps"][0]

This adds similar functionality to qsharp.eval which now supports save_events=True to capture output, so for single shot execution you can use:

state = qsharp.eval("DumpMachine()", save_events=True)["dumps"][0]

This adds some convenience accessors for getting dumps, messages, and matrices as separate entries from an invocation of `qsharp.run` and `qsharp.eval`. Previously, the only way to get a state dump from a run was the awkward:

```python
state = qsharp.StateDump(qsharp.run("DumpMachine()", shots=1, save_events=True)[0]["events"][0].state_dump())
```

This change preserves the existings "events" entry in the saved output, which has everything intermingled in the order from each shot, but also introduces dumps, messages, and matrices that will keep just the ordered output of that type. This makes the above pattern slightly better (and more discoverable):

```python
state = qsharp.run("DumpMachine()", shots=1, save_events=True)[0]["dumps"][0]
```

This adds similar functionality to `qsharp.eval` which now supports `save_events=True` to capture output, so for single shot execution you can use:

```python
state = qsharp.eval("DumpMachine()", save_events=True)["dumps"][0]
```
@swernli swernli added this pull request to the merge queue Dec 12, 2024
Merged via the queue into main with commit 502ae34 Dec 12, 2024
18 checks passed
@swernli swernli deleted the swernli/python-dumps-access branch December 12, 2024 19:21
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.

3 participants