Beispiel #1
0
    def _serialize_program(
        self,
        program: TProgram,
        gate_set: serializable_gate_set.SerializableGateSet = None
    ) -> Dict[str, Any]:
        gate_set = gate_set or gate_sets.XMON

        if self.proto_version == ProtoVersion.V1:
            schedule = self.program_as_schedule(program)
            schedule.device.validate_schedule(schedule)

            program_descriptor = v1.program_pb2.Program.DESCRIPTOR
            program_dict = {}  # type: Dict[str, Any]
            program_dict['@type'] = TYPE_PREFIX + program_descriptor.full_name
            program_dict['operations'] = [
                op for op in api_v1.schedule_to_proto_dicts(schedule)
            ]
            return program_dict
        elif self.proto_version == ProtoVersion.V2:
            if isinstance(program, schedules.Schedule):
                program.device.validate_schedule(program)
            program = gate_set.serialize(program)
            return _any_dict_from_msg(program)
        else:
            raise ValueError('invalid program proto version: {}'.format(
                self.proto_version))
Beispiel #2
0
    def _serialize_program_v1(
            self, program: Program, sweeps: List[Sweep],
            repetitions: int) -> Tuple[Dict[str, Any], Dict[str, Any]]:
        schedule = self.program_as_schedule(program)
        schedule.device.validate_schedule(schedule)

        program_descriptor = v1.program_pb2.Program.DESCRIPTOR
        program_dict = {}  # type: Dict[str, Any]
        program_dict['@type'] = TYPE_PREFIX + program_descriptor.full_name
        program_dict['operations'] = [
            op for op in api_v1.schedule_to_proto_dicts(schedule)
        ]

        context_descriptor = v1.program_pb2.RunContext.DESCRIPTOR
        context_dict = {}  # type: Dict[str, Any]
        context_dict['@type'] = TYPE_PREFIX + context_descriptor.full_name
        context_dict['parameter_sweeps'] = [
            api_v1.sweep_to_proto_dict(sweep, repetitions) for sweep in sweeps
        ]
        return program_dict, context_dict