Ejemplo n.º 1
0
    def initialize(self, options):
        self.qobj_compiler = xacc.getCompiler('qobj')
        if 'shots' in options:
            self.shots = options['shots']

        if 'backend' in options:
            self.backend = options['backend']
            import json
            from qiskit.providers.models.backendproperties import BackendProperties
            from qiskit.providers.aer import noise
            self.modeled_qpu = xacc.getAccelerator('ibm:' + self.backend)
            props = self.modeled_qpu.getProperties()
            jsonStr = props['total-json']
            # print("jsonStr: \n", jsonStr)
            properties = BackendProperties.from_dict(json.loads(jsonStr))
            ro_error = True if 'readout_error' in options and options[
                'readout_error'] else False
            rel = True if 'thermal_relaxation' in options and options[
                'thermal_relaxation'] else False
            ge = True if 'gate_error' in options and options[
                'gate_error'] else False
            self.noise_model = noise.NoiseModel.from_backend(
                backend,
                readout_error=ro_error,
                thermal_relaxation=rel,
                gate_error=ge)
Ejemplo n.º 2
0
 def __init__(self):
     mock_time = datetime.datetime.now()
     dt = 1.3333
     configuration = BackendProperties(
         backend_name="invalid_t2",
         backend_version="0.0.0",
         num_qubits=1,
         basis_gates=["u3"],
         qubits=[
             [
                 Nduv(date=mock_time, name="T1", unit="µs", value=t1_ns/1000),
                 Nduv(date=mock_time, name="T2", unit="µs", value=invalid_t2_ns/1000),
                 Nduv(date=mock_time, name="frequency", unit="MHz", value=frequency),
             ],
         ],
         gates=[
             Gate(
                 gate="u3",
                 name="u3_0",
                 qubits=[0],
                 parameters=[
                     Nduv(date=mock_time, name="gate_error", unit="", value=0.001),
                     Nduv(date=mock_time, name="gate_length", unit="ns", value=u3_time_ns),
                 ],
             ),
         ],
         last_update_date=mock_time,
         general=[],
     )
     super().__init__(configuration)
Ejemplo n.º 3
0
 def __init__(self):
     """
       0
     """
     mock_time = datetime.datetime.now()
     dt = 1.3333  # pylint: disable=invalid-name
     configuration = BackendProperties(
         backend_name='fake_1q',
         backend_version='0.0.0',
         n_qubits=1,
         basis_gates=['u1', 'u2', 'u3', 'cx'],
         simulator=False,
         local=True,
         conditional=False,
         memory=False,
         max_shots=1024,
         qubits=[
             [Nduv(date=mock_time, name='T1', unit='µs', value=71.9500421005539),
              Nduv(date=mock_time, name='frequency', unit='MHz', value=4919.96800692)]
         ],
         gates=[
             Gate(gate='u1', name='u1_0', qubits=[0],
                  parameters=[
                      Nduv(date=mock_time, name='gate_error', unit='', value=1.0),
                      Nduv(date=mock_time, name='gate_length', unit='ns', value=0.)]),
             Gate(gate='u3', name='u3_0', qubits=[0],
                  parameters=[
                      Nduv(date=mock_time, name='gate_error', unit='', value=1.0),
                      Nduv(date=mock_time, name='gate_length', unit='ns', value=2 * dt)]),
             Gate(gate='u3', name='u3_1', qubits=[1],
                  parameters=[
                      Nduv(date=mock_time, name='gate_error', unit='', value=1.0),
                      Nduv(date=mock_time, name='gate_length', unit='ns', value=4 * dt)]),
             Gate(gate='cx', name='cx0_1', qubits=[0, 1],
                  parameters=[
                      Nduv(date=mock_time, name='gate_error', unit='', value=1.0),
                      Nduv(date=mock_time, name='gate_length', unit='ns', value=22 * dt)]),
         ],
         coupling_map=None,
         n_registers=1,
         last_update_date=mock_time,
         general=[]
     )
     super().__init__(configuration)
Ejemplo n.º 4
0
def list_schedule_experiment(
    qexp: QasmQobjExperiment, hardware_props: BackendProperties
) -> List[Tuple[QasmQobjInstruction, float]]:
    """List schedule experiment to minimize run time

    :param qexp: quantum experiment to schedule
    :param hardware_props: hardware properties (T1, T2, etc.)
    :return: a list of tuples with an instruction and its corresponding execution time
    """
    # Keep track of when to schedule gates and which qubits are measured
    scheduling_times = [1] * qexp.config.n_qubits
    instruction_time_order = []

    # Schedule gate times
    for index, instruction in enumerate(qexp.instructions):
        instruction.id = index
        try:
            gate_length = hardware_props.gate_length(
                gate=instruction.name, qubits=instruction.qubits) * 1e9
        except (BackendPropertyError, AttributeError):
            gate_length = 0  # TODO: should measure have a time?

        gate_application_time = max(
            [scheduling_times[qubit] for qubit in instruction.qubits])

        if instruction.name == 'u1':
            gate_length = 10

        for qubit in instruction.qubits:
            scheduling_times[qubit] = gate_application_time
            scheduling_times[qubit] += gate_length

        instruction_time_order.append((instruction, gate_application_time))

    instruction_time_order.sort(
        key=lambda pair: pair[1])  # sort instructions by time

    # for instruction, gate_application_time in instruction_time_order:
    #     print(f"Applying gate {instruction.name} on {instruction.qubits} at time {gate_application_time} ns.")

    return instruction_time_order
