QdAnnealingIR#
- class qudas.annealing.ir.QdAnnealingIR(qubo: dict | None = None)[source]#
Bases:
Mapping量子アニーリング用の中間表現 (QUBO) を表すクラス。
旧 QuDataInput で担っていた QUBO 変換・演算機能を移植した。 qubo は dict で保持し、キーは変数名のタプル、値は係数。
- Any = typing.Any#
- class Base#
Bases:
pybind11_object- compile(*args, **kwargs)#
Overloaded function.
compile(self: cpp_pyqubo.Base, strength: float = 5) -> pyqubo::model
compile(self: cpp_pyqubo.Base, strength: cpp_pyqubo.Base) -> pyqubo::model
- Dict#
alias of
Dict
- class LpProblem(name='NoName', sense=1)#
Bases:
objectAn LP Problem
- add(constraint, name=None)#
- addConstraint(constraint, name=None)#
- addVariable(variable)#
Adds a variable to the problem before a constraint is added
@param variable: the variable to be added
- addVariables(variables)#
Adds variables to the problem before a constraint is added
@param variables: the variables to be added
- assignConsPi(values)#
- assignConsSlack(values, activity=False)#
- assignStatus(status, sol_status=None)#
Sets the status of the model after solving. :param status: code for the status of the model :param sol_status: code for the status of the solution :return:
- assignVarsDj(values)#
- assignVarsVals(values)#
- checkDuplicateVars() None#
Checks if there are at least two variables with the same name :return: 1 :raises const.PulpError: if there ar duplicates
- checkLengthVars(max_length: int) None#
Checks if variables have names smaller than max_length :param int max_length: max size for variable name :return: :raises const.PulpError: if there is at least one variable that has a long name
- coefficients(translation=None)#
- copy()#
Make a copy of self. Expressions are copied by reference
- deepcopy()#
Make a copy of self. Expressions are copied by value
- extend(other, use_objective=True)#
extends an LpProblem by adding constraints either from a dictionary a tuple or another LpProblem object.
@param use_objective: determines whether the objective is imported from the other problem
For dictionaries the constraints will be named with the keys For tuples an unique name will be generated For LpProblems the name of the problem will be added to the constraints name
- fixObjective()#
- classmethod fromDict(_dict)#
Takes a dictionary with all necessary information to build a model. And returns a dictionary of variables and a problem object
- Parameters:
_dict – dictionary with the model stored
- Returns:
a tuple with a dictionary of variables and a
LpProblem
- classmethod fromJson(filename)#
Creates a new Lp Problem from a json file with information
- Parameters:
filename (str) – json file name
- Returns:
a tuple with a dictionary of variables and an LpProblem
- Return type:
(dict,
LpProblem)
- classmethod fromMPS(filename, sense=1, **kwargs)#
- classmethod from_dict(_dict)#
Takes a dictionary with all necessary information to build a model. And returns a dictionary of variables and a problem object
- Parameters:
_dict – dictionary with the model stored
- Returns:
a tuple with a dictionary of variables and a
LpProblem
- classmethod from_json(filename)#
Creates a new Lp Problem from a json file with information
- Parameters:
filename (str) – json file name
- Returns:
a tuple with a dictionary of variables and an LpProblem
- Return type:
(dict,
LpProblem)
- getSense()#
- get_dummyVar()#
- infeasibilityGap(mip=1)#
- isMIP()#
- normalisedNames()#
- numConstraints()#
- Returns:
number of constraints in model
- numVariables()#
- Returns:
number of variables in model
- resolve(solver=None, **kwargs)#
resolves an Problem using the same solver as previously
- restoreObjective(wasNone, dummyVar)#
- roundSolution(epsInt=1e-05, eps=1e-07)#
Rounds the lp variables
- Inputs:
none
- Side Effects:
The lp variables are rounded
- sequentialSolve(objectives, absoluteTols=None, relativeTols=None, solver=None, debug=False)#
Solve the given Lp problem with several objective functions.
This function sequentially changes the objective of the problem and then adds the objective function as a constraint
- Parameters:
objectives – the list of objectives to be used to solve the problem
absoluteTols – the list of absolute tolerances to be applied to the constraints should be +ve for a minimise objective
relativeTols – the list of relative tolerances applied to the constraints
solver – the specific solver to be used, defaults to the default solver.
- setObjective(obj)#
Sets the input variable as the objective function. Used in Columnwise Modelling
- Parameters:
obj – the objective function of type
LpConstraintVar
- Side Effects:
The objective function is set
- setSolver(solver=<pulp.apis.coin_api.PULP_CBC_CMD object>)#
Sets the Solver for this problem useful if you are using resolve
- solve(solver=None, **kwargs)#
Solve the given Lp problem.
This function changes the problem to make it suitable for solving then calls the solver.actualSolve() method to find the solution
- Parameters:
solver – Optional: the specific solver to be used, defaults to the default solver.
- Side Effects:
The attributes of the problem object are changed in
actualSolve()to reflect the Lp solution
- startClock()#
initializes properties with the current time
- stopClock()#
updates time wall time and cpu time
- toDict()#
creates a dictionary from the model with as much data as possible. It replaces variables by variable names. So it requires to have unique names for variables.
- Returns:
dictionary with model data
- Return type:
dict
- toJson(filename, *args, **kwargs)#
Creates a json file from the LpProblem information
- Parameters:
filename (str) – filename to write json
args – additional arguments for json function
kwargs – additional keyword arguments for json function
- Returns:
None
- to_dict()#
creates a dictionary from the model with as much data as possible. It replaces variables by variable names. So it requires to have unique names for variables.
- Returns:
dictionary with model data
- Return type:
dict
- to_json(filename, *args, **kwargs)#
Creates a json file from the LpProblem information
- Parameters:
filename (str) – filename to write json
args – additional arguments for json function
kwargs – additional keyword arguments for json function
- Returns:
None
- unusedConstraintName()#
- valid(eps=0)#
- variables()#
Returns the problem variables
- Returns:
A list containing the problem variables
- Return type:
(list,
LpVariable)
- variablesDict()#
- writeLP(filename, writeSOS=1, mip=1, max_length=100)#
Write the given Lp problem to a .lp file.
This function writes the specifications (objective function, constraints, variables) of the defined Lp problem to a file.
- Parameters:
filename (str) – the name of the file to be created.
- Returns:
variables
- Side Effects:
The file is created
- writeMPS(filename, mpsSense=0, rename=0, mip=1, with_objsense: bool = False)#
Writes an mps files from the problem information
- Parameters:
filename (str) – name of the file to write
mpsSense (int) –
rename (bool) – if True, normalized names are used for variables and constraints
mip – variables and variable renames
- Returns:
- Side Effects:
The file is created
- Optional = typing.Optional#
- class Poly#
Bases:
object- class Iterator#
Bases:
object
- as_dict#
Returns: dict[tuple[int, …], float]:
- as_variable#
Returns: amplify.Variable:
- asdict#
alias of
as_dict()- Return type:
dict[tuple[int, …], float]
- decode#
Overloading:
1. decode(self, values: amplify.Values) -> float
- Args:
values (amplify.Values):
- Returns:
float:
2. decode(self, values: amplify.Values, default: float) -> float
- Args:
values (amplify.Values):
default (float):
- Returns:
float:
3. decode(self, values: amplify.Values, default: Optional[None]) -> amplify.Poly
- Args:
values (amplify.Values):
default (None | None):
- Returns:
amplify.Poly:
- degree#
Returns: int:
- evaluate#
Overloading:
1. evaluate(self, values: amplify.Values) -> float
- Args:
values (amplify.Values):
- Returns:
float:
2. evaluate(self, values: amplify.Values, default: float) -> float
- Args:
values (amplify.Values):
default (float):
- Returns:
float:
3. evaluate(self, values: amplify.Values, default: Optional[None]) -> amplify.Poly
- Args:
values (amplify.Values):
default (None | None):
- Returns:
amplify.Poly:
- property id#
id property
- Return type:
int
- is_linear#
Returns: bool:
- is_number#
Returns: bool:
- is_quadratic#
Returns: bool:
- is_variable#
Returns: bool:
- property lower_bound#
lower_bound property
- Return type:
float | None
- property name#
name property
- Return type:
str
- substitute#
- Parameters:
mapping (dict[amplify.Poly, Union[amplify.Poly, float, int]]) –
- Return type:
- property type#
type property
- Return type:
amplify.VariableType
- property upper_bound#
upper_bound property
- Return type:
float | None
- property variables#
variables property
- Return type:
List[amplify.Variable]
- csv = <module 'csv' from '/Users/kei/opt/anaconda3/envs/quantum/lib/python3.8/csv.py'>#
- dimod = <module 'dimod' from '/Users/kei/Desktop/python/quantum programming/nedo/qudas/.venv/lib/python3.8/site-packages/dimod/__init__.py'>#
- from_amplify(prob: Poly) QdAnnealingIR[source]#
- from_array(prob: np.ndarray) QdAnnealingIR[source]#
- from_csv(path: str, encoding: str = 'utf-8-sig') QdAnnealingIR[source]#
- classmethod from_dict(data: dict) QdAnnealingIR[source]#
- from_dimod_bqm(prob: dimod.BinaryQuadraticModel) QdAnnealingIR[source]#
- from_json(path: str) QdAnnealingIR[source]#
- from_networkx(prob: nx.Graph) QdAnnealingIR[source]#
- from_pandas(prob: pd.DataFrame) QdAnnealingIR[source]#
- from_pulp(prob: LpProblem) QdAnnealingIR[source]#
- from_pyqubo(prob: Base) QdAnnealingIR[source]#
- from_sympy(prob: sympy.core.expr.Expr) QdAnnealingIR[source]#
- json = <module 'json' from '/Users/kei/opt/anaconda3/envs/quantum/lib/python3.8/json/__init__.py'>#
- np = <module 'numpy' from '/Users/kei/Desktop/python/quantum programming/nedo/qudas/.venv/lib/python3.8/site-packages/numpy/__init__.py'>#
- nx = <module 'networkx' from '/Users/kei/Desktop/python/quantum programming/nedo/qudas/.venv/lib/python3.8/site-packages/networkx/__init__.py'>#
- pd = <module 'pandas' from '/Users/kei/Desktop/python/quantum programming/nedo/qudas/.venv/lib/python3.8/site-packages/pandas/__init__.py'>#
- property prob#
- sympy = <module 'sympy' from '/Users/kei/Desktop/python/quantum programming/nedo/qudas/.venv/lib/python3.8/site-packages/sympy/__init__.py'>#