コード例 #1
0
def _assemble_pulse_gates(
    circuit: QuantumCircuit, run_config: RunConfig
) -> Tuple[Optional[QasmExperimentCalibrations], Optional[PulseLibrary]]:
    """Assemble and return the circuit calibrations and associated pulse library, if there are any.
    The calibrations themselves may reference the pulse library which is returned as a dict.

    Args:
        circuit: circuit which may have pulse calibrations
        run_config: configuration of the runtime environment

    Returns:
        The calibrations and pulse library, if there are any
    """
    if not circuit.calibrations:
        return None, None
    if not hasattr(run_config, "parametric_pulses"):
        run_config.parametric_pulses = []
    calibrations = []
    pulse_library = {}
    for gate, cals in circuit.calibrations.items():
        for (qubits, params), schedule in cals.items():
            qobj_instructions, _ = _assemble_schedule(
                schedule,
                converters.InstructionToQobjConverter(PulseQobjInstruction),
                run_config,
                pulse_library,
            )
            calibrations.append(
                GateCalibration(str(gate), list(qubits), list(params),
                                qobj_instructions))
    return QasmExperimentCalibrations(gates=calibrations), pulse_library
コード例 #2
0
    def test_gate_calibrations_to_dict(self):
        """Test gate calibrations to dict."""

        pulse_library = [PulseLibraryItem(name="test", samples=[1j, 1j])]
        valid_qobj = QasmQobj(
            qobj_id="12345",
            header=QobjHeader(),
            config=QasmQobjConfig(shots=1024,
                                  memory_slots=2,
                                  max_credits=10,
                                  pulse_library=pulse_library),
            experiments=[
                QasmQobjExperiment(
                    instructions=[
                        QasmQobjInstruction(name="u1",
                                            qubits=[1],
                                            params=[0.4])
                    ],
                    config=QasmQobjConfig(
                        calibrations=QasmExperimentCalibrations(gates=[
                            GateCalibration(name="u1",
                                            qubits=[1],
                                            params=[0.4],
                                            instructions=[])
                        ])),
                )
            ],
        )
        res = valid_qobj.to_dict()
        expected_dict = {
            "qobj_id":
            "12345",
            "type":
            "QASM",
            "schema_version":
            "1.3.0",
            "header": {},
            "config": {
                "max_credits": 10,
                "memory_slots": 2,
                "shots": 1024,
                "pulse_library": [{
                    "name": "test",
                    "samples": [1j, 1j]
                }],
            },
            "experiments": [{
                "instructions": [{
                    "name": "u1",
                    "params": [0.4],
                    "qubits": [1]
                }],
                "config": {
                    "calibrations": {
                        "gates": [{
                            "name": "u1",
                            "qubits": [1],
                            "params": [0.4],
                            "instructions": []
                        }]
                    }
                },
                "header": {},
            }],
        }
        self.assertEqual(expected_dict, res)
コード例 #3
0
    def test_gate_calibrations_to_dict(self):
        """Test gate calibrations to dict."""

        pulse_library = [PulseLibraryItem(name='test', samples=[1j, 1j])]
        valid_qobj = QasmQobj(
            qobj_id='12345',
            header=QobjHeader(),
            config=QasmQobjConfig(shots=1024,
                                  memory_slots=2,
                                  max_credits=10,
                                  pulse_library=pulse_library),
            experiments=[
                QasmQobjExperiment(
                    instructions=[
                        QasmQobjInstruction(name='u1',
                                            qubits=[1],
                                            params=[0.4])
                    ],
                    config=QasmQobjConfig(
                        calibrations=QasmExperimentCalibrations(gates=[
                            GateCalibration(name='u1',
                                            qubits=[1],
                                            params=[0.4],
                                            instructions=[])
                        ])))
            ])
        res = valid_qobj.to_dict(validate=True)
        expected_dict = {
            'qobj_id':
            '12345',
            'type':
            'QASM',
            'schema_version':
            '1.3.0',
            'header': {},
            'config': {
                'max_credits': 10,
                'memory_slots': 2,
                'shots': 1024,
                'pulse_library': [{
                    'name': 'test',
                    'samples': [1j, 1j]
                }]
            },
            'experiments': [{
                'instructions': [{
                    'name': 'u1',
                    'params': [0.4],
                    'qubits': [1]
                }],
                'config': {
                    'calibrations': {
                        'gates': [{
                            'name': 'u1',
                            'qubits': [1],
                            'params': [0.4],
                            'instructions': []
                        }]
                    }
                },
                'header': {}
            }],
        }
        self.assertEqual(expected_dict, res)