예제 #1
0
def test_aqt_device_wrong_op_str():
    circuit = Circuit()
    q0, q1 = LineQubit.range(2)
    circuit.append(CNOT(q0, q1)**1.0)
    for op in circuit.all_operations():
        with pytest.raises(ValueError):
            _result = get_op_string(op)
예제 #2
0
    def _generate_json(
        self,
        circuit: circuits.Circuit,
        param_resolver: study.ParamResolverOrSimilarType,
    ) -> str:
        """Generates the JSON string from a Circuit

        The json format is defined as follows:

        [[op_string,gate_exponent,qubits]]

        which is a list of sequential quantum operations,
        each operation defined by:

        op_string: str that specifies the operation type: "X","Y","Z","MS"
        gate_exponent: float that specifies the gate_exponent of the operation
        qubits: list of qubits where the operation acts on.

        Args:
            circuit: Circuit to be run
            param_resolver: Param resolver for the

        Returns:
            json formatted string of the sequence
        """

        seq_list: List[Union[Tuple[str, float, List[int]],
                             Tuple[str, float, float, List[int]]]] = []
        circuit = resolve_parameters(circuit, param_resolver)
        for op in circuit.all_operations():
            line_qubit = cast(Tuple[LineQubit], op.qubits)
            op = cast(ops.GateOperation, op)
            qubit_idx = [obj.x for obj in line_qubit]
            op_str = get_op_string(op)
            gate: Union[ops.EigenGate, ops.PhasedXPowGate]
            if op_str == 'R':
                gate = cast(ops.PhasedXPowGate, op.gate)
                seq_list.append((op_str, float(gate.exponent),
                                 float(gate.phase_exponent), qubit_idx))
            else:
                gate = cast(ops.EigenGate, op.gate)
                seq_list.append((op_str, float(gate.exponent), qubit_idx))
        if len(seq_list) == 0:
            raise RuntimeError('Cannot send an empty circuit')
        json_str = json.dumps(seq_list)
        return json_str
예제 #3
0
    def _generate_json(
        self,
        circuit: circuits.Circuit,
        param_resolver: study.ParamResolverOrSimilarType,
    ) -> str:
        """
        Args:
            circuit: Circuit to be run
            param_resolver: Param resolver for the

        Returns:
            json formatted string of the sequence

        The json format is defined as follows:

        [[op_string,gate_exponent,qubits]]

        which is a list of sequential quantum operations,
        each operation defined by:

        op_string: str that specifies the operation type, either "X","Y","MS"
        gate_exponent: float that specifies the gate_exponent of the operation
        qubits: list of qubits where the operation acts on.
        """

        seq_list: List[Tuple[str, float, List[int]]] = []
        circuit = resolve_parameters(circuit, param_resolver)
        # TODO: Check if circuit is empty
        for op in circuit.all_operations():
            line_qubit = cast(Tuple[LineQubit], op.qubits)
            op = cast(ops.GateOperation, op)
            qubit_idx = [obj.x for obj in line_qubit]
            op_str = get_op_string(op)
            gate = cast(ops.EigenGate, op.gate)
            seq_list.append((op_str, gate.exponent, qubit_idx))
        json_str = json.dumps(seq_list)
        return json_str