Example #1
0
def test_ir_non_empty_instructions_result_types_basis_rotation_instructions():
    circ = Circuit().h(0).cnot(0, 1).sample(observable=Observable.X(),
                                            target=[0])
    expected = jaqcd.Program(
        instructions=[jaqcd.H(target=0),
                      jaqcd.CNot(control=0, target=1)],
        results=[jaqcd.Sample(observable=["x"], targets=[0])],
        basis_rotation_instructions=[jaqcd.H(target=0)],
    )
    assert circ.to_ir() == expected
Example #2
0
def test_calculate_ir_results(ir_result, expected_result):
    ir_string = jaqcd.Program(
        instructions=[jaqcd.H(target=i) for i in range(4)], results=[ir_result]
    ).json()
    measured_qubits = [0, 1, 2, 3]
    measurements = np.array(
        [
            [0, 0, 1, 0],
            [1, 1, 1, 1],
            [1, 0, 0, 1],
            [0, 0, 1, 0],
            [1, 1, 1, 1],
            [0, 1, 1, 1],
            [0, 0, 0, 1],
            [0, 1, 1, 1],
            [0, 0, 0, 0],
            [0, 0, 0, 1],
        ]
    )
    result_types = GateModelQuantumTaskResult._calculate_result_types(
        ir_string, measurements, measured_qubits
    )
    assert len(result_types) == 1
    assert result_types[0].type == ir_result
    assert np.allclose(result_types[0].value, expected_result)
Example #3
0
def test_ir_non_empty_instructions_result_types():
    circ = Circuit().h(0).cnot(0, 1).probability([0, 1])
    expected = jaqcd.Program(
        instructions=[jaqcd.H(target=0),
                      jaqcd.CNot(control=0, target=1)],
        results=[jaqcd.Probability(targets=[0, 1])],
        basis_rotation_instructions=[],
    )
    assert circ.to_ir() == expected
Example #4
0
    def _qft_operations(qubit_count):
        qft_ops = []
        for target_qubit in range(qubit_count):
            angle = np.pi / 2
            qft_ops.append(jaqcd.H(target=target_qubit))
            for control_qubit in range(target_qubit + 1, qubit_count):
                qft_ops.append(
                    jaqcd.CPhaseShift(control=control_qubit,
                                      target=target_qubit,
                                      angle=angle))
                angle /= 2

        amplitudes = [
            "".join([str(random.randint(0, 1)) for _ in range(qubit_count)])
            for _ in range(2**(qubit_count // 2))
        ]
        return jaqcd.Program(
            instructions=qft_ops,
            results=[
                jaqcd.StateVector(),
                jaqcd.Amplitude(states=amplitudes),
                jaqcd.Expectation(observable=["x"]),
            ],
        )
Example #5
0
#
# 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 pytest

import braket.ir.jaqcd as instruction
from braket.default_simulator import gate_operations
from braket.default_simulator.operation_helpers import check_unitary
from braket.ir.jaqcd import shared_models

testdata = [
    (instruction.I(target=4), (4,), gate_operations.Identity),
    (instruction.H(target=13), (13,), gate_operations.Hadamard),
    (instruction.X(target=11), (11,), gate_operations.PauliX),
    (instruction.Y(target=10), (10,), gate_operations.PauliY),
    (instruction.Z(target=9), (9,), gate_operations.PauliZ),
    (instruction.CNot(target=9, control=11), (11, 9), gate_operations.CX),
    (instruction.CY(target=10, control=7), (7, 10), gate_operations.CY),
    (instruction.CZ(target=14, control=7), (7, 14), gate_operations.CZ),
    (instruction.S(target=2), (2,), gate_operations.S),
    (instruction.Si(target=2), (2,), gate_operations.Si),
    (instruction.T(target=1), (1,), gate_operations.T),
    (instruction.Ti(target=1), (1,), gate_operations.Ti),
    (instruction.V(target=1), (1,), gate_operations.V),
    (instruction.Vi(target=1), (1,), gate_operations.Vi),
    (instruction.PhaseShift(target=2, angle=0.15), (2,), gate_operations.PhaseShift),
    (
        instruction.CPhaseShift(target=2, control=7, angle=0.15),