Functions to construct a dataset. Here we define the tokenization (encoding and decoding).
Tokenizer: encoding and decoding
source
get_target_control_qubits
get_target_control_qubits
(qc:qiskit.circuit.quantumcircuit.QuantumCircu
it, gate:qiskit.circuit.gate.Gate)
source
encode_circuit
encode_circuit (qc:qiskit.circuit.quantumcircuit.QuantumCircuit,
num_of_qubits, gate_classes:dict, max_gates:int,
sign_labels={'control_qubits': -1, 'target_qubits': 1},
return_params=False)
source
decode_circuit
decode_circuit (enc_tensor:torch.Tensor,
gate_pool:list[qiskit.circuit.gate.Gate],
place_barrier=True, sign_labels={'control_qubits': -1,
'target_qubits': 1}, params_tensor=None)
Dataset generation
Totally random SRV circuits
source
get_rnd_encoded_circuit
get_rnd_encoded_circuit (num_of_qubits, min_gates, max_gates, gate_pool,
gate_classes, rng, optimized=True,
return_params=False)
source
get_rnd_encoded_circuits
get_rnd_encoded_circuits (samples, num_of_qubits=3, min_gates=3,
max_gates=10, gate_pool=[<class 'qiskit.circuit
.library.standard_gates.h.HGate'>, <class 'qisk
it.circuit.library.standard_gates.x.CXGate'>],
optimized=True, silent=False,
return_params=False)
gate_pool=[ql.HGate, ql.CXGate, ql.CU3Gate, ql.CRXGate]
print("Encode:")
enc_t, y, params = get_rnd_encoded_circuits(samples=1, num_of_qubits=3, min_gates=6, max_gates=6, gate_pool=gate_pool, optimized=True, return_params=True)
for enc_i, y_i, params_i in zip(enc_t, y, params):
print(f"{enc_i=}")
print(f"{y_i=}")
print(f"{params_i=}")
print("Decode:")
qc = decode_circuit(enc_t[0], gate_pool=gate_pool, params_tensor=params[0])
display(qc.draw("mpl"))
enc_i=tensor([[-2, 0, -2, 3, 3, 0],
[ 2, 1, 2, -3, -3, 0],
[ 0, 0, 0, 0, 0, 1]], dtype=torch.int32)
y_i=[2, 2, 1]
params_i=tensor([[0.0000, 0.0000, 0.0000, 2.2710, 4.8585, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0304, 1.1044, 0.0000],
[0.0000, 0.0000, 0.0000, 3.0486, 4.9504, 0.0000]])
Decode:
source
gen_qc_dataset
gen_qc_dataset (samples, num_of_qubits, min_gates, max_gates, gate_pool,
optimized, silent=False)
Specific random SRV circuit
source
get_specific_rnd_srv_circuit
get_specific_rnd_srv_circuit (srv, requested_length, gate_pool,
max_i=2000, silent=True,
fix_length_after_optimizing=True,
requested_length_tolerance=0)
gen_compilation_rndGates_dataset
gen_compilation_rndGates_dataset (samples, num_of_qubits, min_gates,
max_gates, gate_pool,
min_sub_gate_pool_cnt=1, silent=False)
Samples rnd circuit with a rnd subset of gates and return qc with gate label and unitary
gate_pool=[ql.HGate, ql.CXGate, ql.ZGate, ql.XGate, ql.CCXGate]
enc_t, y, U = gen_compilation_rndGates_dataset(samples=1, num_of_qubits=3, min_gates=3, max_gates=4, gate_pool=gate_pool)
np.set_printoptions(edgeitems=30, linewidth=100000, formatter=dict(float=lambda x: "%.3g" % x))
print(f"\ny Label >>> {y[0]} <<<")
print(f"\n{enc_t[0]}")
print(f"\n{U[0]}")
print("\nDecoded:")
qc = decode_circuit(enc_t[0], gate_pool=gate_pool)
display(qc.draw("mpl"))
generated unique circuits: 1
y Label >>> Compile using: ['x'] <<<
tensor([[0, 0, 0, 0],
[4, 0, 0, 0],
[0, 4, 4, 4]], dtype=torch.int32)
[[0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j]
[0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j]
[0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j]
[0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j]
[0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
[0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
[1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
[0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]]
Decoded:
Graph states dataset
#place all h on all bist then only cz
Back to top