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

Add Ion dialect and pass for quantum to Ion lowering #1260

Merged
merged 86 commits into from
Dec 18, 2024
Merged

Conversation

rmoyard
Copy link
Contributor

@rmoyard rmoyard commented Oct 31, 2024

Context:

Add MLIR support for pulse level ionic programs for OQD.

Description of the Change:

This PR adds:

  1. The ion dialect
  2. The lowering from quantum to ion dialect. At a high level, we add the decomposition from the gateset {RX, RY, MS} to physical pulses
  3. Mechanism to read in physical parameters from toml to mlir. In this step we use toml++

[sc-73704, sc-73705]

@rmoyard
Copy link
Contributor Author

rmoyard commented Nov 5, 2024

[sc-73704]

mlxd
mlxd previously requested changes Nov 8, 2024
Copy link
Member

@mlxd mlxd left a comment

Choose a reason for hiding this comment

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

Just some simple housekeeping.

mlir/include/Ion/IR/IonInterfaces.h Outdated Show resolved Hide resolved
mlir/include/Ion/IR/IonInterfaces.td Outdated Show resolved Hide resolved
mlir/include/Ion/IR/IonOps.h Outdated Show resolved Hide resolved
mlir/include/Ion/IR/IonOps.td Outdated Show resolved Hide resolved
mlir/lib/Ion/IR/IonOps.cpp Outdated Show resolved Hide resolved
mlir/include/Ion/IR/IonOps.h Outdated Show resolved Hide resolved
mlir/test/Ion/PulseOp.mlir Outdated Show resolved Hide resolved
mlir/test/Ion/PulseOp.mlir Outdated Show resolved Hide resolved
mlir/test/Ion/PulseOp.mlir Outdated Show resolved Hide resolved
mlir/test/Ion/PulseOp.mlir Outdated Show resolved Hide resolved
mlir/test/Ion/PulseOp.mlir Outdated Show resolved Hide resolved
### Before submitting

Please complete the following checklist when submitting a PR:

- [ ] All new functions and code must be clearly commented and
documented.

- [ ] Ensure that code is properly formatted by running `make format`.
The latest version of black and `clang-format-14` are used in CI/CD to
check formatting.

- [ ] All new features must include a unit test.
Integration and frontend tests should be added to
[`frontend/test`](../frontend/test/),
Quantum dialect and MLIR tests should be added to
[`mlir/test`](../mlir/test/), and
Runtime tests should be added to [`runtime/tests`](../runtime/tests/).

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


------------------------------------------------------------------------------------------------------------

**Context:**

**Description of the Change:**

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
@rmoyard rmoyard changed the title [Draft] Ion dialect [Draft] Ion dialect and quantum to Ion lowering Nov 29, 2024
joeycarter added a commit that referenced this pull request Dec 6, 2024
)

**Context:**

PR #1260 will introduce an MLIR dialect (the _Ion Dialect_) for Open
Quantum Design (OQD) trapped-ion quantum devices and the means to lower
quantum-dialect MLIR to the ion dialect. The ion dialect requires data
specific to the target device in order to perform the lowering. For
example, the compiler requires data for the ions used in the device,
such as their species and energy levels, parameters determined from
calibration runs, such as laser pulse frequencies and Rabi frequencies,
and other parameters pertaining to the experimental apparatus. This PR
creates these databases and the APIs to load and interact with them.

**Description of the Change:**

Three database objects have been created, contained in the module
frontend/catalyst/third_party/oqd/oqd_database_managers.py:

1. `OQDDeviceDatabase`: for storing properties about the OQD device,
such as hardware specification and parameters relating to the
experimental apparatus.
2. `OQDQubitDatabase`: for storing properties about the physical qubits
used in the trapped-ion device. These are generally physical constants
of the ion species being used, such as their energy levels and
transitions, and phonon parameters.
3. `OQDBeamDatabase`: for storing parameters about the laser beams used
to interact with the qubits, such as the Rabi frequency, detuning, phase
and polarization parameters for the given energy-level transition.

These databases have been implemented using TOML configuration files for
the time being for simplicity and ease-of-use. In the future, some of
these parameters may be stored in a SQL database, particularly those
determined in calibration runs (these parameters will thus be updated
regularly). For the moment, we assume that there is the ability to
extract the relevant parameters from the database and dump them into
TOML format immediately before compilation. The database APIs listed
above have been separated into three objects for this reason—to separate
out parameters that are device constants (`OQDDeviceDatabase`), physical
constants (`OQDQubitDatabase`), and parameters that require calibration
and updating (`OQDBeamDatabase`).

The implementation details of the OQD trapped-ion device are still being
finalized, so the list of parameters and how they are organized is
subject to change. This PR creates a template database on which we can
build and start using to test drive the ion dialect.

These changes are largely self-contained and should not interfere with
regular Catalyst usage.

-----

This PR also introduces the `toml_utils` module to extend the
functionality of the TOML database files. It adds the `safe_eval`
function, which allows inputting values as arithmetic expressions. For
example, instead of writing

```toml
x = 6283185307.179586  # 2 * pi * 1e9
```

we can instead input this value directly as:

```toml
x = "2 * math.pi * 1e9"
```

The main advantage of this approach is that it uses self-documenting
values: it is clear what the origin of the value is without having to
keep the comment in sync with the value itself.

We define `safe_eval` to perform the expression evaluation rather than
use Python's built-in `eval()` function, since `eval`'s ability to
perform arbitrary code execution of a user's input makes it inherently
unsafe. The functionality of `safe_eval` is deliberately limited to
basic mathematical operations to prevent malicious code, intentional or
not, from being evaluated.

-----


[[sc-73706](https://app.shortcut.com/xanaduai/story/73706/create-a-list-of-hardware-info-calibration-data-necessary-for-the-compiler-0-5)],
[[sc-73707](https://app.shortcut.com/xanaduai/story/73707/add-hardware-info-to-the-toml-json-specs-1-5)]

---------

Co-authored-by: paul0403 <[email protected]>
paul0403 and others added 2 commits December 17, 2024 17:01
The sign of the phonon energy in the expression already agrees with the
formula in the spec, so not sure what this TODO item is about.
@joeycarter joeycarter changed the title [Draft] Ion dialect and quantum to Ion lowering Add Ion dialect and pass for quantum to Ion lowering Dec 18, 2024
@paul0403 paul0403 merged commit c88192a into main Dec 18, 2024
41 checks passed
@paul0403 paul0403 deleted the ion_dialect branch December 18, 2024 20:11
paul0403 added a commit that referenced this pull request Dec 18, 2024
**Context:**
A big redesign of oqd ion dialect and the associated toml file format
took place during #1260 . Therefore, the frontend oqd pytests (which
performs some toml parsing) should be removed, since (a) they are
interpreting against the old toml format, and (b) the toml parsing now
happens in the mlir layer alongside the actual `--quantum-to-ion` pass,
not at the frontend python layer as a standalone.
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.

4 participants