Exemplo n.º 1
0
 (
     Gate.ZZ(angle=0.17),
     [4, 5],
     OpenQASMSerializationProperties(
         qubit_reference_type=QubitReferenceType.VIRTUAL),
     "zz(0.17) q[4], q[5];",
 ),
 (
     Gate.ZZ(angle=0.17),
     [4, 5],
     OpenQASMSerializationProperties(
         qubit_reference_type=QubitReferenceType.PHYSICAL),
     "zz(0.17) $4, $5;",
 ),
 (
     Gate.I(),
     [4],
     OpenQASMSerializationProperties(
         qubit_reference_type=QubitReferenceType.VIRTUAL),
     "i q[4];",
 ),
 (
     Gate.I(),
     [4],
     OpenQASMSerializationProperties(
         qubit_reference_type=QubitReferenceType.PHYSICAL),
     "i $4;",
 ),
 (
     Gate.V(),
     [4],
Exemplo n.º 2
0
def i_unitary():
    return Unitary(Gate.I().to_matrix())
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

import math

import numpy as np
import pytest

from braket.circuits import Gate, Observable
from braket.circuits.observables import observable_from_ir
from braket.circuits.quantum_operator_helpers import get_pauli_eigenvalues

testdata = [
    (Observable.I(), Gate.I(), ["i"], (), np.array([1, 1])),
    (Observable.X(), Gate.X(), ["x"], tuple([Gate.H()]),
     get_pauli_eigenvalues(1)),
    (
        Observable.Y(),
        Gate.Y(),
        ["y"],
        tuple([Gate.Z(), Gate.S(), Gate.H()]),
        get_pauli_eigenvalues(1),
    ),
    (Observable.Z(), Gate.Z(), ["z"], (), get_pauli_eigenvalues(1)),
    (Observable.H(), Gate.H(), ["h"], tuple([Gate.Ry(-math.pi / 4)]),
     get_pauli_eigenvalues(1)),
]

invalid_hermitian_matrices = [
Exemplo n.º 4
0
            ], [Instruction(Gate.CNot(), [0, 1])]),
 (
     None,
     None,
     [Instruction(Gate.H(), 1),
      Instruction(Gate.CNot(), [0, 1])],
     [Instruction(Observable.X, 0)],
 ),
 (
     Gate.H,
     range(3),
     [Instruction(Gate.H(), 0),
      Instruction(Gate.H(), 1)],
     [
         Instruction(Gate.H(), 3),
         Instruction(Gate.I(), 1),
         [Instruction(Gate.H(), 0)],
     ],
 ),
 (Gate.H, 1, [Instruction(Gate.H(), 1)], [Instruction(Gate.H(), 0)]),
 ([Gate.H], [1], [Instruction(Gate.H(), 1)], [Instruction(Gate.H(), 0)
                                              ]),
 (
     [Gate.CNot],
     [0, 1],
     [Instruction(Gate.CNot(), [0, 1])],
     [Instruction(Gate.CNot(), [1, 0])],
 ),
 (
     [Gate.CNot],
     [[0, 1], [1, 2]],