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
Improve Qobj creation function metadata setting #2388
Conversation
qutip/tests/core/test_gates.py
Outdated
@@ -142,3 +150,49 @@ def test_gate_normalises_pauli_group(self, gate): | |||
del pauli_gates[i] | |||
break | |||
assert len(pauli_gates) == 0 | |||
|
|||
|
|||
@pytest.mark.parametrize("dtype", [qutip.data.Dense, qutip.data.CSR]) |
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.
Should we just check the Dia type here too? I guess the with qutip.CoreOptions(default_dtype="dia")
around clifford = ...
above was to check the Dia case, but I would prefer not to have to stare at the test to tell that Dia is tested too.
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.
I choose 2 types so we don't only get the default, but not all type since we are not testing the conversion code, just that it is used. Adding dia
would just add more test without testing anything new.
op.to(dtype) | ||
for op in map( | ||
partial(reduce, mul), | ||
product(_powers(E, 3), _powers(X, 2), _powers(S, 4)), | ||
) | ||
] | ||
for gate in gates: | ||
gate.isherm |
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.
?
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.
Set the flags, since there are 24 of them with some being hermitian other not, I call the method compute them. Since they are all 2x2, it does not that a significant time.
return Qobj( | ||
[ | ||
[np.cos(phi / 2), -1j * np.sin(phi / 2)], | ||
[-1j * np.sin(phi / 2), np.cos(phi / 2)], | ||
] | ||
], | ||
isherm=(phi % (2 * np.pi) <= settings.core["atol"]), |
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.
This is nice but I fear that it may again cause problems with jit. I'm fine just leave it None here. The same for other rotations.
@@ -72,10 +83,11 @@ def cz_gate(*, dtype="csr"): | |||
result : :class:`.Qobj` | |||
Quantum object for operator describing the rotation. | |||
""" | |||
return qdiags([1, 1, 1, -1], dims=[[2, 2], [2, 2]], dtype=dtype) | |||
dtype = dtype or settings.core["default_dtype"] or _data.CSR | |||
return qdiags([1, 1, 1, -1], dims=_DIMS_2_QB, dtype=dtype) |
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.
How does qdiags handle the isherms property? Will it check if the input is real? If so, maybe for those we could manually set the isherms and isunitary.
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.
When there is only one diagonal, it sets it automatically.
There is only one case in our code base where this is not the case (and it's not in the tests...).
Improving tests for it and adding manual flag setting could make a good first issue.
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.
Other than my two small suggestions, looks good.
Co-authored-by: Simon Cross <hodgestar+github@gmail.com>
Description
Many of the operator functions did not set the
isherm
flag.Not having the flag set would cause issue with
jax.jit
.isherm
flag for almost every functions inoperators.py
andgates.py
.qdiags
flags are only set when only one diagonal in used.commutator
,squeezing
)isunitary
flags for all these also.dtype
parameter to use thedefault_dtype
settings.dtype
parameter.