Beispiel #1
0
 def __init__(self, molecule, slice_index=-1):
     """See class fields for parameter definitions.
     """
     super()
     self.molecule = molecule
     self.slice_index = slice_index
     # If the slice index is -1, the full circuit is being optimized.
     if self.slice_index == -1:
         self.circuit = UCCSD_DATA[molecule]["CIRCUIT"]
         self.file_name = "full"
         self.lr = UCCSD_DATA[molecule]["FULL_DATA"]["HP"]["lr"]
         self.decay = UCCSD_DATA[molecule]["FULL_DATA"]["HP"]["decay"]
     else:
         self.circuit = UCCSD_DATA[molecule]["SLICES"][slice_index].circuit
         self.file_name = "s{}".format(slice_index)
         self.lr = UCCSD_DATA[molecule]["SLICE_DATA"]["HP"][slice_index][
             "lr"]
         self.decay = UCCSD_DATA[molecule]["SLICE_DATA"]["HP"][slice_index][
             "decay"]
     self.unitary = get_unitary(self.circuit)
     self.grape_config = UCCSD_DATA[molecule]["GRAPE_CONFIG"]
     self.grape_config.update(GRAPE_TASK_CONFIG)
     self.data_path = os.path.join(BASE_DATA_PATH,
                                   "uccsd_{}".format(molecule.lower()))
     # TODO: We assume BASE_DAT_PATH exists.
     if not os.path.exists(self.data_path):
         os.mkdir(self.data_path)
    def __init__(self, molecule, rz_index):
        """See class fields for parameter definitions.
        """
        super()
        self.molecule = molecule
        self.rz_index = rz_index

        # Get circuit, cqp and slice_index.
        pickle_file_name = "{}_circuits.pickle".format(molecule.lower())
        pickle_file_path = os.path.join(HPO_DATA_PATH, pickle_file_name)
        with open(pickle_file_path, "rb") as f:
            rz_indices, circuit_list = pickle.load(f)
        slice_index = rz_indices[self.rz_index]
        circuit, connected_qubit_pairs = circuit_list[slice_index]

        self.slice_index = slice_index
        self.circuit = circuit
        self.connected_qubit_pairs = connected_qubit_pairs
        self.unitary = get_unitary(circuit)
        self.file_name = "s{}".format(slice_index)
        datadir_name = "uccsd_{}".format(molecule.lower())
        self.data_path = os.path.join(TIME_DATA_PATH, datadir_name)
        # TODO: We assume TIME_DATA_PATH exists.
        if not os.path.exists(self.data_path):
            os.mkdir(self.data_path)
        # Get grape config.
        # Set grape parameters.
        num_qubits = self.circuit.width()
        H0 = np.zeros((NUM_STATES ** num_qubits, NUM_STATES ** num_qubits))
        Hops, Hnames = get_Hops_and_Hnames(num_qubits, NUM_STATES, self.connected_qubit_pairs)
        states_concerned_list = get_full_states_concerned_list(num_qubits, NUM_STATES)
        maxA = get_maxA(num_qubits, NUM_STATES, self.connected_qubit_pairs)
        reg_coeffs = {}
        self.grape_config = {
            "H0": H0,
            "Hops": Hops,
            "Hnames": Hnames,
            "states_concerned_list": states_concerned_list,
            "reg_coeffs": reg_coeffs,
            "maxA": maxA,
        }
        self.grape_config.update(GRAPE_TASK_CONFIG)        
        
        # Get hyperparameters by choosing the configuration with the lowest loss.
        best_data = {"loss": 1}
        hpo_file_name = "{}.json".format(self.file_name)
        hpo_file_path = os.path.join(HPO_DATA_PATH, datadir_name, hpo_file_name)
        with open(hpo_file_path) as f:
            line = f.readline()
            while line:
                data = json.loads(line)
                if data["loss"] < best_data["loss"]:
                    best_data = data
                line = f.readline()
        #ENDWITH
        self.lr = best_data["lr"]
        self.decay = best_data["decay"]
Beispiel #3
0
    def __init__(self, molecule, slice_index, circuit, connected_qubit_pairs):
        """See corresponding class field declarations above for other arguments.
        """
        super()
        self.molecule = molecule
        self.slice_index = slice_index
        self.circuit = circuit
        self.connected_qubit_pairs = connected_qubit_pairs
        self.unitary = get_unitary(self.circuit)
        if self.circuit.depth() > REDUCED_CIRCUIT_DEPTH_CUTOFF:
            self.pulse_time = get_max_pulse_time(
                self.circuit) * PULSE_TIME_MULTIPLIER
        else:
            self.pulse_time = get_max_pulse_time(
                self.circuit) * REDUCED_PULSE_TIME_MULTIPLIER
        self.file_name = "s{}".format(self.slice_index)
        self.data_path = os.path.join(BASE_DATA_PATH,
                                      "uccsd_{}".format(molecule.lower()))
        # TODO: We assume BASE_DATA_PATH exists.
        if not os.path.exists(self.data_path):
            os.mkdir(self.data_path)

        # Set grape parameters.
        num_qubits = self.circuit.width()
        H0 = np.zeros((NUM_STATES**num_qubits, NUM_STATES**num_qubits))
        Hops, Hnames = get_Hops_and_Hnames(num_qubits, NUM_STATES,
                                           self.connected_qubit_pairs)
        states_concerned_list = get_full_states_concerned_list(
            num_qubits, NUM_STATES)
        maxA = get_maxA(num_qubits, NUM_STATES, self.connected_qubit_pairs)
        reg_coeffs = {}
        self.grape_config = {
            "H0": H0,
            "Hops": Hops,
            "Hnames": Hnames,
            "states_concerned_list": states_concerned_list,
            "reg_coeffs": reg_coeffs,
            "maxA": maxA,
        }
        self.grape_config.update(GRAPE_TASK_CONFIG)
