Skip to content

Commit

Permalink
Miscellaneous fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwysoc committed Sep 3, 2024
1 parent d696551 commit 220b500
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 9 deletions.
6 changes: 5 additions & 1 deletion pygsti/algorithms/fiducialselection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,7 @@ def create_candidate_fiducial_list(target_model, omit_identity= True, ops_to_omi
if ops_to_omit is None:
ops_to_omit = []

fidOps = [gate for gate in target_model.operations if gate not in ops_to_omit]
fidOps = [gate for gate in target_model.operations if str(gate) not in ops_to_omit]

if omit_identity:
# we assume identity gate is always the identity mx regardless of basis
Expand Down Expand Up @@ -2013,6 +2013,10 @@ def create_candidate_fiducial_list(target_model, omit_identity= True, ops_to_omi
else:
availableFidList.extend(_circuits.list_random_circuits_onelen(
fidOps, fidLength, count, seed=candidate_seed))

for ckt in availableFidList:
ckt.line_labels = target_model.state_space.state_space_labels
print(ckt.line_labels)
return availableFidList


Expand Down
2 changes: 1 addition & 1 deletion pygsti/algorithms/gaugeopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def gaugeopt_to_target(model, target_model, item_weights=None,
model = model.copy() # don't alter the original model's parameterization (this would be unexpected)
for args in conversion_args:
if isinstance(args, str):
model.convert_members_inplace(args, set_default_gauge_group=True)
model.convert_members_inplace(args, set_default_gauge_group=True, convert_new_inst=False)
elif isinstance(args, dict):
model.convert_members_inplace(**args)
else:
Expand Down
1 change: 1 addition & 0 deletions pygsti/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4047,6 +4047,7 @@ def convert_to_openqasm(self, num_qubits=None,
if include_delay_on_idle:
# Include a delay instruction
openqasm += 'opaque delay(t) q;\n\n'
openqasm += 'gate rzx(param0) q0,q1 { h q1; cx q0,q1; rz(param0) q1; cx q0,q1; h q1; }\ngate ecr q0,q1 { rzx(pi/4) q0,q1; x q0; rzx(-pi/4) q0,q1; }'

openqasm += 'qreg q[{0}];\n'.format(str(num_qubits))
# openqasm += 'creg cr[{0}];\n'.format(str(num_qubits))
Expand Down
3 changes: 2 additions & 1 deletion pygsti/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ def degrees_of_freedom(self, circuits=None, method="present_outcomes-1",
nDOF = 0
Nout = len(self.olIndex)
if model is not None:
prev_sim = model.sim
model.sim = 'map'

def compute_tuned_expected_llr(cur_outcomes):
Expand Down Expand Up @@ -1449,7 +1450,7 @@ def exp_llr_func(x):
nDOF += nOutcomes - 1 # last time stamp

if model is not None:
model.sim = 'matrix'
model.sim = prev_sim

if keyerrors != 0:
_warnings.warn(f'The dataset includes circuits the model cannot calculate probabilities for (e.g. the model does not include instruments for an instrument-containing dataset). Skipping KeyErrors = {keyerrors} circuits in calculation of degrees of freedom.')
Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion pygsti/modelmembers/instruments/composedinstrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,13 @@ def transform_inplace(self,s):
Smx = s.transform_matrix
Si = s.transform_matrix_inverse
self.noise_map = _op.FullTPOp(_np.kron(Si, _np.eye(4)) @ self.noise_map.to_dense() @ self.aux_GATES @ _np.kron(Smx, _np.eye(4)) @ self.aux_GATES)

for i in range(2):
self[f'p{i}'] = _ComposedInstrumentOp(self.noise_map, i, self.right_isometry, self.left_isometry, 'pp')
self.dirty = True

def __str__(self):
s = f'MCMInstrument representing a MCM with elements:\n'
s = f'ComposedInstrument representing a mid-curcuit measurement with elements:\n'
for lbl, element in self.items():
s += "%s:\n%s\n" % (lbl, _mt.mx_to_string(element.to_dense(), width=4, prec=3))
return s
4 changes: 3 additions & 1 deletion pygsti/modelmembers/instruments/tpinstrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ def simplify_operations(self, prefix=""):
@property
def parameter_labels(self): # same as in Instrument CONSOLIDATE?
"""
An array of labels (usually strings) describing this model member's parameters.
An array of labels (usually strings) describing this model member's parameters. Here,
we will have d^2(d^2-1) parameters corresponding to the sum of the instrument elements
followed by d^2*d^2 parameters for each of the instrument elements (except the first one).
"""
plabels_per_local_index = _collections.defaultdict(list)
for operation, factorgate_local_inds in zip(self.submembers(), self._submember_rpindices):
Expand Down
9 changes: 5 additions & 4 deletions pygsti/models/explicitmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def __getitem__(self, label):
raise KeyError("Key %s has an invalid prefix" % label)

def convert_members_inplace(self, to_type, categories_to_convert='all', labels_to_convert='all',
ideal_model=None, flatten_structure=False, set_default_gauge_group=False, cptp_truncation_tol= 1e-6):
ideal_model=None, flatten_structure=False, set_default_gauge_group=False, cptp_truncation_tol= 1e-6, convert_new_inst = True):
"""
TODO: docstring -- like set_all_parameterizations but doesn't set default gauge group by default
"""
Expand All @@ -385,8 +385,9 @@ def convert_members_inplace(self, to_type, categories_to_convert='all', labels_t
if any([c in categories_to_convert for c in ('all', 'instruments')]):
for lbl, inst in self.instruments.items():
if labels_to_convert == 'all' or lbl in labels_to_convert:
ideal = ideal_model.instruments.get(lbl, None) if (ideal_model is not None) else None
self.instruments[lbl] = _instrument.convert(inst, to_type, self.basis, ideal, flatten_structure)
if not isinstance(inst, _instrument.ComposedInstrument) and not convert_new_inst:
ideal = ideal_model.instruments.get(lbl, None) if (ideal_model is not None) else None
self.instruments[lbl] = _instrument.convert(inst, to_type, self.basis, ideal, flatten_structure)
if any([c in categories_to_convert for c in ('all', 'preps')]):
for lbl, prep in self.preps.items():
if labels_to_convert == 'all' or lbl in labels_to_convert:
Expand Down Expand Up @@ -564,7 +565,7 @@ def num_nongauge_params(self):
int
the number of non-gauge model parameters.
"""
return self.num_params - self.num_gauge_params
return self.num_params - self.num_gauge_params

@property

Expand Down
1 change: 1 addition & 0 deletions pygsti/tools/internalgates.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ def standard_gatenames_openqasm_conversions(version='u3'):
std_gatenames_to_qasm['Gc23'] = ['rz(4.71238898038469)']
std_gatenames_to_qasm['Gt'] = ['rz(0.7853981633974485)']
std_gatenames_to_qasm['Gtdag'] = ['rz(5.497787143782138)']
std_gatenames_to_qasm['Gecr'] = ['ecr']

std_gatenames_to_argmap = {}
std_gatenames_to_argmap['Gzr'] = lambda gatearg: ['rz(' + str(gatearg[0]) + ')']
Expand Down

0 comments on commit 220b500

Please sign in to comment.