-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clifford simultaneous filtered rb #412
Changes from all commits
dc917ce
e5d80c3
affa5b5
dc17697
d51e258
174b2a5
7d9d83b
57e81e5
d3a6306
21997f3
2186a78
6be3ea5
95aba30
3824b52
e2c1194
73f7596
93ca115
39353f6
31b1208
dff5910
724e7f2
0fd4a46
126ce86
7767ebb
af686e2
8486a2e
78c3031
7a3cbce
a93001c
79a0d5c
27f3f8a
e521611
c343bd9
0d01232
76f40c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -31,7 +31,7 @@ def embed_circuit(circuit: Circuit, nqubits: int, qubits: list) -> Circuit: | |||||||||||
return large_circuit | ||||||||||||
|
||||||||||||
|
||||||||||||
def layer_circuit(layer_gen: Callable, depth: int) -> Circuit: | ||||||||||||
def layer_circuit(layer_gen: Callable, depth: int, **kwargs) -> Circuit: | ||||||||||||
"""Creates a circuit of `depth` layers from a generator `layer_gen` yielding `Circuit` or `Gate`. | ||||||||||||
|
||||||||||||
Args: | ||||||||||||
|
@@ -42,29 +42,36 @@ def layer_circuit(layer_gen: Callable, depth: int) -> Circuit: | |||||||||||
Circuit: with `depth` many layers. | ||||||||||||
""" | ||||||||||||
|
||||||||||||
if not isinstance(depth, int) or depth <= 0: | ||||||||||||
raise_error(ValueError, "Depth must be type int and positive.") | ||||||||||||
full_circuit = None | ||||||||||||
if not isinstance(depth, int) or depth < 0: | ||||||||||||
raise_error(ValueError, f"Depth: {depth}, must be type int and >= 0.") | ||||||||||||
|
||||||||||||
# Generate a layer to get nqubits. | ||||||||||||
new_layer = layer_gen() | ||||||||||||
if isinstance(new_layer, Gate): | ||||||||||||
nqubits = max(new_layer.qubits) + 1 | ||||||||||||
elif all(isinstance(gate, Gate) for gate in new_layer): | ||||||||||||
nqubits = max(max(gate.qubits) for gate in new_layer) + 1 | ||||||||||||
Comment on lines
+50
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||||||||||||
elif isinstance(new_layer, Circuit): | ||||||||||||
nqubits = new_layer.nqubits | ||||||||||||
else: | ||||||||||||
Comment on lines
+54
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. I think the original functionality of passing either a single |
||||||||||||
raise_error( | ||||||||||||
TypeError, | ||||||||||||
f"layer_gen must return type Circuit or Gate, but it is type {type(new_layer)}.", | ||||||||||||
) | ||||||||||||
|
||||||||||||
Comment on lines
+56
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Is there a particular reason for raising this error? We're all adults here; I'm guessing the code will crash if the wrong type is used. |
||||||||||||
# instantiate an empty circuit | ||||||||||||
full_circuit = Circuit(nqubits, **kwargs) | ||||||||||||
|
||||||||||||
# Build each layer, there will be depth many in the final circuit. | ||||||||||||
for _ in range(depth): | ||||||||||||
# Generate a layer. | ||||||||||||
# Generate a new layer. | ||||||||||||
new_layer = layer_gen() | ||||||||||||
# Ensure new_layer is a circuit | ||||||||||||
if isinstance(new_layer, Gate): | ||||||||||||
new_circuit = Circuit(max(new_layer.qubits) + 1) | ||||||||||||
new_circuit.add(new_layer) | ||||||||||||
elif all(isinstance(gate, Gate) for gate in new_layer): | ||||||||||||
new_circuit = Circuit(max(max(gate.qubits) for gate in new_layer) + 1) | ||||||||||||
new_circuit.add(new_layer) | ||||||||||||
elif isinstance(new_layer, Circuit): | ||||||||||||
if isinstance(new_layer, Circuit): | ||||||||||||
new_circuit = new_layer | ||||||||||||
else: | ||||||||||||
raise_error( | ||||||||||||
TypeError, | ||||||||||||
f"layer_gen must return type Circuit or Gate, but it is type {type(new_layer)}.", | ||||||||||||
) | ||||||||||||
if full_circuit is None: # instantiate in first loop | ||||||||||||
full_circuit = Circuit(new_circuit.nqubits) | ||||||||||||
new_circuit = Circuit(nqubits, **kwargs) | ||||||||||||
new_circuit.add(new_layer) | ||||||||||||
full_circuit = full_circuit + new_circuit | ||||||||||||
return full_circuit | ||||||||||||
|
||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the first part of this function, if you need to know the number of qubits, you can add it as an input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle there is no need to pass nqubits as it is implicit in the output of
layer_gen.__call__()
. But I don't like that now the first call of the generator is not added to the circuit. This makes it harder when one actually has to reproduce the result of a generator, say by restoring the rng state.