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

Define constants for readability and bug finding #24

Open
wants to merge 3 commits into
base: gates-in-rust
Choose a base branch
from

Conversation

jlapeyre
Copy link

@jlapeyre jlapeyre commented May 9, 2024

Something like this might be easier to read.

Many computations are not allowed when defining and using consts. So unfortunately, things like -ONE are not allowed.

See for example CCXGATE

Pretty sure Complex64 is Copy, otherwise it would not compile.

mtreinish and others added 2 commits May 7, 2024 15:52
This commit adds a native representation of Gates, Instruction, and
Operations to rust's circuit module. At a high level this works by
either wrapping the Python object in a rust wrapper struct that tracks
metadata about the operations (name, num_qubits, etc) and then for other
details it calls back to Python to get dynamic details like the
definition, matrix, etc. For standard library gates like Swap, CX, H,
etc this replaces the on circuit representation with a new enum
StandardGate. The enum representation is much more efficient and has a
minimal memory footprint as all the gate properties are defined in code
based on the enum variant (which represents the gate).

The use of an enum to represent standard gates does mean a change in
what we store on a CircuitInstruction. To represent a standard gate
fully we need to store the mutable properties of the existing Gate class
on the circuit instruction as the gate by itself doesn't contain this
detail. That means, the parameters, label, unit, duration, and condition
are added to the rust side of circuit instrucion. However no Python side
access methods are added for these as they're internal only to the rust
code and hopefully in Qiskit 2.0 we'll be able to drop, unit, duration,
and condition from the api leaving only label and parameters.

When an object is added to a CircuitInstruction the operation field is
translated to it's internal representation automatically. For standard
gates this translates it to the enum form, and for Python defined gates
this involves just wrapping them. Then whenever the operation field of
a circuit instruction object is read from python it converts it back to
the normal Python object representation.

This commit does not translate the full standard library of gates as
that would make the pull request huge, instead this adds the basic
infrastructure for having a more efficient standard gate representation
on circuits. There will be follow up pull requests to add the missing
gates and round out support in rust.

The goal of this pull request is primarily to add the infrastructure for
representing the full circuit model (and dag model in the future) in
rust. By itself this is not expected to improve runtime performance (if
anything it will probably hurt performance because of extra type
conversions) but it is intended to enable writing native circuit
manipulations in rust, including transpiler passes without needing
involvement from Python.

TODO:

- [ ] Fix parameter handling on copy (might involve moving parameter
  table to rust)
- [ ] Handle global phase in definitions (might mean moving a
  QuantumCircuit struct to rust instead of just CircuitData)
- [ ] Add definitions for gates migrated so far

Fixes: Qiskit#12205
@jlapeyre jlapeyre force-pushed the gjl-changes-gates-in-rust branch from e0bedf9 to 4614348 Compare May 9, 2024 17:56
@jlapeyre
Copy link
Author

I added fn c64() in 37f4fd4. This is very close to the function that is new in num_complex 0.4.6, which is just a couple of lines. But the one I included here is a bit more flexible.

AFAIKT, neither is as flexible as we'd like as they can't be used in const or static constructions.

@mtreinish mtreinish force-pushed the gates-in-rust branch 2 times, most recently from e6030f6 to f896512 Compare May 25, 2024 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants