Skip to content

Add C FFI for transpilation #14245

@mtreinish

Description

@mtreinish

What should we add?

This was originally part of #13276 but decided to split that into 2 epics, one for circuit construction and the other for transpilation. The goal of this issue is to expose transpilation through the Qiskit C API. There are 2 patterns to expose here, the first is a dedicated transpile() function that would have a signature like:

QkCircuit *qk_transpile(QkCircuit *circuit, Target *target, unsigned char optimization_level)

where it's a full path transpilation where internally we run the circuit to dag conversion and then build the equivalent of the python space preset pass managers as a rust function and compile the circuit for the given target. To start we should concentrate on level 2 as that is the default, and only worry about circuits construable from the C API (so that means we don't need to worry about things like HLS to start). This will obviously change over time as we grow what's exposed via the C API, but the intent of this function is not to replace Python space transpilation in a hybrid/c extension workflow but instead it's intended to expose transpilation to the standalone C API.

The second usage pattern to expose is to provide dedicated standalone functions for individual transpiler passes to do an isolated analysis or transformation of a circuit. The goal here is to enable C API users to compose custom transpilation workflows using the built-in passes. To start since we don't have a DAGCircuit representation in C we should expose the equivalent of the Python Pass(..)(qc) pattern and expose a standalone function that takes in a circuit and runs the pass on just that. For example:

QkCircuit *qk_optimize_1q_gates_decomposition(QkCircuit *circuit, Target *target)

or

NLayout *qk_vf2_layout(QkCircuit *circuit, Target *target, long long call_limit, double time_limit long long max_trials)

where internally it runs circuit -> dag conversion and then the corresponding rust function for the pass. When we have a DAGCircuit representation in C we should expose a function for that as the input too. Just like with transpile the goal here is not to replace Python space transpilation in a mixed usage mode (if Python is available that should be the entrypoint for the transpiler), but instead to expose an entrypoint for the user that is operating without Python.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    C APIRelated to the C APIRustThis PR or issue is related to Rust code in the repositorymod: transpilerIssues and PRs related to Transpilertype: epicA theme of work that contain sub-taskstype: feature requestNew feature or request

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions