Skip to content

Creating a n-dimensional state vector space for nonperfect square n #583

Open
@nkoskelo

Description

@nkoskelo

I am opening this issue now, I will fix it next week.

On version '0.9.13.1', I am getting an error when I try to make a basis for a two dimensional state vector space.

from pygsti.baseobjs.basis import BuiltinBasis
b = BuiltinBasis("sv", 2)

Suggests that the dimension needs to be a perfect square, but one should be able to make a state vector of any dimension.

Here is the error message.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/name/pg-misc/pygsti-repo/pygsti/baseobjs/basis.py", line 1071, in __init__
    else _statespace.default_space_for_dim(dim_or_statespace)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/name/pg-misc/pygsti-repo/pygsti/baseobjs/statespace.py", line 1296, in default_space_for_dim
    assert(udim**2 == dim), "`dim` must be a perfect square: %d is not" % dim
           ^^^^^^^^^^^^^^
AssertionError: `dim` must be a perfect square: 2 is not

For a four dimensional state vector space we see that,

print(BuiltinBasis("sv", 4))

returns

State-vector basis (dim=4), 4 elements of shape (4,) :
|0>, |1>, |2>, |3>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA bug or regression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions