Skip to content

How to_unitary_mut should work #467

@bramathon

Description

@bramathon

Currently, to_unitary_mut requires the user to specify the dimension of the unitary.

This seem unnecessary and I'm not sure what it's used for. I suspect, however, that it's used to "lift" unitaries to a larger Hilbert space based on the qubit indices. This is not a good approach because it assumes that the space is for qubits 0 to n, in that order while in fact a Hilbert space could be defined on qubits 5, 3, 10, 33, for example. If lifting is required, a separate function should be provided and it should require the Hilbert space qubit order to be specified.

Rather to_unitary_mut should return the canonical matrix of the gate. There is no need to specify the dimension, it's a property of the gate and should produce a matrix of dimensions (2^n, 2^n).

Furthermore, I would like all Gate instructions in a program to have a unitary attached to them. For standard quil gates, this is achieved by to_unitary_mut, however, for defined gates in the program this is not the case. Rather the user needs to check the defined gates of the program to know what is the definition of an instruction. Ideally, this would not be necessary, the instruction would have the defgate associated with it allowing the following.

program = """DEFGATE BLARG AS MATRIX:
    -0.28705672572498936-0.11277532694223659i, -0.5998793485470028-0.3613248187346551i, -0.05259662196286458-0.6195952054027546i, 0.05949628004150796+0.15577186480089364i
    0.0042693221909431-0.37767648756583294i, 0.21434622020589333+0.0861879617069231i, -0.3702023023607123-0.3181064164720223i, -0.6471484586315557-0.3833105951903434i
    -0.3999605210419518+0.6267674838894352i, 0.16961228281142476+0.24120155674611812i, 0.3866424148211197-0.30283186464280754i, -0.344791688723465-0.012914391002983222i
    -0.407825281226674+0.2075934686261242i, 0.4307462151034142-0.42863464210242547i, -0.36409272342149845-0.03648196124031003i, 0.39962918525837543-0.35737319861073946i

BLARG 0 1"""

program = Program.parse(program)

program.body_instructions[0].to_unitary_mut()

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions