Skip to content

Commit

Permalink
Merge pull request #186 from mit-han-lab/dev
Browse files Browse the repository at this point in the history
[minor] expand_param supports fixed gate
  • Loading branch information
Hanrui-Wang authored Aug 31, 2023
2 parents cb3a5ec + af0bc60 commit 370ac70
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/mnist/mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def forward(self, qdev: tq.QuantumDevice):
def __init__(self):
super().__init__()
self.n_wires = 4
self.encoder = tq.GeneralEncoder(tq.encoder_op_list_name_dict["4x4_u3rx"])
self.encoder = tq.GeneralEncoder(tq.encoder_op_list_name_dict["4x4_u3_h_rx"])

self.q_layer = self.QLayer()
self.measure = tq.MeasureAll(tq.PauliZ)
Expand Down
14 changes: 14 additions & 0 deletions torchquantum/encoding/encodings.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,20 @@ def __init__(self):
{"input_idx": [12, 13, 14], "func": "u3", "wires": [3]},
{"input_idx": [15], "func": "rx", "wires": [3]},
],
"4x4_u3_h_rx": [
{"input_idx": [0, 1, 2], "func": "u3", "wires": [0]},
{"input_idx": [3], "func": "rx", "wires": [0]},
{"func": "h", "wires": [0]},
{"func": "h", "wires": [1]},
{"func": "h", "wires": [2]},
{"func": "h", "wires": [3]},
{"input_idx": [4, 5, 6], "func": "u3", "wires": [1]},
{"input_idx": [7], "func": "rx", "wires": [1]},
{"input_idx": [8, 9, 10], "func": "u3", "wires": [2]},
{"input_idx": [11], "func": "rx", "wires": [2]},
{"input_idx": [12, 13, 14], "func": "u3", "wires": [3]},
{"input_idx": [15], "func": "rx", "wires": [3]},
],
"4x4_ryzxy": [
{"input_idx": [0], "func": "ry", "wires": [0]},
{"input_idx": [1], "func": "ry", "wires": [1]},
Expand Down
9 changes: 7 additions & 2 deletions torchquantum/plugin/qiskit/qiskit_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,15 @@ def op_history2qiskit_expand_params(n_wires, op_history, bsz):
for i in range(bsz):
circ = QuantumCircuit(n_wires)
for op in op_history:
if "params" in op.keys() and op["params"] is not None:
param = op["params"][i]
else:
param = None

append_fixed_gate(
circ, op["name"], op["params"][i], op["wires"], op["inverse"]
circ, op["name"], param, op["wires"], op["inverse"]
)

circs_all.append(circ)

return circs_all
Expand Down

0 comments on commit 370ac70

Please sign in to comment.