Ejemplo n.º 5
0
    def __init__(self):
        configuration = PulseBackendConfiguration(
            backend_name='fake_openpulse_2q',
            backend_version='0.0.0',
            n_qubits=2,
            meas_levels=[0, 1, 2],
            basis_gates=['u1', 'u2', 'u3', 'cx', 'id'],
            simulator=False,
            local=True,
            conditional=True,
            open_pulse=True,
            memory=False,
            max_shots=65536,
            gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')],
            coupling_map=[[0, 1]],
            n_registers=2,
            n_uchannels=2,
            u_channel_lo=[
                [UchannelLO(q=0, scale=1. + 0.j)],
                [UchannelLO(q=0, scale=-1. + 0.j), UchannelLO(q=1, scale=1. + 0.j)]
            ],
            qubit_lo_range=[[4.5, 5.5], [4.5, 5.5]],
            meas_lo_range=[[6.0, 7.0], [6.0, 7.0]],
            dt=1.3333,
            dtm=10.5,
            rep_times=[100, 250, 500, 1000],
            meas_map=[[0, 1]],
            channel_bandwidth=[
                [-0.2, 0.4], [-0.3, 0.3], [-0.3, 0.3],
                [-0.02, 0.02], [-0.02, 0.02], [-0.02, 0.02]
            ],
            meas_kernels=['kernel1'],
            discriminators=['max_1Q_fidelity'],
            acquisition_latency=[[100, 100], [100, 100]],
            conditional_latency=[
                [100, 1000], [1000, 100], [100, 1000],
                [1000, 100], [100, 1000], [1000, 100]
            ],
            hamiltonian={
                'h_str': ["np.pi*(2*v0-alpha0)*O0", "np.pi*alpha0*O0*O0", "2*np.pi*r*X0||D0",
                          "2*np.pi*r*X0||U1", "2*np.pi*r*X1||U0", "np.pi*(2*v1-alpha1)*O1",
                          "np.pi*alpha1*O1*O1", "2*np.pi*r*X1||D1", "2*np.pi*j*(Sp0*Sm1+Sm0*Sp1)"],
                'description': "A hamiltonian for a mocked 2Q device, with 1Q and 2Q terms.",
                'qub': {'0': 3, '1': 3},
                'vars':  {'v0': 5.00,
                          'v1': 5.1,
                          'j': 0.01,
                          'r': 0.02,
                          'alpha0': -0.33,
                          'alpha1': -0.33}
            },
            channels={
                'acquire0': {
                    'operates': {'qubits': [0]},
                    'purpose': 'acquire',
                    'type': 'acquire'
                },
                'acquire1': {
                    'operates': {'qubits': [1]},
                    'purpose': 'acquire',
                    'type': 'acquire'
                },
                'd0': {
                    'operates': {'qubits': [0]},
                    'purpose': 'drive',
                    'type': 'drive'
                },
                'd1': {
                    'operates': {'qubits': [1]},
                    'purpose': 'drive',
                    'type': 'drive'
                },
                'm0': {
                    'type': 'measure',
                    'purpose': 'measure',
                    'operates': {'qubits': [0]}
                },
                'm1': {
                    'type': 'measure',
                    'purpose': 'measure',
                    'operates': {'qubits': [1]}
                },
                'u0': {
                    'operates': {'qubits': [0, 1]},
                    'purpose': 'cross-resonance',
                    'type': 'control'
                },
                'u1': {
                    'operates': {'qubits': [1, 0]},
                    'purpose': 'cross-resonance',
                    'type': 'control'
                }
            }
        )

        self._defaults = PulseDefaults.from_dict({
            'qubit_freq_est': [4.9, 5.0],
            'meas_freq_est': [6.5, 6.6],
            'buffer': 10,
            'pulse_library': [
                {
                    'name': 'test_pulse_1',
                    'samples': [[0.0, 0.0], [0.0, 0.1]]
                },
                {
                    'name': 'test_pulse_2',
                    'samples': [[0.0, 0.0], [0.0, 0.1], [0.0, 1.0]]
                },
                {
                    'name': 'test_pulse_3',
                    'samples': [[0.0, 0.0], [0.0, 0.1], [0.0, 1.0], [0.5, 0.0]]
                },
                {
                    'name': 'test_pulse_4',
                    'samples': 7 * [
                        [0.0, 0.0], [0.0, 0.1], [0.0, 1.0], [0.5, 0.0]
                    ]
                }
            ],
            'cmd_def': [
                Command.from_dict({
                    'name': 'u1',
                    'qubits': [0],
                    'sequence': [
                        PulseQobjInstruction(name='fc', ch='d0',
                                             t0=0, phase='-P0').to_dict()
                    ]}).to_dict(),
                Command.from_dict({
                    'name': 'u1',
                    'qubits': [1],
                    'sequence': [
                        PulseQobjInstruction(name='fc', ch='d1',
                                             t0=0, phase='-P0').to_dict()
                    ]}).to_dict(),
                Command.from_dict({
                    'name': 'u2',
                    'qubits': [0],
                    'sequence': [
                        PulseQobjInstruction(name='fc', ch='d0',
                                             t0=0,
                                             phase='-P1').to_dict(),
                        PulseQobjInstruction(name='test_pulse_4', ch='d0',
                                             t0=0).to_dict(),
                        PulseQobjInstruction(name='fc', ch='d0', t0=0,
                                             phase='-P0').to_dict()
                    ]}).to_dict(),
                Command.from_dict({
                    'name': 'u2',
                    'qubits': [1],
                    'sequence': [
                        PulseQobjInstruction(name='fc', ch='d1', t0=0,
                                             phase='-P1').to_dict(),
                        PulseQobjInstruction(name='test_pulse_4',
                                             ch='d1', t0=0).to_dict(),
                        PulseQobjInstruction(name='fc', ch='d1',
                                             t0=0, phase='-P0').to_dict()
                    ]}).to_dict(),
                Command.from_dict({
                    'name': 'u3',
                    'qubits': [0],
                    'sequence': [
                        PulseQobjInstruction(name='test_pulse_1', ch='d0',
                                             t0=0).to_dict()
                    ]}).to_dict(),
                Command.from_dict({
                    'name': 'u3',
                    'qubits': [1],
                    'sequence': [
                        PulseQobjInstruction(name='test_pulse_3', ch='d1',
                                             t0=0).to_dict()
                    ]}).to_dict(),
                Command.from_dict({
                    'name': 'cx',
                    'qubits': [0, 1],
                    'sequence': [
                        PulseQobjInstruction(name='test_pulse_1', ch='d0',
                                             t0=0).to_dict(),
                        PulseQobjInstruction(name='test_pulse_2', ch='u0',
                                             t0=10).to_dict(),
                        PulseQobjInstruction(name='test_pulse_1', ch='d1',
                                             t0=20).to_dict(),
                        PulseQobjInstruction(name='fc', ch='d1',
                                             t0=20, phase=2.1).to_dict()
                    ]}).to_dict(),
                Command.from_dict({
                    'name': 'ParametrizedGate',
                    'qubits': [0, 1],
                    'sequence': [
                        PulseQobjInstruction(name='test_pulse_1', ch='d0',
                                             t0=0).to_dict(),
                        PulseQobjInstruction(name='test_pulse_2', ch='u0',
                                             t0=10).to_dict(),
                        PulseQobjInstruction(name='pv', ch='d1',
                                             t0=2, val='cos(P2)').to_dict(),
                        PulseQobjInstruction(name='test_pulse_1', ch='d1',
                                             t0=20).to_dict(),
                        PulseQobjInstruction(name='fc', ch='d1',
                                             t0=20, phase=2.1).to_dict()
                    ]}).to_dict(),
                Command.from_dict({
                    'name': 'measure',
                    'qubits': [0, 1],
                    'sequence': [
                        PulseQobjInstruction(name='test_pulse_1', ch='m0',
                                             t0=0).to_dict(),
                        PulseQobjInstruction(name='test_pulse_1', ch='m1',
                                             t0=0).to_dict(),
                        PulseQobjInstruction(name='acquire', duration=10, t0=0,
                                             qubits=[0, 1],
                                             memory_slot=[0, 1]).to_dict()
                    ]}).to_dict()
            ]
        })

        mock_time = datetime.datetime.now()
        dt = 1.3333  # pylint: disable=invalid-name
        self._properties = BackendProperties(
            backend_name='fake_openpulse_2q',
            backend_version='0.0.0',
            last_update_date=mock_time,
            qubits=[
                [Nduv(date=mock_time, name='T1', unit='µs', value=71.9500421005539),
                 Nduv(date=mock_time, name='frequency', unit='MHz', value=4919.96800692)],
                [Nduv(date=mock_time, name='T1', unit='µs', value=81.9500421005539),
                 Nduv(date=mock_time, name='frequency', unit='GHz', value=5.01996800692)]
            ],
            gates=[
                Gate(gate='u1', qubits=[0],
                     parameters=[
                         Nduv(date=mock_time, name='gate_error', unit='', value=0.06),
                         Nduv(date=mock_time, name='gate_length', unit='ns', value=0.)]),
                Gate(gate='u3', qubits=[0],
                     parameters=[
                         Nduv(date=mock_time, name='gate_error', unit='', value=0.06),
                         Nduv(date=mock_time, name='gate_length', unit='ns', value=2 * dt)]),
                Gate(gate='u3', qubits=[1],
                     parameters=[
                         Nduv(date=mock_time, name='gate_error', unit='', value=0.06),
                         Nduv(date=mock_time, name='gate_length', unit='ns', value=4 * dt)]),
                Gate(gate='cx', qubits=[0, 1],
                     parameters=[
                         Nduv(date=mock_time, name='gate_error', unit='', value=1.0),
                         Nduv(date=mock_time, name='gate_length', unit='ns', value=22 * dt)]),
            ],
            general=[]
        )

        super().__init__(configuration)
Ejemplo n.º 6
0
 def __init__(self):
     """
     0
     """
     mock_time = datetime.datetime.now()
     dt = 1.3333
     configuration = BackendProperties(
         backend_name="fake_1q",
         backend_version="0.0.0",
         n_qubits=1,
         basis_gates=["u1", "u2", "u3", "cx"],
         simulator=False,
         local=True,
         conditional=False,
         memory=False,
         max_shots=1024,
         qubits=[[
             Nduv(date=mock_time,
                  name="T1",
                  unit="µs",
                  value=71.9500421005539),
             Nduv(date=mock_time,
                  name="frequency",
                  unit="MHz",
                  value=4919.96800692),
         ]],
         gates=[
             Gate(
                 gate="u1",
                 name="u1_0",
                 qubits=[0],
                 parameters=[
                     Nduv(date=mock_time,
                          name="gate_error",
                          unit="",
                          value=1.0),
                     Nduv(date=mock_time,
                          name="gate_length",
                          unit="ns",
                          value=0.0),
                 ],
             ),
             Gate(
                 gate="u3",
                 name="u3_0",
                 qubits=[0],
                 parameters=[
                     Nduv(date=mock_time,
                          name="gate_error",
                          unit="",
                          value=1.0),
                     Nduv(date=mock_time,
                          name="gate_length",
                          unit="ns",
                          value=2 * dt),
                 ],
             ),
             Gate(
                 gate="u3",
                 name="u3_1",
                 qubits=[1],
                 parameters=[
                     Nduv(date=mock_time,
                          name="gate_error",
                          unit="",
                          value=1.0),
                     Nduv(date=mock_time,
                          name="gate_length",
                          unit="ns",
                          value=4 * dt),
                 ],
             ),
             Gate(
                 gate="cx",
                 name="cx0_1",
                 qubits=[0, 1],
                 parameters=[
                     Nduv(date=mock_time,
                          name="gate_error",
                          unit="",
                          value=1.0),
                     Nduv(date=mock_time,
                          name="gate_length",
                          unit="ns",
                          value=22 * dt),
                 ],
             ),
         ],
         coupling_map=None,
         n_registers=1,
         last_update_date=mock_time,
         general=[],
     )
     super().__init__(configuration)
