Exemplo n.º 1
0
    def program_as_schedule(self, program: Union[Circuit,
                                                 Schedule]) -> Schedule:
        if isinstance(program, Circuit):
            device = program.device
            circuit_copy = program.copy()
            ConvertToXmonGates().optimize_circuit(circuit_copy)
            DropEmptyMoments().optimize_circuit(circuit_copy)
            device.validate_circuit(circuit_copy)
            return moment_by_moment_schedule(device, circuit_copy)

        elif isinstance(program, Schedule):
            return program

        else:
            raise TypeError('Unexpected program type.')
Exemplo n.º 2
0
    def _to_xmon_circuit(
            self,
            circuit: Circuit,
            param_resolver: ParamResolver,
            extensions: Extensions = None) -> Tuple[Circuit, Set[str]]:
        converter = ConvertToXmonGates(extensions)
        extensions = converter.extensions

        # TODO: Use one optimization pass.
        xmon_circuit = circuit.with_parameters_resolved_by(
            param_resolver, extensions)
        converter.optimize_circuit(xmon_circuit)
        DropEmptyMoments().optimize_circuit(xmon_circuit)
        keys = find_measurement_keys(xmon_circuit)
        return xmon_circuit, keys
Exemplo n.º 3
0
Arquivo: engine.py Projeto: YZNIU/Cirq
    def program_as_schedule(self,
                            program: Union[Circuit, Schedule],
                            device: Device = None) -> Schedule:
        if isinstance(program, Circuit):
            device = device or UnconstrainedDevice
            circuit_copy = Circuit(program.moments)
            ConvertToXmonGates().optimize_circuit(circuit_copy)
            DropEmptyMoments().optimize_circuit(circuit_copy)
            device.validate_circuit(circuit_copy)
            return moment_by_moment_schedule(device, circuit_copy)

        elif isinstance(program, Schedule):
            if device:
                raise ValueError(
                    'Device can not be provided when running a schedule.')
            return program
        else:
            raise TypeError('Unexpected program type.')