> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.conductorquantum.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.conductorquantum.com/_mcp/server.

# stanza.logger.session



## Module Contents

### Classes

| Name | Description |
|------|-------------|
| [`SweepContext`](#stanzaloggersessionsweepcontext) | Context manager for streaming sweep data with live plotting. |
| [`LoggerSession`](#stanzaloggersessionloggersession) | Session for the logger. |

### Data

`logger`

### API

```python
stanza.logger.session.logger
```

**Value**: `getLogger(...)`


```python
class stanza.logger.session.SweepContext(session: stanza.logger.session.LoggerSession, name: str, x_label: str | list[str], y_label: str, metadata: dict[str, typing.Any], routine_name: str | None = None)
```

Context manager for streaming sweep data with live plotting.

Accumulates data points via append() calls, streams to live plot writers
immediately, and writes the complete sweep to file writers on context exit.

Supports 1D sweeps (scalar x, scalar y) and 2D sweeps ([x0, x1], y).

Example:
    >>> # 1D sweep
    >>> with session.sweep("signal", "Time", "Amplitude") as s:
    ...     for x, y in data_stream:
    ...         s.append([x], [y])  # Live plot updates

    >>> # 2D sweep
    >>> with session.sweep("heatmap", ["V1", "V2"], "Current") as s:
    ...     for v1, v2 in voltage_pairs:
    ...         s.append([v1, v2], [current])  # Live heatmap updates
    >>> # Sweep written to files here

### Initialization

Initialize sweep context.

**Parameters:**

**Parameters:**

- **session**: Parent LoggerSession
- **name**: Sweep name
- **x_label**: X-axis label (string for 1D, list for 2D)
- **y_label**: Y-axis label
- **metadata**: User metadata dict
- **routine_name**: Optional routine name


```python
append(
    x_data: list[float] | numpy.ndarray, y_data: list[float] | numpy.ndarray
) -> None
```

Append data points and stream to live plots.

1D: append([x], [y]) or append([x1, x2, ...], [y1, y2, ...])
2D: append([x, y], [value])


```python
end() -> None
```

Write accumulated sweep to file writers.


```python
cancel() -> None
```

Cancel without persisting. Live updates remain visible.


```python
__enter__() -> stanza.logger.session.SweepContext
```

Enter context manager.


```python
__exit__(
    exc_type: type[BaseException] | None,
    exc_value: BaseException | None,
    traceback: typing.Any
) -> None
```

Exit context manager: end() on success, cancel() on exception.


```python
class stanza.logger.session.LoggerSession(metadata: stanza.logger.datatypes.SessionMetadata, writer_pool: dict[str, stanza.logger.writers.base.AbstractDataWriter], writer_refs: list[str], base_dir: str | pathlib.Path, buffer_size: int = 1000, auto_flush_interval: float | None = 30.0)
```

Session for the logger.

```python
session_id: str
```


```python
_check_buffer_size_warning() -> None
```

Check if buffer has grown too large and log warning once.


```python
initialize() -> None
```

Initialize the session.

**Raises:**

LoggerSessionError: If session is already initialized


```python
finalize() -> None
```

Finalize the session.


```python
close() -> None
```

Close the session (alias for finalize()).


```python
log_measurement(
    name: str,
    data: dict[str, typing.Any],
    metadata: dict[str, typing.Any] | None = None,
    routine_name: str | None = None
) -> None
```

Log measurement data to a session.


```python
log_analysis(
    name: str,
    data: dict[str, typing.Any],
    metadata: dict[str, typing.Any] | None = None,
    routine_name: str | None = None
) -> None
```

Log analysis data to a session.


```python
log_sweep(
    name: str,
    x_data: list[float] | list[list[float]] | numpy.ndarray,
    y_data: list[float] | numpy.ndarray,
    x_label: str,
    y_label: str,
    metadata: dict[str, typing.Any] | None = None
) -> None
```

Log sweep data to a session.


```python
log_parameters(parameters: dict[str, typing.Any]) -> None
```

Log parameters to a session.


```python
sweep(
    name: str,
    x_label: str | list[str],
    y_label: str,
    metadata: dict[str, typing.Any] | None = None
) -> stanza.logger.session.SweepContext
```

Create streaming sweep context for live plotting.

Accumulates data via append(), writes complete sweep to files on exit.
Supports 1D and 2D data. Exception in context = no file write.
One active sweep per name; HDF5 auto-uniquifies sequential same-name sweeps.

Example:
    # 1D sweep
    with session.sweep("signal", "Time (s)", "Amplitude") as s:
        for x, y in data_stream:
            s.append([x], [y])

    # 2D sweep
    with session.sweep("heatmap", ["V1 (V)", "V2 (V)"], "Current (A)") as s:
        for v1, v2 in voltage_pairs:
            s.append([v1, v2], [current])


```python
_should_flush() -> bool
```

Check if buffer should be flushed.


```python
_stream_live_sweep_chunk(
    name: str,
    x: numpy.ndarray,
    y: numpy.ndarray,
    x_label: str | list[str],
    y_label: str,
    dim: int
) -> None
```

Stream data chunk to live plot writers only.


```python
_write_completed_sweep(sweep_data: stanza.logger.datatypes.SweepData) -> None
```

Write complete sweep to file writers only (skip live/bokeh).


```python
flush() -> None
```

Flush buffered data to all writers.

**Raises:**

LoggerSessionError: If any writer fails to write or flush data


```python
__enter__() -> stanza.logger.session.LoggerSession
```

Enter the session context.


```python
__exit__(
    exc_type: type[BaseException] | None,
    exc_value: BaseException | None,
    traceback: typing.Any
) -> None
```

Exit the session context.


```python
__repr__() -> str
```