Skip to content

feat: Analytics#160

Merged
jake-arkinstall merged 10 commits intomainfrom
feat/analytics
Apr 21, 2026
Merged

feat: Analytics#160
jake-arkinstall merged 10 commits intomainfrom
feat/analytics

Conversation

@jake-arkinstall
Copy link
Copy Markdown
Collaborator

@jake-arkinstall jake-arkinstall commented Apr 16, 2026

Provides a pydantic trace format for recording events going into, and coming out of, a runtime during a run.

This can be extracted from a CircuitExtractor with get_trace(), and then encoded as json. A schema is provided in selene-core's _dist bundle that may be used to validate the json.

The trace can be loaded at a later point via pydantic. This provides a way of analysing the characteristics of a simulated run.

@jake-arkinstall jake-arkinstall marked this pull request as ready for review April 21, 2026 20:28
Copilot AI review requested due to automatic review settings April 21, 2026 20:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces an analytics/trace facility by defining a Pydantic-based selene_core.Trace event model, emitting traces from the simulator instruction log, and packaging a JSON schema into the selene-core distribution for later validation/loading.

Changes:

  • Add selene_core.trace Pydantic models for event traces, including JSON (de)serialization.
  • Extend CircuitExtractor/ShotInstructions to produce a Trace via get_trace() and snapshot it in existing batching tests.
  • Add a Hatch build hook to generate and ship the Trace JSON schema in the _dist bundle; add pydantic dependency.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
uv.lock Locks in pydantic as a dependency.
selene-sim/python/selene_sim/event_hooks/instruction_log.py Builds a Trace from instruction logs (get_trace).
selene-ext/runtimes/soft_rz/python/tests/test_batching.py Adds trace snapshot assertions and updates backend imports.
selene-ext/runtimes/soft_rz/python/tests/snapshots/.../trace_batching_*.json New trace snapshots for batching scenarios.
selene-core/python/selene_core/trace.py New Pydantic trace/event schema and helpers.
selene-core/pyproject.toml Adds pydantic dependency; wires schema generation into build cache keys and build-system requirements.
selene-core/hatch_build.py Generates and writes Trace JSON schema into _dist during build.
justfile Minor whitespace change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +606 to +611
case Rzz(qubit0=qubit0, qubit1=qubit1, theta=theta):
event = GateEvent(
gate_name="Rzz",
qubits=[qubit0, qubit1],
args={"theta": theta},
)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

GateEvent doesn't define an args field (and extra='ignore'), so the theta value passed here will be dropped from the emitted trace. Use params or add an explicit args field to the trace schema/model.

Copilot uses AI. Check for mistakes.
Comment thread selene-core/pyproject.toml Outdated
Comment thread selene-core/hatch_build.py Outdated
Comment thread selene-sim/python/selene_sim/event_hooks/instruction_log.py
Comment on lines +589 to +597
case Rxy(qubit=qubit, theta=theta, phi=phi):
event = GateEvent(
gate_name="Rxy",
qubits=[qubit],
args={
"theta": theta,
"phi": phi,
},
)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

GateEvent doesn't define an args field (and AbstractEvent is configured with extra='ignore'), so the theta/phi values provided here will be silently dropped from the serialized trace. Either add a typed args field to GateEvent (and schema), or encode these values using the existing params field (as done for user-program events).

Copilot uses AI. Check for mistakes.
Comment thread selene-sim/python/selene_sim/event_hooks/instruction_log.py Outdated
jake-arkinstall and others added 5 commits April 21, 2026 21:33
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +469 to +478
match instruction.operation:
case CustomOperation(tag=tag, data=data):
trace.add_user_program_event(
CustomEvent(payload=OpaquePayload(tag=tag, data=data)),
index=user_program_event_index,
)
user_program_event_index += 1
case LocalBarrier(qubits=qubits, sleep_time=sleep_time):
trace.add_user_program_event(
GateEvent(
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

get_trace() has a lot of repeated add_user_program_event(...); user_program_event_index += 1 / add_runtime_event(...) boilerplate across the match cases, which makes the method harder to maintain when new operations are added. Consider introducing a small local helper (e.g., add_user(event) / add_runtime(event)) or factoring the Operation->Event conversion into a separate function/table to centralize the index increment and reduce duplication.

Copilot uses AI. Check for mistakes.
@jake-arkinstall jake-arkinstall merged commit 24b9978 into main Apr 21, 2026
19 of 21 checks passed
@jake-arkinstall jake-arkinstall deleted the feat/analytics branch April 21, 2026 22:55
jake-arkinstall pushed a commit that referenced this pull request Apr 21, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.2.8](selene-core-v0.2.7...selene-core-v0.2.8)
(2026-04-21)


### Features

* add timing to builtin runtimes and batching options to softrz runtime
([#158](#158))
([049e123](049e123))
* Traces for analytics
([#160](#160))
([24b9978](24b9978))


### Bug Fixes

* classify lowered qir-qis bitcode as helios
([#157](#157))
([67fca60](67fca60))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
jake-arkinstall pushed a commit that referenced this pull request Apr 21, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.2.14](selene-sim-v0.2.13...selene-sim-v0.2.14)
(2026-04-21)


### Features

* add timing to builtin runtimes and batching options to softrz runtime
([#158](#158))
([049e123](049e123))
* Record simulated delays in event hooks
([#154](#154))
([608884a](608884a))
* Traces for analytics
([#160](#160))
([24b9978](24b9978))


### Bug Fixes

* classify lowered qir-qis bitcode as helios
([#157](#157))
([67fca60](67fca60))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

2 participants