Skip to content
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

Sourcery refactored main branch #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Sourcery refactored main branch #20

wants to merge 1 commit into from

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jun 13, 2022

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

Comment on lines -76 to +90
gamma = Parameter('g{}_{}_{}'.format(p, n1, n2))
gamma = Parameter(f'g{p}_{n1}_{n2}')
qc.cx(n1, n2)
qc.rz(gamma, n2)
qc.cx(n1, n2)
beta = Parameter('b{}'.format(p))
beta = Parameter(f'b{p}')
for node in self.zz_graph.nodes():
qc.rx(beta,node)
qc.barrier()
qc.measure(range(n), range(n))

trans_ckt = self.__compile_with_backend(ckt_qiskit = qc)
filename = 'uncompiled_' + self.output_file_name
filename = f'uncompiled_{self.output_file_name}'
qc.qasm(filename = filename)
self.__fix_param_names(filename)
filename = 'naive_compiled_' + self.output_file_name
filename = f'naive_compiled_{self.output_file_name}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CompileQAOAQiskit.__naive_compilation refactored with the following changes:

Comment on lines -124 to +127
assert self.Backend in self.supported_backends
else:
self.Backend = 'qiskit'
assert self.Backend in self.supported_backends

assert self.Backend in self.supported_backends
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CompileQAOAQiskit.__load_config refactored with the following changes:

Comment on lines -210 to 218
fmap[logical_q[0:]] = int(physical_q[0:])
fmap[logical_q[:]] = int(physical_q[:])

final_map = [
fmap[str(i)]
for i in range(
qiskit_ckt_object.width() - qiskit_ckt_object.num_qubits
)
]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CompileQAOAQiskit.__final_mapping_ic refactored with the following changes:

Comment on lines -246 to +255
if not self.incr_c_var_awareness:
swap_dist = self.qq_distances[_physical_q1][_physical_q2]
else:
swap_dist = self.noise_aware_qq_distances[_physical_q1][_physical_q2]
swap_dist = (
self.noise_aware_qq_distances[_physical_q1][_physical_q2]
if self.incr_c_var_awareness
else self.qq_distances[_physical_q1][_physical_q2]
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CompileQAOAQiskit.__sort_zz_by_qq_distances refactored with the following changes:

Comment on lines -275 to +281
gamma = Parameter('g{}_{}_{}'.format(p, n1, n2))
gamma = Parameter(f'g{p}_{n1}_{n2}')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CompileQAOAQiskit.__construct_single_layer_ckt_ic refactored with the following changes:

Comment on lines -642 to +683
out = open('{}_fixed'.format(filename), 'w')
for line in f:
captures = re.search('(g\d+)_(\d+)_(\d+)', line)
if captures:
captures = captures.groups()
g = captures[0]
n1 = captures[1]
n2 = captures[2]
if '({}, {})'.format(n1, n2) in all_keys:
coeff = 2*float(self.zz_dict['({}, {})'.format(n1, n2)])
else:
coeff = 2*float(self.zz_dict['({}, {})'.format(n2, n1)])
line = line.replace('{}_{}_{}'.format(g, n1, n2), str(coeff) + '*' + g)
out.write(line)
out.close()
with open(f'{filename}_fixed', 'w') as out:
for line in f:
if captures := re.search('(g\d+)_(\d+)_(\d+)', line):
captures = captures.groups()
g = captures[0]
n1 = captures[1]
n2 = captures[2]
if f'({n1}, {n2})' in all_keys:
coeff = 2 * float(self.zz_dict[f'({n1}, {n2})'])
else:
coeff = 2 * float(self.zz_dict[f'({n2}, {n1})'])
line = line.replace(f'{g}_{n1}_{n2}', f'{str(coeff)}*{g}')
out.write(line)
os.remove(filename)
os.rename(filename + '_fixed', filename)
os.rename(f'{filename}_fixed', filename)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CompileQAOAQiskit.__fix_param_names refactored with the following changes:

Comment on lines -35 to +37
logical_to_physical_layout = {}
for node in problem_zz_interactions_graph.nodes():
logical_to_physical_layout[node] = 'NA'
logical_to_physical_layout = {
node: 'NA' for node in problem_zz_interactions_graph.nodes()
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function initial_layout refactored with the following changes:

This removes the following comments ( why? ):

#if some logical neighbors are already placed find unallocated physical neighbors
#assign best available physical qubit to logical
#qubit if none of the logical neighbors are placed
#check which neighbors are already placced

Comment on lines -128 to +126
if sorted_program_qubits == []:
if not sorted_program_qubits:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function sort_program_qubits refactored with the following changes:

Comment on lines -159 to +157
print('Unconnected node: {}'.format(node))
print(f'Unconnected node: {node}')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function problem_profiling refactored with the following changes:

Comment on lines -175 to +173
strength = 0
for neigh in neighbours:
strength += coupling_graph[node][neigh]['weight']
strength = sum(coupling_graph[node][neigh]['weight'] for neigh in neighbours)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function hardware_qubit_strength_vqp refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

0 participants