Skip to content
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

Make it easier to access dumps and matrices from Python #2042

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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]
```
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.

1 participant