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

WIP: [Adding Specification for the Adaptive Profile] #35

Draft
wants to merge 54 commits into
base: main
Choose a base branch
from

Conversation

peter-campora
Copy link

Trying this again. I expect linting issues but hopefully no committer/CLA issues. Initial draft of the specification here for public comments.

Copy link

@qci-amos qci-amos left a comment

Choose a reason for hiding this comment

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

I was asked to take a look, so here are some quick comments. I'll come back later when I have time.

One question I couldn't find a suitable place for based on a quick search is a way for backends to specify whether they want their loops unrolled (if possible) or not.

Copy link

@qci-amos qci-amos left a comment

Choose a reason for hiding this comment

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

I've gotten as far as the Program Structure section. This is well written, but it's taking me a while to work through it!!

I'll come back later. 😓

Adaptive Profile compliance with additional features. A maximal Adaptive Profile program adds
all of the following capabilities. The extended possible Adaptive Profile capabilities a program can express are:

8. Qubit resetting (`__quantum__qis__reset__body` supported in the instruction set).

Choose a reason for hiding this comment

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

arguably, at least naive implementations of this feature are covered by features 4-7. is there a reason 8 is not in the same section as those?

Copy link
Author

Choose a reason for hiding this comment

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

I think one could still have branching features and conditional gates based on say random number generation if a back-end has support for extern function call outs.

point arithmetic calculations of a back-end specified width, or logical operations
on integers of a back-end specified width. Front-ends can use any integer width when generating code,
and it is the responsiblity of a back-end to provide a compile-time error message if the front-end
uses an integer width greater than that which the support.

Choose a reason for hiding this comment

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

two concerns:

  • an end-user would be working with a "high level" data type which is likely to imply high width (so how would they know), and
  • therefore some mechanism for lowering the width would need to happen somewhere (breaking this guidance)

Personally, I wouldn't be excited about having to deal with explicit typing (e.g., numpy's dtype) either as an end-user or working on a backend. On the other hand, rigor is good too...

Copy link
Member

Choose a reason for hiding this comment

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

We intend to update the spec to have the module flag explicitly specifying the used data type size(s). The backend should then look at these flags and reject the program if it does not provide support for these sizes.

Copy link

@chemix-lunacy chemix-lunacy left a comment

Choose a reason for hiding this comment

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

One thing that isn't clear from reading, and it seems this context also switches depending upon topic, is whether the spec views QIR to be run almost-directly on a QPU, or whether it's executed by a runtime which provides classical support and that calls to a QPU.

It talks about classical results post-processing on one hand, then about how memory on the FPGA should be highlighted to consumer systems on the other. I've always considered it (relatively) high-level - your QIR is the basic outline of what you'd like to run, including all contextual information added to help the backend run your request better. Especially since if you implement the full QIR spec you can send classical programs with fragments of quantum in it and run them directly.

While you can interpret it at both levels, and it depends upon what sort of backend you have, certain assertions and constraints don't apply depending upon what lens you look at it though.

Also out of curiosity: is this the outcome of some working group?

Copy link

github-actions bot commented Nov 8, 2023

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the Contributor License Agreement and I hereby accept the Terms.


3 out of 4 committers have signed the CLA.
@peter-campora
@qartik
@bettinaheim
@Bettina Heim
Bettina Heim seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request


### Bullet 3: Program output

There is no change to output specifications with respect to the base profile, sans for the
Copy link
Collaborator

Choose a reason for hiding this comment

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

Error codes are no longer present in the spec. Non-zero return values indicate an error has occurred, but are all provider/backend specific.

| __quantum__rt__array_record_output | `void(i64,i8*)` | Inserts a marker in the generated output that indicates the start of an array and how many array elements it has. The second parameter defines a string label for the array. Depending on the output schema, the label is included in the output or omitted. |
| __quantum__rt__result_record_output | `void(%Result*,i8*)` | Adds a measurement result to the generated output. The second parameter defines a string label for the result value. Depending on the output schema, the label is included in the output or omitted. |
| __quantum__rt__bool_record_output | `void(i1,i8*)` | Adds a boolean value to the generated output. The second parameter defines a string label for the result value. Depending on the output schema, the label is included in the output or omitted. |

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to update the output recording formats to include any changes in recording varying bit widths for int, float, fixed.


## Runtime Functions

The following runtime functions must be supported by all backends:
Copy link

Choose a reason for hiding this comment

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

This table is missing the __quantum__rt__bool_record_output function.

Additionally, the Adaptive Profile imposes the following restrictions on qubit
and result usage:

- Qubits must not be used after they have been passed as arguments to a function
Copy link

Choose a reason for hiding this comment

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

This seems inconsistent with the rest of the specification. Up to this point, qubit reuse is a required capability, but this point conveys the message that qubit reuse is not supported in an adaptive profile program.

support more advanced adaptive computations:

<!-- markdownlint-disable MD029 -->
5. Computations on classical (non-composite) data types, specifically on
Copy link

Choose a reason for hiding this comment

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

This point mentions fixed-point numbers, which should not be included.

!3 = !{i32 1, !"dynamic_result_management", i1 false}
!4 = !{i32 5, !"int_computations", !""}
!5 = !{i32 5, !"float_computations", !""}
!6 = !{i32 5, !"fixedpoint_computations", !""}
Copy link

Choose a reason for hiding this comment

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

This sample contains a the fixedpoint_computations module flag which is no longer part of the spec.

floating point numbers of all listed precisions must be supported by the
executing backend. An empty value indicates that no floating-point
computations are supported/used.
- a flag with the string identifier `"fixedpoint_computations"` that contains a
Copy link

Choose a reason for hiding this comment

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

This point should be removed since fixed point computations are no longer part of the adaptive profile spec.

computations with precision `2N`, and it must be able to process constant
integer values of type `i32` being passed as scale. See also the [LLVM
Language
Reference](https://llvm.org/docs/LangRef.html#fixed-point-arithmetic-intrinsics).
Copy link

Choose a reason for hiding this comment

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

This point should also be removed since it references fixed point computations.

Allow to define and use global constants for (only) the supported data types.
-->

### Bullet 6: IR-defined functions and function calls
Copy link

Choose a reason for hiding this comment

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

I think a few more restrictions are required on IR-defined functions:

  • Calls to IR-defined functions should only take constant %Qubit and %Result arguments.
  • Currently, it is specified that IR-defined functions can return a value of type %Result. I think this should not be the case because it would require dynamic result allocation.
  • Within IR-defined functions, the only %Qubit and %Result values that can be used are the ones coming from arguments.

Comment on lines 793 to 794
`inlinehint`, `nofree`, `norecurse`, `readnone`, `readonly`, `writeonly`, and
`argmemonly`.
Copy link

@cesarzc cesarzc Aug 28, 2024

Choose a reason for hiding this comment

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

Is there a reason to highlight this specific set of LLVM attributes? I would think that if someone includes certain attributes LLVM attributes in their QIR program, consumers of that program can use some of them as hints for processing it but it would be up to them which specific attributes will have special handling.

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.