def test_alloc(): p, qubits = five_qubit_prog() for qubit in qubits: assert qubit in p.resource_manager.live_qubits assert not instantiated(qubit) check_live_qubit(qubit) # Give the qubits labels for qubit in qubits: p.resource_manager.instantiate(qubit) assert instantiated(qubit) for qubit in qubits: p.free(qubit) assert qubit in p.resource_manager.dead_qubits
def __init__(self, qubit, classical_reg=None): check_live_qubit(qubit) if classical_reg is None: args = (qubit, ) elif isinstance(classical_reg, Addr): args = (qubit, classical_reg) else: raise TypeError("classical_reg should be None or an Addr instance") super(Measurement, self).__init__("MEASURE", params=None, args=args) self.classical_reg = classical_reg
def free(self, qubit): """ Free a qubit. :param AbstractQubit q: An AbstractQubit instance. """ check_live_qubit(qubit) if qubit.resource_manager != self.resource_manager: raise RuntimeError("qubit is managed by a different instruction group") self.actions.append(action(ACTION_RELEASE_QUBIT, qubit)) self.resource_manager.free_qubit(qubit)
def __init__(self, name, params, qubits): for qubit in qubits: check_live_qubit(qubit) super(Gate, self).__init__(name, params, qubits)