Ejemplo n.º 7
0
    def __init__(self):
        configuration = PulseBackendConfiguration(
            backend_name="fake_openpulse_2q",
            backend_version="0.0.0",
            n_qubits=2,
            meas_levels=[0, 1, 2],
            basis_gates=["u1", "u2", "u3", "cx", "id"],
            simulator=False,
            local=True,
            conditional=True,
            open_pulse=True,
            memory=False,
            max_shots=65536,
            gates=[GateConfig(name="TODO", parameters=[], qasm_def="TODO")],
            coupling_map=[[0, 1]],
            n_registers=2,
            n_uchannels=2,
            u_channel_lo=[
                [UchannelLO(q=0, scale=1.0 + 0.0j)],
                [
                    UchannelLO(q=0, scale=-1.0 + 0.0j),
                    UchannelLO(q=1, scale=1.0 + 0.0j)
                ],
            ],
            qubit_lo_range=[[4.5, 5.5], [4.5, 5.5]],
            meas_lo_range=[[6.0, 7.0], [6.0, 7.0]],
            dt=1.3333,
            dtm=10.5,
            rep_times=[100, 250, 500, 1000],
            meas_map=[[0, 1]],
            channel_bandwidth=[
                [-0.2, 0.4],
                [-0.3, 0.3],
                [-0.3, 0.3],
                [-0.02, 0.02],
                [-0.02, 0.02],
                [-0.02, 0.02],
            ],
            meas_kernels=["kernel1"],
            discriminators=["max_1Q_fidelity"],
            acquisition_latency=[[100, 100], [100, 100]],
            conditional_latency=[
                [100, 1000],
                [1000, 100],
                [100, 1000],
                [1000, 100],
                [100, 1000],
                [1000, 100],
            ],
            hamiltonian={
                "h_str": [
                    "np.pi*(2*v0-alpha0)*O0",
                    "np.pi*alpha0*O0*O0",
                    "2*np.pi*r*X0||D0",
                    "2*np.pi*r*X0||U1",
                    "2*np.pi*r*X1||U0",
                    "np.pi*(2*v1-alpha1)*O1",
                    "np.pi*alpha1*O1*O1",
                    "2*np.pi*r*X1||D1",
                    "2*np.pi*j*(Sp0*Sm1+Sm0*Sp1)",
                ],
                "description":
                "A hamiltonian for a mocked 2Q device, with 1Q and 2Q terms.",
                "qub": {
                    "0": 3,
                    "1": 3
                },
                "vars": {
                    "v0": 5.00,
                    "v1": 5.1,
                    "j": 0.01,
                    "r": 0.02,
                    "alpha0": -0.33,
                    "alpha1": -0.33,
                },
            },
            channels={
                "acquire0": {
                    "operates": {
                        "qubits": [0]
                    },
                    "purpose": "acquire",
                    "type": "acquire"
                },
                "acquire1": {
                    "operates": {
                        "qubits": [1]
                    },
                    "purpose": "acquire",
                    "type": "acquire"
                },
                "d0": {
                    "operates": {
                        "qubits": [0]
                    },
                    "purpose": "drive",
                    "type": "drive"
                },
                "d1": {
                    "operates": {
                        "qubits": [1]
                    },
                    "purpose": "drive",
                    "type": "drive"
                },
                "m0": {
                    "type": "measure",
                    "purpose": "measure",
                    "operates": {
                        "qubits": [0]
                    }
                },
                "m1": {
                    "type": "measure",
                    "purpose": "measure",
                    "operates": {
                        "qubits": [1]
                    }
                },
                "u0": {
                    "operates": {
                        "qubits": [0, 1]
                    },
                    "purpose": "cross-resonance",
                    "type": "control",
                },
                "u1": {
                    "operates": {
                        "qubits": [1, 0]
                    },
                    "purpose": "cross-resonance",
                    "type": "control",
                },
            },
            processor_type={
                "family": "Canary",
                "revision": "1.0",
                "segment": "A",
            },
        )

        self._defaults = PulseDefaults.from_dict({
            "qubit_freq_est": [4.9, 5.0],
            "meas_freq_est": [6.5, 6.6],
            "buffer":
            10,
            "pulse_library": [
                {
                    "name": "x90p_d0",
                    "samples": 2 * [0.1 + 0j]
                },
                {
                    "name": "x90p_d1",
                    "samples": 2 * [0.1 + 0j]
                },
                {
                    "name": "x90m_d0",
                    "samples": 2 * [-0.1 + 0j]
                },
                {
                    "name": "x90m_d1",
                    "samples": 2 * [-0.1 + 0j]
                },
                {
                    "name": "y90p_d0",
                    "samples": 2 * [0.1j]
                },
                {
                    "name": "y90p_d1",
                    "samples": 2 * [0.1j]
                },
                {
                    "name": "xp_d0",
                    "samples": 2 * [0.2 + 0j]
                },
                {
                    "name": "ym_d0",
                    "samples": 2 * [-0.2j]
                },
                {
                    "name": "cr90p_u0",
                    "samples": 9 * [0.1 + 0j]
                },
                {
                    "name": "cr90m_u0",
                    "samples": 9 * [-0.1 + 0j]
                },
                {
                    "name": "measure_m0",
                    "samples": 10 * [0.1 + 0j]
                },
                {
                    "name": "measure_m1",
                    "samples": 10 * [0.1 + 0j]
                },
            ],
            "cmd_def": [
                Command.from_dict({
                    "name":
                    "u1",
                    "qubits": [0],
                    "sequence": [
                        PulseQobjInstruction(name="fc",
                                             ch="d0",
                                             t0=0,
                                             phase="-P0").to_dict()
                    ],
                }).to_dict(),
                Command.from_dict({
                    "name":
                    "u1",
                    "qubits": [1],
                    "sequence": [
                        PulseQobjInstruction(name="fc",
                                             ch="d1",
                                             t0=0,
                                             phase="-P0").to_dict()
                    ],
                }).to_dict(),
                Command.from_dict({
                    "name":
                    "u2",
                    "qubits": [0],
                    "sequence": [
                        PulseQobjInstruction(name="fc",
                                             ch="d0",
                                             t0=0,
                                             phase="-P1").to_dict(),
                        PulseQobjInstruction(name="y90p_d0", ch="d0",
                                             t0=0).to_dict(),
                        PulseQobjInstruction(name="fc",
                                             ch="d0",
                                             t0=2,
                                             phase="-P0").to_dict(),
                    ],
                }).to_dict(),
                Command.from_dict({
                    "name":
                    "u2",
                    "qubits": [1],
                    "sequence": [
                        PulseQobjInstruction(name="fc",
                                             ch="d1",
                                             t0=0,
                                             phase="-P1").to_dict(),
                        PulseQobjInstruction(name="y90p_d1", ch="d1",
                                             t0=0).to_dict(),
                        PulseQobjInstruction(name="fc",
                                             ch="d1",
                                             t0=2,
                                             phase="-P0").to_dict(),
                    ],
                }).to_dict(),
                Command.from_dict({
                    "name":
                    "u3",
                    "qubits": [0],
                    "sequence": [
                        PulseQobjInstruction(name="fc",
                                             ch="d0",
                                             t0=0,
                                             phase="-P2").to_dict(),
                        PulseQobjInstruction(name="x90p_d0", ch="d0",
                                             t0=0).to_dict(),
                        PulseQobjInstruction(name="fc",
                                             ch="d0",
                                             t0=2,
                                             phase="-P0").to_dict(),
                        PulseQobjInstruction(name="x90m_d0", ch="d0",
                                             t0=2).to_dict(),
                        PulseQobjInstruction(name="fc",
                                             ch="d0",
                                             t0=4,
                                             phase="-P1").to_dict(),
                    ],
                }).to_dict(),
                Command.from_dict({
                    "name":
                    "u3",
                    "qubits": [1],
                    "sequence": [
                        PulseQobjInstruction(name="fc",
                                             ch="d1",
                                             t0=0,
                                             phase="-P2").to_dict(),
                        PulseQobjInstruction(name="x90p_d1", ch="d1",
                                             t0=0).to_dict(),
                        PulseQobjInstruction(name="fc",
                                             ch="d1",
                                             t0=2,
                                             phase="-P0").to_dict(),
                        PulseQobjInstruction(name="x90m_d1", ch="d1",
                                             t0=2).to_dict(),
                        PulseQobjInstruction(name="fc",
                                             ch="d1",
                                             t0=4,
                                             phase="-P1").to_dict(),
                    ],
                }).to_dict(),
                Command.from_dict({
                    "name":
                    "cx",
                    "qubits": [0, 1],
                    "sequence": [
                        PulseQobjInstruction(name="fc",
                                             ch="d0",
                                             t0=0,
                                             phase=1.57).to_dict(),
                        PulseQobjInstruction(name="ym_d0", ch="d0",
                                             t0=0).to_dict(),
                        PulseQobjInstruction(name="xp_d0", ch="d0",
                                             t0=11).to_dict(),
                        PulseQobjInstruction(name="x90p_d1", ch="d1",
                                             t0=0).to_dict(),
                        PulseQobjInstruction(name="cr90p_u0", ch="u0",
                                             t0=2).to_dict(),
                        PulseQobjInstruction(name="cr90m_u0", ch="u0",
                                             t0=13).to_dict(),
                    ],
                }).to_dict(),
                Command.from_dict({
                    "name":
                    "measure",
                    "qubits": [0, 1],
                    "sequence": [
                        PulseQobjInstruction(name="measure_m0", ch="m0",
                                             t0=0).to_dict(),
                        PulseQobjInstruction(name="measure_m1", ch="m1",
                                             t0=0).to_dict(),
                        PulseQobjInstruction(
                            name="acquire",
                            duration=10,
                            t0=0,
                            qubits=[0, 1],
                            memory_slot=[0, 1],
                        ).to_dict(),
                    ],
                }).to_dict(),
            ],
        })

        mock_time = datetime.datetime.now()
        dt = 1.3333
        self._properties = BackendProperties(
            backend_name="fake_openpulse_2q",
            backend_version="0.0.0",
            last_update_date=mock_time,
            qubits=[
                [
                    Nduv(date=mock_time,
                         name="T1",
                         unit="µs",
                         value=71.9500421005539),
                    Nduv(date=mock_time,
                         name="T2",
                         unit="µs",
                         value=69.4240447362455),
                    Nduv(date=mock_time,
                         name="frequency",
                         unit="MHz",
                         value=4919.96800692),
                    Nduv(date=mock_time,
                         name="readout_error",
                         unit="",
                         value=0.02),
                ],
                [
                    Nduv(date=mock_time,
                         name="T1",
                         unit="µs",
                         value=81.9500421005539),
                    Nduv(date=mock_time,
                         name="T2",
                         unit="µs",
                         value=75.5598482446578),
                    Nduv(date=mock_time,
                         name="frequency",
                         unit="GHz",
                         value=5.01996800692),
                    Nduv(date=mock_time,
                         name="readout_error",
                         unit="",
                         value=0.02),
                ],
            ],
            gates=[
                Gate(
                    gate="u1",
                    qubits=[0],
                    parameters=[
                        Nduv(date=mock_time,
                             name="gate_error",
                             unit="",
                             value=0.06),
                        Nduv(date=mock_time,
                             name="gate_length",
                             unit="ns",
                             value=0.0),
                    ],
                ),
                Gate(
                    gate="u3",
                    qubits=[0],
                    parameters=[
                        Nduv(date=mock_time,
                             name="gate_error",
                             unit="",
                             value=0.06),
                        Nduv(date=mock_time,
                             name="gate_length",
                             unit="ns",
                             value=2 * dt),
                    ],
                ),
                Gate(
                    gate="u3",
                    qubits=[1],
                    parameters=[
                        Nduv(date=mock_time,
                             name="gate_error",
                             unit="",
                             value=0.06),
                        Nduv(date=mock_time,
                             name="gate_length",
                             unit="ns",
                             value=4 * dt),
                    ],
                ),
                Gate(
                    gate="cx",
                    qubits=[0, 1],
                    parameters=[
                        Nduv(date=mock_time,
                             name="gate_error",
                             unit="",
                             value=1.0),
                        Nduv(date=mock_time,
                             name="gate_length",
                             unit="ns",
                             value=22 * dt),
                    ],
                ),
            ],
            general=[],
        )

        super().__init__(configuration)
