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

Momentum and position default isherm values. #2032

Merged
merged 4 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/2032.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added default _isherm value (True) for momentum and position operators.
8 changes: 6 additions & 2 deletions qutip/core/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,9 @@ def position(N, offset=0, *, dtype=_data.CSR):
Position operator as Qobj.
"""
a = destroy(N, offset=offset, dtype=dtype)
return np.sqrt(0.5) * (a + a.dag())
position = np.sqrt(0.5) * (a + a.dag())
position._isherm = True
AGaliciaMartinez marked this conversation as resolved.
Show resolved Hide resolved
return position


def momentum(N, offset=0, *, dtype=_data.CSR):
Expand All @@ -621,7 +623,9 @@ def momentum(N, offset=0, *, dtype=_data.CSR):
Momentum operator as Qobj.
"""
a = destroy(N, offset=offset, dtype=dtype)
return -1j * np.sqrt(0.5) * (a - a.dag())
momentum = -1j * np.sqrt(0.5) * (a - a.dag())
momentum._isherm = True
AGaliciaMartinez marked this conversation as resolved.
Show resolved Hide resolved
return momentum


def num(N, offset=0, *, dtype=_data.CSR):
Expand Down
2 changes: 2 additions & 0 deletions qutip/tests/core/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,15 @@ def test_position():
expected = (np.diag((np.arange(1, N) / 2)**0.5, k=-1) +
np.diag((np.arange(1, N) / 2)**0.5, k=1))
np.testing.assert_allclose(operator.full(), expected)
assert operator._isherm == True


def test_momentum():
operator = qutip.momentum(N)
expected = (np.diag((np.arange(1, N) / 2)**0.5, k=-1) -
np.diag((np.arange(1, N) / 2)**0.5, k=1)) * 1j
np.testing.assert_allclose(operator.full(), expected)
assert operator._isherm == True


def test_squeeze():
Expand Down