Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/gate-operations
Browse files Browse the repository at this point in the history
  • Loading branch information
nulinspiratie committed Nov 27, 2024
2 parents 711cdd9 + f269b0f commit 80fd559
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/quam_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.11]
python-version: [3.9, 3.11, 3.12]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.9"
cache: "pip"

- name: Install python deps
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## [Unreleased]
### Added
- Added time tagging to channels
- Added support for Python 3.12

### Removed
- Removed support for Python 3.8
- Added `Pulse.play()` method

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Explore detailed documentation and get started with QuAM here: [QuAM Documentati
- **State Management**: Features robust tools for saving and loading your quantum states, promoting reproducibility and consistency.

## Installation
To install QuAM, first ensure you have 3.8 ≤ Python ≤ 3.11 installed on your system.
To install QuAM, first ensure you have 3.9 ≤ Python ≤ 3.12 installed on your system.
Then run the following command:

```bash
Expand Down
4 changes: 2 additions & 2 deletions docs/components/custom-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ name = "my-quam"
version = "0.1.0"
description = "User QuAM repository"
authors = [{ name = "Jane Doe", email = "[email protected]" }]
requires-python = ">=3.8"
requires-python = ">=3.9"

[build-system]
requires = ["setuptools", "setuptools-scm"]
Expand Down Expand Up @@ -102,7 +102,7 @@ child = Child(required_attr=12) # Note that we now need to explicitly pass keyw
```

The keyword `kw_only` was only introduced in Python 3.10, and so the example above would raise an error in Python <3.10.
However, to ensure QuAM is compatible with Python 3.8 and above, we introduced `@quam_dataclass` which fixes this problem:
However, to ensure QuAM is compatible with Python 3.9 and above, we introduced `@quam_dataclass` which fixes this problem:

```python
@quam_dataclass
Expand Down
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

/// tab | For Windows
- Windows 10 (build 1809 and later), or Windows 11
- 3.8 ≤ Python ≤ 3.11, we recommend Python 3.10 or 3.11
<!-- For Python 3.8 and 3.9, please see additional notes (TODO add note reference) -->
- 3.9 ≤ Python ≤ 3.12, we recommend Python 3.10 or 3.11
<!-- For Python 3.9, please see additional notes (TODO add note reference) -->
- [Git version control system](https://git-scm.com/), or a Git GUI such as [GitHub Desktop](https://desktop.github.com/) or [GitKraken](https://www.gitkraken.com/)

/// details | Using a virtual environment
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = [
{ name = "Serwan Asaad", email = "[email protected]" },
]
license = { text = "BSD-3-Clause" }
requires-python = ">=3.8"
requires-python = ">=3.9"
readme = "README.md"

classifiers = [
Expand Down Expand Up @@ -40,7 +40,7 @@ dependencies = [
]

[project.urls]
Homepage = "https://github.com/entropy-lab/quam"
Homepage = "https://github.com/qua-platform/quam"

[project.optional-dependencies]
dev = [
Expand All @@ -56,7 +56,7 @@ docs = ["mkdocstrings[python]>=0.18", "mkdocs-gen-files", "mkdocs-jupyter"]
build = ["setuptools >= 71", "setuptools-scm >= 8.1.0", "build >= 1.2.1"]

[tool.black]
target-version = ["py38"]
target-version = ["py39"]
line-length = 88
preview = true

Expand Down
83 changes: 83 additions & 0 deletions quam/components/pulses.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
from quam.core import QuamComponent, quam_dataclass
from quam.utils import string_reference as str_ref

from qm.qua._dsl import (
AmpValuesType,
QuaExpressionType,
ChirpType,
StreamType,
QuaNumberType,
)

__all__ = [
"Pulse",
Expand Down Expand Up @@ -159,6 +166,82 @@ def waveform_function(
"""
...

def play(
self,
amplitude_scale: Union[float, AmpValuesType] = None,
duration: QuaNumberType = None,
condition: QuaExpressionType = None,
chirp: ChirpType = None,
truncate: QuaNumberType = None,
timestamp_stream: StreamType = None,
continue_chirp: bool = False,
target: str = "",
validate: bool = True,
) -> None:
"""Play the pulse on the channel.
The corresponding channel to play the pulse on is determined from the
parent of the pulse.
Args:
pulse_name (str): The name of the pulse to play. Should be registered in
`self.operations`.
amplitude_scale (float, _PulseAmp): Amplitude scale of the pulse.
Can be either a float, or qua.amp(float).
duration (int): Duration of the pulse in units of the clock cycle (4ns).
If not provided, the default pulse duration will be used. It is possible
to dynamically change the duration of both constant and arbitrary
pulses. Arbitrary pulses can only be stretched, not compressed.
chirp (Union[(list[int], str), (int, str)]): Allows to perform
piecewise linear sweep of the element's intermediate
frequency in time. Input should be a tuple, with the 1st
element being a list of rates and the second should be a
string with the units. The units can be either: 'Hz/nsec',
'mHz/nsec', 'uHz/nsec', 'pHz/nsec' or 'GHz/sec', 'MHz/sec',
'KHz/sec', 'Hz/sec', 'mHz/sec'.
truncate (Union[int, QUA variable of type int]): Allows playing
only part of the pulse, truncating the end. If provided,
will play only up to the given time in units of the clock
cycle (4ns).
condition (A logical expression to evaluate.): Will play analog
pulse only if the condition's value is true. Any digital
pulses associated with the operation will always play.
timestamp_stream (Union[str, _ResultSource]): (Supported from
QOP 2.2) Adding a `timestamp_stream` argument will save the
time at which the operation occurred to a stream. If the
`timestamp_stream` is a string ``label``, then the timestamp
handle can be retrieved with
`qm._results.JobResults.get` with the same ``label``.
validate (bool): If True (default), validate that the pulse is registered
in Channel.operations
Raises:
ValueError: If the pulse is not attached to a channel.
KeyError: If the pulse is not registered in the channel's operations.
"""
if self.id is not None:
name = self.id
elif self.parent is not None:
name = self.parent.get_attr_name(self)
else:
raise ValueError(f"Cannot determine name of pulse '{self}'")

if self.channel is None:
raise ValueError(f"Pulse '{name}' is not attached to a channel")

self.channel.play(
pulse_name=name,
amplitude_scale=amplitude_scale,
duration=duration,
condition=condition,
chirp=chirp,
truncate=truncate,
timestamp_stream=timestamp_stream,
continue_chirp=continue_chirp,
target=target,
validate=validate,
)

def _config_add_pulse(self, config: Dict[str, Any]):
"""Add the pulse to the config
Expand Down
2 changes: 1 addition & 1 deletion quam/core/quam_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def sort_quam_components(
def _quam_dataclass(cls=None, **kwargs):
"""Dataclass for QuAM classes.
This class is used as a patch to maintain compatibility with Python 3.8 and 3.9, as
This class is used as a patch to maintain compatibility with Python 3.9, as
these do not support the dataclass argument `kw_only`. This argument is needed to
ensure inheritance of parent dataclasses is allowed.
Expand Down
26 changes: 26 additions & 0 deletions tests/components/pulses/test_pulses.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,29 @@ def test_deprecated_drag_pulse():
pulses.DragPulse(
axis_angle=0, amplitude=1, sigma=4, alpha=2, anharmonicity=200e6, length=20
)


def test_pulse_play(mocker):
channel = SingleChannel(id="single", opx_output=("con1", 1))
pulse = pulses.SquarePulse(length=60, amplitude=0)
channel.operations["pulse"] = pulse

mock_play = mocker.patch("quam.components.channels.play")
channel.play("pulse", duration=100)
mock_play.assert_called_once_with(
pulse="pulse",
element="single",
duration=100,
condition=None,
chirp=None,
truncate=None,
timestamp_stream=None,
continue_chirp=False,
target="",
)


def test_pulse_play_no_channel(mocker):
pulse = pulses.SquarePulse(length=60, amplitude=0)
with pytest.raises(ValueError):
pulse.play()

0 comments on commit 80fd559

Please sign in to comment.