Ejemplo n.º 8
0
def target_to_backend_properties(target: Target):
    """Convert a :class:`~.Target` object into a legacy :class:`~.BackendProperties`"""

    properties_dict = {
        "backend_name": "",
        "backend_version": "",
        "last_update_date": None,
        "general": [],
    }
    gates = []
    qubits = []
    for gate, qargs_list in target.items():
        if gate != "measure":
            for qargs, props in qargs_list.items():
                property_list = []
                if props is not None:
                    if props.duration is not None:
                        property_list.append({
                            "date": datetime.datetime.utcnow(),
                            "name": "gate_length",
                            "unit": "s",
                            "value": props.duration,
                        })
                    if props.error is not None:
                        property_list.append({
                            "date": datetime.datetime.utcnow(),
                            "name": "gate_error",
                            "unit": "",
                            "value": props.error,
                        })
                if property_list:
                    gates.append({
                        "gate":
                        gate,
                        "qubits":
                        list(qargs),
                        "parameters":
                        property_list,
                        "name":
                        gate + "_".join([str(x) for x in qargs]),
                    })
        else:
            qubit_props = {x: None for x in range(target.num_qubits)}
            for qargs, props in qargs_list.items():
                if qargs is None:
                    continue
                qubit = qargs[0]
                props_list = []
                if props.error is not None:
                    props_list.append({
                        "date": datetime.datetime.utcnow(),
                        "name": "readout_error",
                        "unit": "",
                        "value": props.error,
                    })
                if props.duration is not None:
                    props_list.append({
                        "date": datetime.datetime.utcnow(),
                        "name": "readout_length",
                        "unit": "s",
                        "value": props.duration,
                    })
                if not props_list:
                    qubit_props = {}
                    break
                qubit_props[qubit] = props_list
            if qubit_props and all(x is not None
                                   for x in qubit_props.values()):
                qubits = [qubit_props[i] for i in range(target.num_qubits)]
    if gates or qubits:
        properties_dict["gates"] = gates
        properties_dict["qubits"] = qubits
        return BackendProperties.from_dict(properties_dict)
    else:
        return None
Ejemplo n.º 9
0
ibmqx_4_properties_instance = BackendProperties.from_dict({'backend_name': 'ibmqx4',
 'backend_version': '1.0.0',
 'gates': [{'gate': 'u1',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.0}],
   'qubits': [0]},
  {'gate': 'u2',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.0009443532335046134}],
   'qubits': [0]},
  {'gate': 'u3',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.0018887064670092268}],
   'qubits': [0]},
  {'gate': 'u1',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.0}],
   'qubits': [1]},
  {'gate': 'u2',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.0012019552727863259}],
   'qubits': [1]},
  {'gate': 'u3',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.0024039105455726517}],
   'qubits': [1]},
  {'gate': 'u1',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.0}],
   'qubits': [2]},
  {'gate': 'u2',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.0012019552727863259}],
   'qubits': [2]},
  {'gate': 'u3',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.0024039105455726517}],
   'qubits': [2]},
  {'gate': 'u1',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.0}],
   'qubits': [3]},
  {'gate': 'u2',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.0013737021608475342}],
   'qubits': [3]},
  {'gate': 'u3',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.0027474043216950683}],
   'qubits': [3]},
  {'gate': 'u1',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.0}],
   'qubits': [4]},
  {'gate': 'u2',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.001803112096824766}],
   'qubits': [4]},
  {'gate': 'u3',
   'parameters': [{'date': '2019-05-08T09:57:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.003606224193649532}],
   'qubits': [4]},
  {'gate': 'cx',
   'name': 'CX1_0',
   'parameters': [{'date': '2019-05-08T01:27:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.024311890455604945}],
   'qubits': [1, 0]},
  {'gate': 'cx',
   'name': 'CX2_0',
   'parameters': [{'date': '2019-05-08T01:32:39+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.023484363587478657}],
   'qubits': [2, 0]},
  {'gate': 'cx',
   'name': 'CX2_1',
   'parameters': [{'date': '2019-05-08T01:38:20+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.04885221406150694}],
   'qubits': [2, 1]},
  {'gate': 'cx',
   'name': 'CX3_2',
   'parameters': [{'date': '2019-05-08T01:44:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.06682678733530181}],
   'qubits': [3, 2]},
  {'gate': 'cx',
   'name': 'CX3_4',
   'parameters': [{'date': '2019-05-08T01:50:07+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.05217118636435464}],
   'qubits': [3, 4]},
  {'gate': 'cx',
   'name': 'CX4_2',
   'parameters': [{'date': '2019-05-08T01:56:04+00:00',
     'name': 'gate_error',
     'unit': '',
     'value': 0.06446497941268642}],
   'qubits': [4, 2]}],
 'general': [],
 'last_update_date': '2019-05-08T01:56:04+00:00',
 'qconsole': False,
 'qubits': [[{'date': '2019-05-08T01:16:56+00:00',
    'name': 'T1',
    'unit': 'µs',
    'value': 43.21767480545737},
   {'date': '2019-05-08T01:17:40+00:00',
    'name': 'T2',
    'unit': 'µs',
    'value': 19.77368032971812},
   {'date': '2019-05-08T01:56:04+00:00',
    'name': 'frequency',
    'unit': 'GHz',
    'value': 5.246576101635769},
   {'date': '2019-05-08T01:16:37+00:00',
    'name': 'readout_error',
    'unit': '',
    'value': 0.08650000000000002}],
  [{'date': '2019-05-08T01:16:56+00:00',
    'name': 'T1',
    'unit': 'µs',
    'value': 43.87997000828745},
   {'date': '2019-05-08T01:18:27+00:00',
    'name': 'T2',
    'unit': 'µs',
    'value': 11.390521028550571},
   {'date': '2019-05-08T01:56:04+00:00',
    'name': 'frequency',
    'unit': 'GHz',
    'value': 5.298309751315148},
   {'date': '2019-05-08T01:16:37+00:00',
    'name': 'readout_error',
    'unit': '',
    'value': 0.07999999999999996}],
  [{'date': '2019-05-07T09:14:18+00:00',
    'name': 'T1',
    'unit': 'µs',
    'value': 48.97128225850014},
   {'date': '2019-05-08T01:19:07+00:00',
    'name': 'T2',
    'unit': 'µs',
    'value': 31.06845465651204},
   {'date': '2019-05-08T01:56:04+00:00',
    'name': 'frequency',
    'unit': 'GHz',
    'value': 5.3383288291854765},
   {'date': '2019-05-08T01:16:37+00:00',
    'name': 'readout_error',
    'unit': '',
    'value': 0.038250000000000006}],
  [{'date': '2019-05-08T01:16:56+00:00',
    'name': 'T1',
    'unit': 'µs',
    'value': 38.30486582843196},
   {'date': '2019-05-08T01:18:27+00:00',
    'name': 'T2',
    'unit': 'µs',
    'value': 32.35546811356613},
   {'date': '2019-05-08T01:56:04+00:00',
    'name': 'frequency',
    'unit': 'GHz',
    'value': 5.426109336844823},
   {'date': '2019-05-08T01:16:37+00:00',
    'name': 'readout_error',
    'unit': '',
    'value': 0.35675}],
  [{'date': '2019-05-08T01:16:56+00:00',
    'name': 'T1',
    'unit': 'µs',
    'value': 36.02606265575505},
   {'date': '2019-05-07T09:15:02+00:00',
    'name': 'T2',
    'unit': 'µs',
    'value': 4.461644223370699},
   {'date': '2019-05-08T01:56:04+00:00',
    'name': 'frequency',
    'unit': 'GHz',
    'value': 5.174501299220437},
   {'date': '2019-05-08T01:16:37+00:00',
    'name': 'readout_error',
    'unit': '',
    'value': 0.2715000000000001}]]})
Ejemplo n.º 10
0
    def __init__(self):
        configuration = PulseBackendConfiguration(
            backend_name='fake_openpulse_2q',
            backend_version='0.0.0',
            n_qubits=2,
            meas_levels=[0, 1, 2],
            basis_gates=['u1', 'u2', 'u3', 'cx', 'id'],
            simulator=False,
            local=True,
            conditional=True,
            open_pulse=True,
            memory=False,
            max_shots=65536,
            gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')],
            coupling_map=[[0, 1]],
            n_registers=2,
            n_uchannels=2,
            u_channel_lo=[[UchannelLO(q=0, scale=1. + 0.j)],
                          [
                              UchannelLO(q=0, scale=-1. + 0.j),
                              UchannelLO(q=1, scale=1. + 0.j)
                          ]],
            meas_level=[1, 2],
            qubit_lo_range=[[4.5, 5.5], [4.5, 5.5]],
            meas_lo_range=[[6.0, 7.0], [6.0, 7.0]],
            dt=1.3333,
            dtm=10.5,
            rep_times=[100, 250, 500, 1000],
            meas_map=[[0, 1]],
            channel_bandwidth=[[-0.2, 0.4], [-0.3, 0.3], [-0.3, 0.3],
                               [-0.02, 0.02], [-0.02, 0.02], [-0.02, 0.02]],
            meas_kernels=['kernel1'],
            discriminators=['max_1Q_fidelity'],
            acquisition_latency=[[100, 100], [100, 100]],
            conditional_latency=[[100, 1000], [1000, 100], [100, 1000],
                                 [1000, 100], [100, 1000], [1000, 100]])

        self._defaults = PulseDefaults(
            qubit_freq_est=[4.9, 5.0],
            meas_freq_est=[6.5, 6.6],
            buffer=10,
            pulse_library=[
                PulseLibraryItem(name='test_pulse_1', samples=[0.j, 0.1j]),
                PulseLibraryItem(name='test_pulse_2', samples=[0.j, 0.1j, 1j]),
                PulseLibraryItem(name='test_pulse_3',
                                 samples=[0.j, 0.1j, 1j, 0.5 + 0j]),
                PulseLibraryItem(name='test_pulse_4',
                                 samples=7 * [0.j, 0.1j, 1j, 0.5 + 0j])
            ],
            cmd_def=[
                Command(name='u1',
                        qubits=[0],
                        sequence=[
                            PulseQobjInstruction(name='fc',
                                                 ch='d0',
                                                 t0=0,
                                                 phase='-P1*np.pi')
                        ]),
                Command(name='u1',
                        qubits=[1],
                        sequence=[
                            PulseQobjInstruction(name='fc',
                                                 ch='d1',
                                                 t0=0,
                                                 phase='-P1*np.pi')
                        ]),
                Command(name='u2',
                        qubits=[0],
                        sequence=[
                            PulseQobjInstruction(name='fc',
                                                 ch='d0',
                                                 t0=0,
                                                 phase='-P0*np.pi'),
                            PulseQobjInstruction(name='test_pulse_4',
                                                 ch='d0',
                                                 t0=0),
                            PulseQobjInstruction(name='fc',
                                                 ch='d0',
                                                 t0=0,
                                                 phase='-P1*np.pi')
                        ]),
                Command(name='u2',
                        qubits=[1],
                        sequence=[
                            PulseQobjInstruction(name='fc',
                                                 ch='d1',
                                                 t0=0,
                                                 phase='-P0*np.pi'),
                            PulseQobjInstruction(name='test_pulse_4',
                                                 ch='d1',
                                                 t0=0),
                            PulseQobjInstruction(name='fc',
                                                 ch='d1',
                                                 t0=0,
                                                 phase='-P0*np.pi')
                        ]),
                Command(name='u3',
                        qubits=[0],
                        sequence=[
                            PulseQobjInstruction(name='test_pulse_1',
                                                 ch='d0',
                                                 t0=0)
                        ]),
                Command(name='u3',
                        qubits=[1],
                        sequence=[
                            PulseQobjInstruction(name='test_pulse_3',
                                                 ch='d1',
                                                 t0=0)
                        ]),
                Command(name='cx',
                        qubits=[0, 1],
                        sequence=[
                            PulseQobjInstruction(name='test_pulse_1',
                                                 ch='d0',
                                                 t0=0),
                            PulseQobjInstruction(name='test_pulse_2',
                                                 ch='u0',
                                                 t0=10),
                            PulseQobjInstruction(name='test_pulse_1',
                                                 ch='d1',
                                                 t0=20),
                            PulseQobjInstruction(name='fc',
                                                 ch='d1',
                                                 t0=20,
                                                 phase=2.1)
                        ]),
                Command(name='ParametrizedGate',
                        qubits=[0, 1],
                        sequence=[
                            PulseQobjInstruction(name='test_pulse_1',
                                                 ch='d0',
                                                 t0=0),
                            PulseQobjInstruction(name='test_pulse_2',
                                                 ch='u0',
                                                 t0=10),
                            PulseQobjInstruction(name='pv',
                                                 ch='d1',
                                                 t0=2,
                                                 val='cos(P2)'),
                            PulseQobjInstruction(name='test_pulse_1',
                                                 ch='d1',
                                                 t0=20),
                            PulseQobjInstruction(name='fc',
                                                 ch='d1',
                                                 t0=20,
                                                 phase=2.1)
                        ]),
                Command(name='measure',
                        qubits=[0, 1],
                        sequence=[
                            PulseQobjInstruction(name='test_pulse_1',
                                                 ch='m0',
                                                 t0=0),
                            PulseQobjInstruction(name='test_pulse_1',
                                                 ch='m1',
                                                 t0=0),
                            PulseQobjInstruction(name='acquire',
                                                 duration=10,
                                                 t0=0,
                                                 qubits=[0, 1],
                                                 memory_slot=[0, 1])
                        ])
            ])

        mock_time = datetime.datetime.now()
        dt = 1.3333  # pylint: disable=invalid-name
        self._properties = BackendProperties(
            backend_name='fake_openpulse_2q',
            backend_version='0.0.0',
            last_update_date=mock_time,
            qubits=[[
                Nduv(date=mock_time,
                     name='T1',
                     unit='µs',
                     value=71.9500421005539),
                Nduv(date=mock_time,
                     name='frequency',
                     unit='MHz',
                     value=4919.96800692)
            ],
                    [
                        Nduv(date=mock_time,
                             name='T1',
                             unit='µs',
                             value=81.9500421005539),
                        Nduv(date=mock_time,
                             name='frequency',
                             unit='GHz',
                             value=5.01996800692)
                    ]],
            gates=[
                Gate(gate='u1',
                     name='u1_0',
                     qubits=[0],
                     parameters=[
                         Nduv(date=mock_time,
                              name='gate_error',
                              unit='',
                              value=1.0),
                         Nduv(date=mock_time,
                              name='gate_length',
                              unit='ns',
                              value=0.)
                     ]),
                Gate(gate='u3',
                     name='u3_0',
                     qubits=[0],
                     parameters=[
                         Nduv(date=mock_time,
                              name='gate_error',
                              unit='',
                              value=1.0),
                         Nduv(date=mock_time,
                              name='gate_length',
                              unit='ns',
                              value=2 * dt)
                     ]),
                Gate(gate='u3',
                     name='u3_1',
                     qubits=[1],
                     parameters=[
                         Nduv(date=mock_time,
                              name='gate_error',
                              unit='',
                              value=1.0),
                         Nduv(date=mock_time,
                              name='gate_length',
                              unit='ns',
                              value=4 * dt)
                     ]),
                Gate(gate='cx',
                     name='cx0_1',
                     qubits=[0, 1],
                     parameters=[
                         Nduv(date=mock_time,
                              name='gate_error',
                              unit='',
                              value=1.0),
                         Nduv(date=mock_time,
                              name='gate_length',
                              unit='ns',
                              value=22 * dt)
                     ]),
            ],
            general=[])

        super().__init__(configuration)