|
5 | 5 | import sys
|
6 | 6 | from copy import deepcopy
|
7 | 7 | from functools import reduce, partial
|
8 |
| -from typing import Any, Callable, Optional, Sequence, List, Union |
| 8 | +from typing import Any, Callable, Optional, Sequence, List, Union, Tuple |
9 | 9 | from operator import mul
|
10 | 10 |
|
11 | 11 | import numpy as np
|
12 | 12 | import tensornetwork as tn
|
13 | 13 | from scipy.stats import unitary_group
|
14 | 14 |
|
15 |
| -from .cons import backend, dtypestr, npdtype |
| 15 | +from .cons import backend, dtypestr, npdtype, rdtypestr |
16 | 16 | from .backends import get_backend # type: ignore
|
17 | 17 | from .utils import arg_alias
|
18 | 18 |
|
@@ -466,6 +466,27 @@ def phase_gate(theta: float = 0) -> Gate:
|
466 | 466 | return Gate(unitary)
|
467 | 467 |
|
468 | 468 |
|
| 469 | +# TODO(@refraction-ray): not correct now, correct impl required |
| 470 | +def get_u_parameter(m: Tensor) -> Tuple[Tensor, Tensor, Tensor]: |
| 471 | + """ |
| 472 | + From the single qubit unitary to infer three angles of IBMUgate |
| 473 | +
|
| 474 | + :param m: _description_ |
| 475 | + :type m: Tensor |
| 476 | + :return: theta, phi, lbd |
| 477 | + :rtype: Tuple[Tensor, Tensor, Tensor] |
| 478 | + """ |
| 479 | + print("wrong impl, dont use!") |
| 480 | + a, b, c = m[0, 0], m[0, 1], m[1, 0] |
| 481 | + if a == 0: |
| 482 | + theta = np.pi |
| 483 | + else: |
| 484 | + theta = 2 * backend.atan(backend.sqrt(1 - a**2) / a) |
| 485 | + lbd = -1j * backend.log(b * backend.sqrt(1 - a**2) / (a**2 - 1)) |
| 486 | + phi = -1j * backend.log(c / backend.sqrt(1 - a**2)) |
| 487 | + return array_to_tensor(theta, phi, lbd, dtype=rdtypestr) # type: ignore |
| 488 | + |
| 489 | + |
469 | 490 | def u_gate(theta: float = 0, phi: float = 0, lbd: float = 0) -> Gate:
|
470 | 491 | r"""
|
471 | 492 | IBMQ U gate following the converntion of OpenQASM3.0.
|
|
0 commit comments