Esempio n. 1
0
from hamiltonians import tfi_chain

num_qubits = 8

# The simulator.
dev = qml.device('default.qubit', wires=num_qubits, analytic=True)

# The TFI model at the critical point.
h        = 1.0
periodic = False
H        = tfi_chain(num_qubits, h, periodic=periodic)
print(H)

# The TTN circuit.
fix_layers = False
ansatz     = ttn_circuit(num_qubits, two_qubit_gate, fix_layers=fix_layers)

# The circuit for computing the expectation value of H.
cost_fn = qml.ExpvalCost(ansatz, H, dev, optimize=True)

num_params_per_gate = 15                                 # The number of parameters in each two-qubit gate.
depth               = int(np.floor(np.log2(num_qubits))) # The depth of the TTN.
num_gates           = num_qubits - 1                     # The number of two-qubit gates in the TTN.
if fix_layers:
    num_params = num_params_per_gate * depth
else:
    num_params = num_params_per_gate * num_gates    # The total number of parameters in the TTN.

# Initialize the parameters.
np.random.seed(1)
params = np.pi*(np.random.rand(num_params) - 1.0)
num_qubits = 16

# The simulator.
dev = qml.device('default.qubit', wires=num_qubits)

# The TFI model at the critical point.
h = 1.0
H = tfi_chain(num_qubits, h)
print(H)

# According to this website: https://dmrg101-tutorial.readthedocs.io/en/latest/tfim.html 
# (though their Hamiltonian has a typo: it should be Pauli matrices not spin operators.)
exact_E0 = 1.0 - 1.0/np.sin(np.pi/(2.0 * (2.0 * num_qubits + 1.0))) 

# The TTN circuit.
ansatz = ttn_circuit(num_qubits, simple_two_qubit_gate2)

# The circuit for computing the expectation value of H.
cost_fn = qml.ExpvalCost(ansatz, H, dev, optimize=True)

num_params_per_gate = 2                                  # The number of parameters in each two-qubit gate.
depth               = int(np.floor(np.log2(num_qubits))) # The depth of the TTN.
num_gates           = num_qubits - 1                     # The number of two-qubit gates in the TTN.
num_params          = num_params_per_gate * num_gates    # The total number of parameters in the TTN.

# Initialize the parameters.
np.random.seed(1)
params0 = np.pi*(np.random.rand(num_params) - 1.0)

# Optimizer parameters.
rtol     = 1e-5
Esempio n. 3
0
elif args.two_qubit == "simple2":
    unitary_parameterization = simple_two_qubit_gate2
    num_params_per_gate = 2
elif args.two_qubit == "arbitrary":
    unitary_parameterization = arb_qubit_gate
    num_params_per_gate = 15
else:
    raise NotImplementedError("Two Qubit Parameterization not found!")

# Choose which ansatz
if args.ansatz == "ttn":
    depth = int(np.floor(np.log2(num_qubits)))  # The depth of the TTN.
    num_gates = num_qubits - 1  # The number of two-qubit gates in the TTN.
    num_params = num_params_per_gate * num_gates  # The total number of parameters in the TTN.

    base_ansatz = ttn_circuit(num_qubits, unitary_parameterization)
elif args.ansatz == "mera":
    periodic = args.periodic == 1
    fix_layers = args.fix_layers == 1

    depth = int(np.floor(np.log2(num_qubits)))  # The depth of the TTN.
    num_gates = get_num_mera_gates(num_qubits, periodic, fix_layers)
    num_params = num_params_per_gate * num_gates

    base_ansatz = mera_circuit(num_qubits,
                               unitary_parameterization,
                               periodic=periodic,
                               fix_layers=fix_layers)
elif args.ansatz == "hea":
    hea_depth = 3
    num_params = (num_qubits * hea_depth - 1) * 3
Esempio n. 4
0
g = 0.5  # Longitudinal field

initializations = [
    "Random |0...0>", "Random |+...+>", "Zero |0...0>", "Zero |+...+>"
]

data_dicts = []

for num_qubits in qubits:
    print(f"=== Number of qubits = {num_qubits} ===")
    dev = qml.device("default.qubit.autograd", wires=num_qubits)

    constant_hea_depth = 3

    ansatze = [
        ttn_circuit(num_qubits),
        mera_circuit(num_qubits),
        hea_circuit(num_qubits),
        hea_circuit(num_qubits),
        hea_circuit(num_qubits)
    ]
    num_params_ansatz = [
        num_params_per_gate * get_num_ttn_gates(num_qubits),
        num_params_per_gate * get_num_mera_gates(num_qubits),
        3 * (num_qubits * constant_hea_depth),
        3 * (num_qubits * int(np.floor(np.log2(num_qubits)))),
        3 * (num_qubits * num_qubits)
    ]
    ansatz_names = [
        "TTN", "MERA", "HEA (constant)", "HEA (log)", "HEA (linear)"
    ]