Beispiel #4
0
 def __init__(self, molecule, slice_index=-1):
     """See corresponding class field declarations above for other arguments.
     """
     super()
     self.molecule = molecule
     self.slice_index = slice_index
     # If the slice index is -1, the full circuit is being optimized.
     if self.slice_index == -1:
         self.circuit = UCCSD_DATA[molecule]["CIRCUIT"]
         self.file_name = "full"
     else:
         self.circuit = UCCSD_DATA[molecule]["SLICES"][slice_index].circuit
         self.file_name = "s{}".format(slice_index)
     self.unitary = get_unitary(self.circuit)
     self.grape_config = UCCSD_DATA[molecule]["GRAPE_CONFIG"]
     self.grape_config.update(GRAPE_TASK_CONFIG)
     self.pulse_time = get_max_pulse_time(self.circuit) * PULSE_TIME_MULTIPLIER
     self.data_path = os.path.join(BASE_DATA_PATH,
                                   "uccsd_{}".format(molecule.lower()))
     # TODO: We assume BASE_DATA_PATH exists.
     if not os.path.exists(self.data_path):
         os.mkdir(self.data_path)
Beispiel #5
0
for slice_circuit, block, connected_qubit_pairs in zip(
        slice_circuits, blocking.blocks, blocking.connected_qubit_pairs_list):
    for index in block:
        assert len(slice_circuit.qregs) == 1
        slice_circuit.iden(slice_circuit.qregs[0][index])

    slice_circuit = util.squash_circuit(slice_circuit)
    N = slice_circuit.width()
    H0 = hamiltonian.get_H0(N, d)
    Hops, Hnames = hamiltonian.get_Hops_and_Hnames(N, d, connected_qubit_pairs)
    states_concerned_list = hamiltonian.get_full_states_concerned_list(N, d)
    maxA = hamiltonian.get_maxA(N, d, connected_qubit_pairs)
    max_time = (3 * N) * 5.0 * graph_p

    time = 0.0
    for subslice in uccsd.get_uccsd_slices(slice_circuit, granularity=1):
        if subslice.parameterized:
            time += util.circuitutil.get_max_pulse_time(subslice.circuit)
        else:
            U = util.get_unitary(subslice.circuit)
            time += binary_search_for_shortest_pulse_time(0.0,
                                                          max_time,
                                                          tolerance=0.3)

    times.append(time)

print('\n\n\n')
print(times)
print('TIME FOR SLICE IS:')
print(max(times))
Beispiel #6
0
    slice_circuits_list.append((slice_circuits, blocking))
    gates = remaining_gates
    blockings_index = (blockings_index + 1) % len(blockings)

slice_circuits, blocking = slice_circuits_list[int(sys.argv[1])]

# HACK ALERT: to preserve all qubits, I add a dummy identity on each qubit, then squash
times = []
for slice_circuit, block, connected_qubit_pairs in zip(
        slice_circuits, blocking.blocks, blocking.connected_qubit_pairs_list):
    for index in block:
        assert len(slice_circuit.qregs) == 1
        slice_circuit.iden(slice_circuit.qregs[0][index])

    slice_circuit = util.squash_circuit(slice_circuit)
    U = util.get_unitary(slice_circuit)
    N = slice_circuit.width()
    H0 = hamiltonian.get_H0(N, d)
    Hops, Hnames = hamiltonian.get_Hops_and_Hnames(N, d, connected_qubit_pairs)
    states_concerned_list = hamiltonian.get_full_states_concerned_list(N, d)
    maxA = hamiltonian.get_maxA(N, d, connected_qubit_pairs)
    max_time = (2**N) * 5.0
    times.append(
        binary_search_for_shortest_pulse_time(0.0, max_time, tolerance=0.3))

print('\n\n\n')
print(times)
print('TIME FOR SLICE IS:')
print(max(times))
Beispiel #7
0
 def unitary(self):
     """Return the unitary corresponding to the slice's circuit.
     Returns: unitary :: np.matrix - the unitary corresponding to the
                                     slice's circuit
     """
     return get_unitary(self.circuit)