-
Notifications
You must be signed in to change notification settings - Fork 586
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
Adds Single Excitation operations #1121
Changes from all commits
c211c02
c9aa6d4
49d231e
143cbe3
5f12bbc
6382dc1
9769875
0521cd2
fa16191
a7c4f97
ae018d5
23e85ed
4cd76e7
882bb77
40b2320
3e9f7ba
62683a1
ac178d3
ced73be
6c7bc21
50be11c
d8343c2
0744aaa
aeb6751
711c72e
e6a00e4
95c450c
1b9121d
08fbb8b
0cc729e
40ffa08
2fedf4c
31c05b0
a0bc66a
af9f449
f141160
6bb3848
2b04db3
21d6dc0
c685a6c
27adb98
a0b8328
be16056
5a8432b
a0846e1
b63561c
0875d71
efb0fc4
63a57d3
ea45124
5e7eae1
346edfa
b142126
95d9abc
0c059ea
d85a148
c297f75
434a9ba
2476d1f
ac05f79
9ec2fd3
9348192
042f2b9
a1ef6f1
1d5fc6b
083c61e
ac42e67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,3 +180,47 @@ def MultiRZ(theta, n): | |
array[complex]: diagonal part of the multi-qubit rotation matrix | ||
""" | ||
return jnp.exp(-1j * theta / 2 * pauli_eigs(n)) | ||
|
||
|
||
def SingleExcitation(phi): | ||
r"""Single excitation rotation. | ||
|
||
Args: | ||
phi (float): rotation angle | ||
|
||
Returns: | ||
jnp.Tensor[float]: Single excitation rotation matrix | ||
""" | ||
c = jnp.cos(phi / 2) | ||
s = jnp.sin(phi / 2) | ||
return jnp.array([[1, 0, 0, 0], [0, c, -s, 0], [0, s, c, 0], [0, 0, 0, 1]]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here regarding the type of the returned array, |
||
|
||
|
||
def SingleExcitationPlus(phi): | ||
r"""Single excitation rotation with positive phase-shift outside the rotation subspace. | ||
|
||
Args: | ||
phi (float): rotation angle | ||
|
||
Returns: | ||
jnp.Tensor[complex]: Single excitation rotation matrix with positive phase-shift | ||
""" | ||
c = jnp.cos(phi / 2) | ||
s = jnp.sin(phi / 2) | ||
e = jnp.exp(1j * phi / 2) | ||
return jnp.array([[e, 0, 0, 0], [0, c, -s, 0], [0, s, c, 0], [0, 0, 0, e]]) | ||
|
||
|
||
def SingleExcitationMinus(phi): | ||
r"""Single excitation rotation with negative phase-shift outside the rotation subspace. | ||
|
||
Args: | ||
phi (float): rotation angle | ||
|
||
Returns: | ||
tf.Tensor[complex]: Single excitation rotation matrix with negative phase-shift | ||
""" | ||
c = jnp.cos(phi / 2) | ||
s = jnp.sin(phi / 2) | ||
e = jnp.exp(-1j * phi / 2) | ||
return jnp.array([[e, 0, 0, 0], [0, c, -s, 0], [0, s, c, 0], [0, 0, 0, e]]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,3 +191,51 @@ def CRot(a, b, c): | |
:math:`|0\rangle\langle 0|\otimes \mathbb{I}+|1\rangle\langle 1|\otimes R(a,b,c)` | ||
""" | ||
return tf.linalg.diag(CRZ(c)) @ (CRY(b) @ tf.linalg.diag(CRZ(a))) | ||
|
||
|
||
def SingleExcitation(phi): | ||
r"""Single excitation rotation. | ||
|
||
Args: | ||
phi (float): rotation angle | ||
|
||
Returns: | ||
tf.Tensor[complex]: Single excitation rotation matrix | ||
ixfoduap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
""" | ||
phi = tf.cast(phi, dtype=C_DTYPE) | ||
c = tf.cos(phi / 2) | ||
s = tf.sin(phi / 2) | ||
return tf.convert_to_tensor([[1, 0, 0, 0], [0, c, -s, 0], [0, s, c, 0], [0, 0, 0, 1]]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably the same here: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: while true for JAX and autograd above, in this case the tensor will be complex, since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Attention to details! 😄 |
||
|
||
|
||
def SingleExcitationPlus(phi): | ||
r"""Single excitation rotation with positive phase-shift outside the rotation subspace. | ||
|
||
Args: | ||
phi (float): rotation angle | ||
|
||
Returns: | ||
tf.Tensor[complex]: Single excitation rotation matrix with positive phase-shift | ||
""" | ||
phi = tf.cast(phi, dtype=C_DTYPE) | ||
c = tf.cos(phi / 2) | ||
s = tf.sin(phi / 2) | ||
e = tf.exp(1j * phi / 2) | ||
return tf.convert_to_tensor([[e, 0, 0, 0], [0, c, -s, 0], [0, s, c, 0], [0, 0, 0, e]]) | ||
|
||
|
||
def SingleExcitationMinus(phi): | ||
r"""Single excitation rotation with negative phase-shift outside the rotation subspace. | ||
|
||
Args: | ||
phi (float): rotation angle | ||
|
||
Returns: | ||
tf.Tensor[complex]: Single excitation rotation matrix with negative phase-shift | ||
""" | ||
phi = tf.cast(phi, dtype=C_DTYPE) | ||
c = tf.cos(phi / 2) | ||
s = tf.sin(phi / 2) | ||
e = tf.exp(-1j * phi / 2) | ||
return tf.convert_to_tensor([[e, 0, 0, 0], [0, c, -s, 0], [0, s, c, 0], [0, 0, 0, e]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstring declares that the function returns
array[complex]
but the matrix elementss
andc
are real, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!